From 6b4f3ea4891b6c0e65dfd6d41f49aee2daa9e23d Mon Sep 17 00:00:00 2001 From: jdybnis Date: Mon, 19 Jan 2009 05:21:45 +0000 Subject: [PATCH] fix compiler warnings/error under gcc 4.1 and 4.2 --- map/hashtable.c | 12 ++++++------ runtime/mem.c | 2 +- runtime/rcu.c | 2 +- runtime/rlocal.h | 2 ++ runtime/runtime.c | 3 ++- test/haz_test.c | 2 +- test/map_test1.c | 2 +- test/map_test2.c | 2 +- test/rcu_test.c | 2 +- txn/txn.c | 15 +++++++++++---- 10 files changed, 27 insertions(+), 17 deletions(-) diff --git a/map/hashtable.c b/map/hashtable.c index 231384c..b8d8f6b 100644 --- a/map/hashtable.c +++ b/map/hashtable.c @@ -288,8 +288,8 @@ static int hti_copy_entry (hti_t *ht1, volatile entry_t *ht1_ent, uint32_t key_h // Update the count if we were the one that completed the copy. if (old_ht2_ent_val == DOES_NOT_EXIST) { TRACE("h0", "hti_copy_entry: key %p value %p copied to new entry", key, ht1_ent_val); - SYNC_ADD(&ht1->count, -1); - SYNC_ADD(&ht2->count, 1); + (void)SYNC_ADD(&ht1->count, -1); + (void)SYNC_ADD(&ht2->count, 1); return TRUE; } @@ -376,7 +376,7 @@ static map_val_t hti_cas (hti_t *hti, map_key_t key, uint32_t key_hash, map_val_ if (ent_val != COPIED_VALUE && ent_val != TAG_VALUE(TOMBSTONE, TAG1)) { int did_copy = hti_copy_entry(hti, ent, key_hash, ((volatile hti_t *)hti)->next); if (did_copy) { - SYNC_ADD(&hti->num_entries_copied, 1); + (void)SYNC_ADD(&hti->num_entries_copied, 1); } TRACE("h0", "hti_cas: value in the middle of a copy, copy completed by %s", (did_copy ? "self" : "other"), 0); @@ -410,9 +410,9 @@ static map_val_t hti_cas (hti_t *hti, map_key_t key, uint32_t key_hash, map_val_ // The set succeeded. Adjust the value count. if (old_existed && new == DOES_NOT_EXIST) { - SYNC_ADD(&hti->count, -1); + (void)SYNC_ADD(&hti->count, -1); } else if (!old_existed && new != DOES_NOT_EXIST) { - SYNC_ADD(&hti->count, 1); + (void)SYNC_ADD(&hti->count, 1); } // Return the previous value. @@ -443,7 +443,7 @@ static map_val_t hti_get (hti_t *hti, map_key_t key, uint32_t key_hash) { if (EXPECT_FALSE(ent_val != COPIED_VALUE && ent_val != TAG_VALUE(TOMBSTONE, TAG1))) { int did_copy = hti_copy_entry(hti, ent, key_hash, ((volatile hti_t *)hti)->next); if (did_copy) { - SYNC_ADD(&hti->num_entries_copied, 1); + (void)SYNC_ADD(&hti->num_entries_copied, 1); } } return hti_get(((volatile hti_t *)hti)->next, key, key_hash); // tail-call diff --git a/runtime/mem.c b/runtime/mem.c index 1f7a5a6..57d94aa 100644 --- a/runtime/mem.c +++ b/runtime/mem.c @@ -95,7 +95,7 @@ static void *get_new_region (int block_scale) { return region; } -__attribute__ ((constructor(101))) void mem_init (void) { +void mem_init (void) { #ifdef USE_SYSTEM_MALLOC return; #endif diff --git a/runtime/rcu.c b/runtime/rcu.c index 3e74986..0c49133 100644 --- a/runtime/rcu.c +++ b/runtime/rcu.c @@ -43,7 +43,7 @@ void rcu_thread_init (int id) { assert(id < MAX_NUM_THREADS); if (pending_[id] == NULL) { pending_[id] = fifo_alloc(RCU_QUEUE_SCALE); - SYNC_ADD(&num_threads_, 1); + (void)SYNC_ADD(&num_threads_, 1); } } diff --git a/runtime/rlocal.h b/runtime/rlocal.h index d6e90fa..bb62c76 100644 --- a/runtime/rlocal.h +++ b/runtime/rlocal.h @@ -4,6 +4,8 @@ #include "runtime.h" #include "tls.h" +void mem_init (void); + void rcu_thread_init (int thread_id); void lwt_thread_init (int thread_id); diff --git a/runtime/runtime.c b/runtime/runtime.c index b145faa..ceb6772 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -20,11 +20,12 @@ typedef struct thread_info { void *restrict arg; } thread_info_t; -__attribute__ ((constructor(102))) void nbd_init (void) { +__attribute__ ((constructor)) void nbd_init (void) { //sranddev(); INIT_THREAD_LOCAL(rand_seed_); INIT_THREAD_LOCAL(tid_); SET_THREAD_LOCAL(tid_, 0); + mem_init(); lwt_thread_init(0); rcu_thread_init(0); } diff --git a/test/haz_test.c b/test/haz_test.c index c55ad0e..a84c7be 100644 --- a/test/haz_test.c +++ b/test/haz_test.c @@ -36,7 +36,7 @@ void *worker (void *arg) { haz_t *hp0 = haz_get_static(0); // Wait for all the worker threads to be ready. - __sync_fetch_and_add(&wait_, -1); + (void)__sync_fetch_and_add(&wait_, -1); do {} while (wait_); int i; diff --git a/test/map_test1.c b/test/map_test1.c index 3acf4c2..ce6102c 100644 --- a/test/map_test1.c +++ b/test/map_test1.c @@ -23,7 +23,7 @@ static map_t *map_; void *worker (void *arg) { // Wait for all the worker threads to be ready. - SYNC_ADD(&wait_, -1); + (void)SYNC_ADD(&wait_, -1); do {} while (wait_); #ifdef TEST_STRING_KEYS diff --git a/test/map_test2.c b/test/map_test2.c index b660c1a..b239cfc 100644 --- a/test/map_test2.c +++ b/test/map_test2.c @@ -138,7 +138,7 @@ void *add_remove_worker (void *arg) { int d = wd->id; int iters = 10000; - SYNC_ADD(wd->wait, -1); + (void)SYNC_ADD(wd->wait, -1); do { } while (*wd->wait); // wait for all workers to be ready map_key_t key; diff --git a/test/rcu_test.c b/test/rcu_test.c index 3fd10d5..5181253 100644 --- a/test/rcu_test.c +++ b/test/rcu_test.c @@ -57,7 +57,7 @@ void *worker (void *arg) { unsigned int rand_seed = (unsigned int)id + 1; // Wait for all the worker threads to be ready. - __sync_fetch_and_add(&wait_, -1); + (void)__sync_fetch_and_add(&wait_, -1); do {} while (wait_); int i; diff --git a/txn/txn.c b/txn/txn.c index 20d0583..69f3b55 100644 --- a/txn/txn.c +++ b/txn/txn.c @@ -42,12 +42,13 @@ struct txn { static txn_state_e txn_validate (txn_t *txn); +static skiplist_t *active_ = NULL; + static version_t version_ = 1; -static skiplist_t *active_ = NULL; +static inline skiplist_t *get_active (void) { -__attribute__ ((constructor(103))) void txn_init (void) { - active_ = sl_alloc(NULL); + return active_; } // Validate the updates for . Validation fails if there is a write-write conflict. That is if after our @@ -124,7 +125,7 @@ static txn_state_e txn_validate (txn_t *txn) { case TXN_VALIDATING: if (txn->wv == UNDETERMINED_VERSION) { version_t wv = SYNC_ADD(&version_, 1); - SYNC_CAS(&txn->wv, UNDETERMINED_VERSION, wv); + (void)SYNC_CAS(&txn->wv, UNDETERMINED_VERSION, wv); } for (i = 0; i < txn->writes_count; ++i) { @@ -168,6 +169,12 @@ txn_t *txn_begin (map_t *map) { txn->map = map; txn->writes = nbd_malloc(sizeof(*txn->writes) * INITIAL_WRITES_SIZE); txn->writes_size = INITIAL_WRITES_SIZE; + if (EXPECT_FALSE(active_ == NULL)) { + skiplist_t *a = sl_alloc(NULL); + if (SYNC_CAS(&active_, NULL, a) != NULL) { + sl_free(a); + } + } // acquire the read version for txn. must be careful to avoid a race do { -- 2.40.0