X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=test%2Fhaz_test.c;h=1514efaf0a93a2a1a32aa2db9902b2ddc534e1dc;hp=3b9092afe7678f68a2295aa72661378511c46d1d;hb=HEAD;hpb=a1d0b3ca99552878b1becf561d8f3291992aaa67 diff --git a/test/haz_test.c b/test/haz_test.c index 3b9092a..1514efa 100644 --- a/test/haz_test.c +++ b/test/haz_test.c @@ -17,7 +17,6 @@ #include "hazard.h" #define NUM_ITERATIONS 10000000 -#define MAX_NUM_THREADS 4 typedef struct node { struct node *next; @@ -32,16 +31,16 @@ static lifo_t *stk_; void *worker (void *arg) { int id = (int)(size_t)arg; - unsigned int r = (unsigned int)(id + 1) * 0x5bd1e995; // seed "random" number generator + unsigned int r = (unsigned int)(id + 1) * 0x5bd1e995; // seed psuedo-random number generator haz_t *hp0 = haz_get_static(0); // Wait for all the worker threads to be ready. - __sync_fetch_and_add(&wait_, -1); + (void)SYNC_ADD(&wait_, -1); do {} while (wait_); int i; for (i = 0; i < NUM_ITERATIONS; ++ i) { - r ^= r << 6; r ^= r >> 21; r ^= r << 7; // generate next "random" number + r ^= r << 6; r ^= r >> 21; r ^= r << 7; // generate next psuedo-random number if (r & 0x1000) { // push node_t *new_head = (node_t *)nbd_malloc(sizeof(node_t)); @@ -50,7 +49,7 @@ void *worker (void *arg) { do { temp = old_head; new_head->next = temp; - } while ((old_head = __sync_val_compare_and_swap(&stk_->head, temp, new_head)) != temp); + } while ((old_head = SYNC_CAS(&stk_->head, temp, new_head)) != temp); } else { // pop node_t *temp; @@ -60,10 +59,10 @@ void *worker (void *arg) { if (temp == NULL) break; haz_set(hp0, temp); - head = ((volatile lifo_t *)stk_)->head; + head = VOLATILE_DEREF(stk_).head; if (temp != head) continue; - } while ((head = __sync_val_compare_and_swap(&stk_->head, temp, temp->next)) != temp); + } while ((head = SYNC_CAS(&stk_->head, temp, temp->next)) != temp); if (temp != NULL) { haz_defer_free(temp, nbd_free); @@ -77,7 +76,7 @@ void *worker (void *arg) { int main (int argc, char **argv) { //lwt_set_trace_level("m0r0"); - int num_threads = 2; + int num_threads = MAX_NUM_THREADS; if (argc == 2) { errno = 0;