Commit d83bc171 authored by unknown's avatar unknown

renamed global variables

parent cd40855e
...@@ -8,7 +8,7 @@ TRX active_list_min, active_list_max, ...@@ -8,7 +8,7 @@ TRX active_list_min, active_list_max,
committed_list_min, committed_list_max, *pool; committed_list_min, committed_list_max, *pool;
pthread_mutex_t LOCK_trx_list; pthread_mutex_t LOCK_trx_list;
uint active_transactions; uint trxman_active_transactions, trxman_allocated_transactions;
TrID global_trid_generator; TrID global_trid_generator;
TRX **short_id_to_trx; TRX **short_id_to_trx;
...@@ -30,7 +30,8 @@ int trxman_init() ...@@ -30,7 +30,8 @@ int trxman_init()
active_list_max.next= active_list_min.prev= 0; active_list_max.next= active_list_min.prev= 0;
active_list_max.prev= &active_list_min; active_list_max.prev= &active_list_min;
active_list_min.next= &active_list_max; active_list_min.next= &active_list_max;
active_transactions= 0; trxman_active_transactions= 0;
trxman_allocated_transactions= 0;
committed_list_max.commit_trid= ~0; committed_list_max.commit_trid= ~0;
committed_list_max.next= committed_list_min.prev= 0; committed_list_max.next= committed_list_min.prev= 0;
...@@ -54,7 +55,7 @@ int trxman_init() ...@@ -54,7 +55,7 @@ int trxman_init()
int trxman_destroy() int trxman_destroy()
{ {
DBUG_ASSERT(trid_to_trx.count == 0); DBUG_ASSERT(trid_to_trx.count == 0);
DBUG_ASSERT(active_transactions == 0); DBUG_ASSERT(trxman_active_transactions == 0);
DBUG_ASSERT(active_list_max.prev == &active_list_min); DBUG_ASSERT(active_list_max.prev == &active_list_min);
DBUG_ASSERT(active_list_min.next == &active_list_max); DBUG_ASSERT(active_list_min.next == &active_list_max);
DBUG_ASSERT(committed_list_max.prev == &committed_list_min); DBUG_ASSERT(committed_list_max.prev == &committed_list_min);
...@@ -62,7 +63,7 @@ int trxman_destroy() ...@@ -62,7 +63,7 @@ int trxman_destroy()
while (pool) while (pool)
{ {
TRX *tmp=pool->next; TRX *tmp=pool->next;
my_free(pool, MYF(0)); my_free((void *)pool, MYF(0));
pool=tmp; pool=tmp;
} }
lf_hash_destroy(&trid_to_trx); lf_hash_destroy(&trid_to_trx);
...@@ -93,21 +94,17 @@ static void set_short_id(TRX *trx) ...@@ -93,21 +94,17 @@ static void set_short_id(TRX *trx)
trx->short_id= i; trx->short_id= i;
} }
extern int global_malloc;
TRX *trxman_new_trx() TRX *trxman_new_trx()
{ {
TRX *trx; TRX *trx;
my_atomic_add32(&active_transactions, 1); my_atomic_add32(&trxman_active_transactions, 1);
/* /*
we need a mutex here to ensure that see trxman_end_trx to see why we need a mutex here
transactions in the active list are ordered by the trid.
So, incrementing global_trid_generator and
adding to the list must be atomic.
and as we have a mutex, we can as well do everything and as we have a mutex, we can as well do everything
under it - allocating a TRX, incrementing active_transactions, under it - allocating a TRX, incrementing trxman_active_transactions,
setting trx->min_read_from. setting trx->min_read_from.
Note that all the above is fast. generating short_id may be slow, Note that all the above is fast. generating short_id may be slow,
...@@ -123,7 +120,7 @@ TRX *trxman_new_trx() ...@@ -123,7 +120,7 @@ TRX *trxman_new_trx()
if (!trx) if (!trx)
{ {
trx=(TRX *)my_malloc(sizeof(TRX), MYF(MY_WME)); trx=(TRX *)my_malloc(sizeof(TRX), MYF(MY_WME));
global_malloc++; trxman_allocated_transactions++;
} }
if (!trx) if (!trx)
return 0; return 0;
...@@ -213,7 +210,7 @@ void trxman_end_trx(TRX *trx, my_bool commit) ...@@ -213,7 +210,7 @@ void trxman_end_trx(TRX *trx, my_bool commit)
} }
pthread_mutex_unlock(&LOCK_trx_list); pthread_mutex_unlock(&LOCK_trx_list);
my_atomic_add32(&active_transactions, -1); my_atomic_add32(&trxman_active_transactions, -1);
while (free_me) while (free_me)
{ {
......
...@@ -12,7 +12,7 @@ typedef struct st_transaction ...@@ -12,7 +12,7 @@ typedef struct st_transaction
#define SHORT_ID_MAX 65535 #define SHORT_ID_MAX 65535
extern uint active_transactions; extern uint trxman_active_transactions, trxman_allocated_transactions;
extern TRX **short_id_to_trx; extern TRX **short_id_to_trx;
extern my_atomic_rwlock_t LOCK_short_id_to_trx; extern my_atomic_rwlock_t LOCK_short_id_to_trx;
......
...@@ -106,7 +106,6 @@ void run_test(const char *test, pthread_handler handler, int n, int m) ...@@ -106,7 +106,6 @@ void run_test(const char *test, pthread_handler handler, int n, int m)
ok(litmus == 0, "tested %s in %g secs (%d)", test, ((double)now)/1e7, litmus); ok(litmus == 0, "tested %s in %g secs (%d)", test, ((double)now)/1e7, litmus);
} }
int global_malloc=0;
int main() int main()
{ {
plan(1); plan(1);
...@@ -127,7 +126,7 @@ int main() ...@@ -127,7 +126,7 @@ int main()
trxman_init(); trxman_init();
run_test("trxman", test_trxman, THREADS,CYCLES); run_test("trxman", test_trxman, THREADS,CYCLES);
trxman_destroy(); trxman_destroy();
diag("mallocs: %d\n", global_malloc); diag("mallocs: %d\n", trxman_allocated_transactions);
pthread_mutex_destroy(&rt_mutex); pthread_mutex_destroy(&rt_mutex);
pthread_cond_destroy(&rt_cond); pthread_cond_destroy(&rt_cond);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment