From 1298a6c3355c10875734befcc4270ee86a189a1e Mon Sep 17 00:00:00 2001 From: David Joseph Date: Sun, 17 Feb 2013 22:05:12 -0600 Subject: [PATCH] Add support for MinGW32. This primarily involved changing the configure script and adding several utility functions to regressions/common.h for unit testing. Signed-off-by: Samy Al Bahra --- configure | 18 +- regressions/ck_bag/validate/order.c | 2 +- regressions/ck_barrier/benchmark/throughput.c | 2 +- regressions/ck_brlock/benchmark/throughput.c | 2 +- .../ck_hp/validate/ck_hp_fifo_donner.c | 2 +- .../ck_hs/benchmark/parallel_bytestring.c | 29 ++-- regressions/ck_hs/benchmark/serial.c | 4 +- .../ck_ht/benchmark/parallel_bytestring.c | 27 +-- regressions/ck_ht/benchmark/parallel_direct.c | 31 ++-- regressions/ck_ht/benchmark/serial.c | 4 +- regressions/ck_pr/benchmark/benchmark.h | 2 +- regressions/ck_pr/validate/ck_pr_add.c | 8 +- regressions/ck_pr/validate/ck_pr_and.c | 8 +- regressions/ck_pr/validate/ck_pr_bin.c | 6 +- regressions/ck_pr/validate/ck_pr_btc.c | 6 +- regressions/ck_pr/validate/ck_pr_btr.c | 6 +- regressions/ck_pr/validate/ck_pr_bts.c | 6 +- regressions/ck_pr/validate/ck_pr_btx.c | 6 +- regressions/ck_pr/validate/ck_pr_cas.c | 6 +- regressions/ck_pr/validate/ck_pr_dec.c | 6 +- regressions/ck_pr/validate/ck_pr_faa.c | 8 +- regressions/ck_pr/validate/ck_pr_fas.c | 8 +- regressions/ck_pr/validate/ck_pr_fax.c | 6 +- regressions/ck_pr/validate/ck_pr_inc.c | 6 +- regressions/ck_pr/validate/ck_pr_load.c | 6 +- regressions/ck_pr/validate/ck_pr_n.c | 6 +- regressions/ck_pr/validate/ck_pr_or.c | 8 +- regressions/ck_pr/validate/ck_pr_store.c | 4 +- regressions/ck_pr/validate/ck_pr_sub.c | 8 +- regressions/ck_pr/validate/ck_pr_xor.c | 8 +- regressions/ck_rwlock/benchmark/throughput.c | 2 +- .../ck_spinlock/benchmark/throughput.h | 4 +- regressions/ck_stack/validate/pair.c | 2 +- regressions/ck_stack/validate/pop.c | 2 +- regressions/ck_stack/validate/push.c | 2 +- regressions/common.h | 154 ++++++++++++++++++ 36 files changed, 313 insertions(+), 102 deletions(-) diff --git a/configure b/configure index 059ad61..8976c9d 100755 --- a/configure +++ b/configure @@ -249,7 +249,7 @@ fi DCORES=2 printf "Detecting operating system......." -SYSTEM=`uname -s 2> /dev/null` +SYSTEM=`uname -s 2> /dev/null | grep "^[A-Za-z0-9]*" -o` case "$SYSTEM" in "SunOS") SYSTEM=solaris @@ -278,6 +278,11 @@ case "$SYSTEM" in DCORES=`sysctl -n hw.ncpu` SYSTEM=darwin ;; + "MINGW32") + DCORES=2 + SYSTEM=mingw32 + LDFLAGS="-mthreads $LDFLAGS" + ;; *) SYSTEM= ;; @@ -481,7 +486,14 @@ assert "$CC" "not found" cat << EOF > .1.c #include int main(void) { -#if defined(__clang__) && (__clang_major__ >= 4) +#if defined(_WIN32) +#if defined(__MINGW32__) && (__MINGW32_MAJOR_VERSION >= 3) + puts("mingw32"); + return (0); +#else + return (1); +#endif +#elif defined(__clang__) && (__clang_major__ >= 4) puts("clang"); return (0); #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5110) @@ -512,7 +524,7 @@ if test "$COMPILER" = "suncc"; then LDFLAGS="-G -z text -h libck.so.$VERSION_MAJOR $LDFLAGS" CFLAGS="-xO5 $CFLAGS" PTHREAD_CFLAGS="-mt -lpthread" -elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang"; then +elif test "$COMPILER" = "gcc" || test "$COMPILER" = "clang" || test "$COMPILER" = "mingw32"; then LD=$CC if test "$SYSTEM" = "darwin"; then CC_WL_OPT="-install_name" diff --git a/regressions/ck_bag/validate/order.c b/regressions/ck_bag/validate/order.c index c11a69d..8f6de8f 100644 --- a/regressions/ck_bag/validate/order.c +++ b/regressions/ck_bag/validate/order.c @@ -279,7 +279,7 @@ main(int argc, char **argv) } fprintf(stderr, "Waiting..."); - sleep(30); + common_sleep(30); fprintf(stderr, "done\n"); ck_pr_store_int(&leave, 1); diff --git a/regressions/ck_barrier/benchmark/throughput.c b/regressions/ck_barrier/benchmark/throughput.c index 162db50..1a1c013 100644 --- a/regressions/ck_barrier/benchmark/throughput.c +++ b/regressions/ck_barrier/benchmark/throughput.c @@ -114,7 +114,7 @@ main(int argc, char *argv[]) } fprintf(stderr, "done\n"); - sleep(10); + common_sleep(10); count = 0; ck_pr_store_int(&done, 1); diff --git a/regressions/ck_brlock/benchmark/throughput.c b/regressions/ck_brlock/benchmark/throughput.c index 7efe05b..f952182 100644 --- a/regressions/ck_brlock/benchmark/throughput.c +++ b/regressions/ck_brlock/benchmark/throughput.c @@ -148,7 +148,7 @@ main(int argc, char *argv[]) } fprintf(stderr, "done\n"); - sleep(10); + common_sleep(10); ck_pr_store_uint(&flag, 1); fprintf(stderr, "Waiting for threads to finish acquisition regression..."); diff --git a/regressions/ck_hp/validate/ck_hp_fifo_donner.c b/regressions/ck_hp/validate/ck_hp_fifo_donner.c index 8bafaf8..a911b19 100644 --- a/regressions/ck_hp/validate/ck_hp_fifo_donner.c +++ b/regressions/ck_hp/validate/ck_hp_fifo_donner.c @@ -99,7 +99,7 @@ queue_50_50(void *elements) /* 50/50 enqueue-dequeue */ for(j = 0; j < element_count; j++) { /* rand_r with thread local state should be thread safe */ - if( 50 < (1+(int) (100.0*rand_r(&seed)/(RAND_MAX+1.0)))) { + if( 50 < (1+(int) (100.0*common_rand_r(&seed)/(RAND_MAX+1.0)))) { /* This is the container for the enqueued data. */ fifo_entry = malloc(sizeof(ck_hp_fifo_entry_t)); diff --git a/regressions/ck_hs/benchmark/parallel_bytestring.c b/regressions/ck_hs/benchmark/parallel_bytestring.c index 130a8b3..fa52b85 100644 --- a/regressions/ck_hs/benchmark/parallel_bytestring.c +++ b/regressions/ck_hs/benchmark/parallel_bytestring.c @@ -23,7 +23,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include "../../common.h" #include #include "../../../src/ck_ht_hash.h" @@ -71,6 +70,8 @@ struct hs_epoch { ck_epoch_entry_t epoch_entry; }; +COMMON_ALARM_DECLARE_GLOBAL(alarm_event, next_stage) + static void alarm_handler(int s) { @@ -142,8 +143,8 @@ set_init(void) ck_epoch_init(&epoch_hs); ck_epoch_register(&epoch_hs, &epoch_wr); - srand48((long int)time(NULL)); - if (ck_hs_init(&hs, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC, hs_hash, hs_compare, &my_allocator, 65536, lrand48()) == false) { + common_srand48((long int)time(NULL)); + if (ck_hs_init(&hs, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC, hs_hash, hs_compare, &my_allocator, 65536, common_lrand48()) == false) { perror("ck_hs_init"); exit(EXIT_FAILURE); } @@ -204,6 +205,7 @@ set_reset(void) return ck_hs_reset(&hs); } + static void * reader(void *unused) { @@ -285,6 +287,8 @@ main(int argc, char *argv[]) pthread_t *readers; double p_r, p_d; + COMMON_ALARM_DECLARE_LOCAL(alarm_event) + r = 20; s = 8; p_d = 0.5; @@ -323,6 +327,8 @@ main(int argc, char *argv[]) } } + COMMON_ALARM_INIT(alarm_event, r) + affinerator.delta = 1; readers = malloc(sizeof(pthread_t) * n_threads); assert(readers != NULL); @@ -446,7 +452,7 @@ main(int argc, char *argv[]) while (ck_pr_load_int(&barrier[HS_STATE_STOP]) != n_threads) ck_pr_stall(); ck_pr_inc_int(&barrier[HS_STATE_STOP]); - sleep(r); + common_sleep(r); ck_pr_store_int(&state, HS_STATE_STRICT_REPLACEMENT); while (ck_pr_load_int(&barrier[HS_STATE_GET]) != n_threads) ck_pr_stall(); @@ -457,8 +463,7 @@ main(int argc, char *argv[]) fprintf(stderr, " | Executing strict replacement test..."); a = repeated = 0; - signal(SIGALRM, alarm_handler); - alarm(r); + common_alarm(alarm_handler, &alarm_event, r); ck_pr_inc_int(&barrier[HS_STATE_GET]); for (;;) { @@ -483,8 +488,7 @@ main(int argc, char *argv[]) fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), acc(HS_STATE_STRICT_REPLACEMENT) / n_threads); - signal(SIGALRM, alarm_handler); - alarm(r); + common_alarm(alarm_handler, &alarm_event, r); fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100); a = repeated = 0; @@ -497,7 +501,7 @@ main(int argc, char *argv[]) for (i = 0; i < keys_length; i++) { set_insert(keys[i]); if (p_d != 0.0) { - delete = drand48(); + delete = common_drand48(); if (delete <= p_d) set_remove(keys[i]); } @@ -519,8 +523,7 @@ main(int argc, char *argv[]) fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), acc(HS_STATE_DELETION) / n_threads); - signal(SIGALRM, alarm_handler); - alarm(r); + common_alarm(alarm_handler, &alarm_event, r); fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100); a = repeated = 0; @@ -533,12 +536,12 @@ main(int argc, char *argv[]) for (i = 0; i < keys_length; i++) { set_insert(keys[i]); if (p_d != 0.0) { - delete = drand48(); + delete = common_drand48(); if (delete <= p_d) set_remove(keys[i]); } if (p_r != 0.0) { - replace = drand48(); + replace = common_drand48(); if (replace <= p_r) set_replace(keys[i]); } diff --git a/regressions/ck_hs/benchmark/serial.c b/regressions/ck_hs/benchmark/serial.c index 7bb3c51..5b1cf03 100644 --- a/regressions/ck_hs/benchmark/serial.c +++ b/regressions/ck_hs/benchmark/serial.c @@ -88,8 +88,8 @@ static void set_init(void) { - srand48((long int)time(NULL)); - if (ck_hs_init(&hs, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC, hs_hash, hs_compare, &my_allocator, 8, lrand48()) == false) { + common_srand48((long int)time(NULL)); + if (ck_hs_init(&hs, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC, hs_hash, hs_compare, &my_allocator, 8, common_lrand48()) == false) { perror("ck_hs_init"); exit(EXIT_FAILURE); } diff --git a/regressions/ck_ht/benchmark/parallel_bytestring.c b/regressions/ck_ht/benchmark/parallel_bytestring.c index f2d710c..4f222ec 100644 --- a/regressions/ck_ht/benchmark/parallel_bytestring.c +++ b/regressions/ck_ht/benchmark/parallel_bytestring.c @@ -71,6 +71,8 @@ struct ht_epoch { ck_epoch_entry_t epoch_entry; }; +COMMON_ALARM_DECLARE_GLOBAL(alarm_event, next_stage) + static void alarm_handler(int s) { @@ -125,8 +127,8 @@ table_init(void) ck_epoch_init(&epoch_ht); ck_epoch_register(&epoch_ht, &epoch_wr); - srand48((long int)time(NULL)); - if (ck_ht_init(&ht, CK_HT_MODE_BYTESTRING, NULL, &my_allocator, 8, lrand48()) == false) { + common_srand48((long int)time(NULL)); + if (ck_ht_init(&ht, CK_HT_MODE_BYTESTRING, NULL, &my_allocator, 8, common_lrand48()) == false) { perror("ck_ht_init"); exit(EXIT_FAILURE); } @@ -263,6 +265,8 @@ main(int argc, char *argv[]) pthread_t *readers; double p_r, p_d; + COMMON_ALARM_DECLARE_LOCAL(alarm_event) + r = 20; s = 8; p_d = 0.5; @@ -301,6 +305,8 @@ main(int argc, char *argv[]) } } + COMMON_ALARM_INIT(alarm_event, r) + affinerator.delta = 1; readers = malloc(sizeof(pthread_t) * n_threads); assert(readers != NULL); @@ -424,7 +430,7 @@ main(int argc, char *argv[]) while (ck_pr_load_int(&barrier[HT_STATE_STOP]) != n_threads) ck_pr_stall(); ck_pr_inc_int(&barrier[HT_STATE_STOP]); - sleep(r); + common_sleep(r); ck_pr_store_int(&state, HT_STATE_STRICT_REPLACEMENT); while (ck_pr_load_int(&barrier[HT_STATE_GET]) != n_threads) ck_pr_stall(); @@ -434,8 +440,7 @@ main(int argc, char *argv[]) fprintf(stderr, " | Executing strict replacement test..."); a = repeated = 0; - signal(SIGALRM, alarm_handler); - alarm(r); + common_alarm(alarm_handler, &alarm_event, r); ck_pr_inc_int(&barrier[HT_STATE_GET]); for (;;) { @@ -460,8 +465,7 @@ main(int argc, char *argv[]) fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_STRICT_REPLACEMENT] / n_threads); - signal(SIGALRM, alarm_handler); - alarm(r); + common_alarm(alarm_handler, &alarm_event, r); fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100); a = repeated = 0; @@ -474,7 +478,7 @@ main(int argc, char *argv[]) for (i = 0; i < keys_length; i++) { table_insert(keys[i]); if (p_d != 0.0) { - delete = drand48(); + delete = common_drand48(); if (delete <= p_d) table_remove(keys[i]); } @@ -496,8 +500,7 @@ main(int argc, char *argv[]) fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_DELETION] / n_threads); - signal(SIGALRM, alarm_handler); - alarm(r); + common_alarm(alarm_handler, &alarm_event, r); fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100); a = repeated = 0; @@ -510,12 +513,12 @@ main(int argc, char *argv[]) for (i = 0; i < keys_length; i++) { table_insert(keys[i]); if (p_d != 0.0) { - delete = drand48(); + delete = common_drand48(); if (delete <= p_d) table_remove(keys[i]); } if (p_r != 0.0) { - replace = drand48(); + replace = common_drand48(); if (replace <= p_r) table_replace(keys[i]); } diff --git a/regressions/ck_ht/benchmark/parallel_direct.c b/regressions/ck_ht/benchmark/parallel_direct.c index 56a054f..067e8f1 100644 --- a/regressions/ck_ht/benchmark/parallel_direct.c +++ b/regressions/ck_ht/benchmark/parallel_direct.c @@ -70,6 +70,8 @@ struct ht_epoch { ck_epoch_entry_t epoch_entry; }; +COMMON_ALARM_DECLARE_GLOBAL(alarm_event, next_stage) + static void alarm_handler(int s) { @@ -135,8 +137,8 @@ table_init(void) ck_epoch_init(&epoch_ht); ck_epoch_register(&epoch_ht, &epoch_wr); - srand48((long int)time(NULL)); - if (ck_ht_init(&ht, CK_HT_MODE_DIRECT, hash_function, &my_allocator, 8, lrand48()) == false) { + common_srand48((long int)time(NULL)); + if (ck_ht_init(&ht, CK_HT_MODE_DIRECT, hash_function, &my_allocator, 8, common_lrand48()) == false) { perror("ck_ht_init"); exit(EXIT_FAILURE); } @@ -267,6 +269,8 @@ main(int argc, char *argv[]) pthread_t *readers; double p_r, p_d; + COMMON_ALARM_DECLARE_LOCAL(alarm_event) + r = 20; s = 8; p_d = 0.5; @@ -305,6 +309,8 @@ main(int argc, char *argv[]) } } + COMMON_ALARM_INIT(alarm_event, r) + affinerator.delta = 1; readers = malloc(sizeof(pthread_t) * n_threads); assert(readers != NULL); @@ -316,9 +322,9 @@ main(int argc, char *argv[]) table_init(); for (i = 0; i < keys_length; i++) { - keys[i] = (uintptr_t)lrand48(); + keys[i] = (uintptr_t)common_lrand48(); while (keys[i] == 2) - keys[i] = (uintptr_t)lrand48(); + keys[i] = (uintptr_t)common_lrand48(); } for (i = 0; i < (size_t)n_threads; i++) { @@ -415,7 +421,7 @@ main(int argc, char *argv[]) while (ck_pr_load_int(&barrier[HT_STATE_STOP]) != n_threads) ck_pr_stall(); ck_pr_inc_int(&barrier[HT_STATE_STOP]); - sleep(r); + common_sleep(r); ck_pr_store_int(&state, HT_STATE_STRICT_REPLACEMENT); while (ck_pr_load_int(&barrier[HT_STATE_GET]) != n_threads) ck_pr_stall(); @@ -425,8 +431,7 @@ main(int argc, char *argv[]) fprintf(stderr, " | Executing strict replacement test..."); a = repeated = 0; - signal(SIGALRM, alarm_handler); - alarm(r); + common_alarm(alarm_handler, &alarm_event, r); ck_pr_inc_int(&barrier[HT_STATE_GET]); for (;;) { @@ -451,8 +456,7 @@ main(int argc, char *argv[]) fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_STRICT_REPLACEMENT] / n_threads); - signal(SIGALRM, alarm_handler); - alarm(r); + common_alarm(alarm_handler, &alarm_event, r); fprintf(stderr, " | Executing deletion test (%.2f)...", p_d * 100); a = repeated = 0; @@ -465,7 +469,7 @@ main(int argc, char *argv[]) for (i = 0; i < keys_length; i++) { table_insert(keys[i]); if (p_d != 0.0) { - delete = drand48(); + delete = common_drand48(); if (delete <= p_d) table_remove(keys[i]); } @@ -487,8 +491,7 @@ main(int argc, char *argv[]) fprintf(stderr, "done (writer = %" PRIu64 " ticks, reader = %" PRIu64 " ticks)\n", a / (repeated * keys_length), accumulator[HT_STATE_DELETION] / n_threads); - signal(SIGALRM, alarm_handler); - alarm(r); + common_alarm(alarm_handler, &alarm_event, r); fprintf(stderr, " | Executing replacement test (%.2f)...", p_r * 100); a = repeated = 0; @@ -501,12 +504,12 @@ main(int argc, char *argv[]) for (i = 0; i < keys_length; i++) { table_insert(keys[i]); if (p_d != 0.0) { - delete = drand48(); + delete = common_drand48(); if (delete <= p_d) table_remove(keys[i]); } if (p_r != 0.0) { - replace = drand48(); + replace = common_drand48(); if (replace <= p_r) table_replace(keys[i]); } diff --git a/regressions/ck_ht/benchmark/serial.c b/regressions/ck_ht/benchmark/serial.c index ecee9e9..15797f6 100644 --- a/regressions/ck_ht/benchmark/serial.c +++ b/regressions/ck_ht/benchmark/serial.c @@ -72,8 +72,8 @@ static void table_init(void) { - srand48((long int)time(NULL)); - if (ck_ht_init(&ht, CK_HT_MODE_BYTESTRING, NULL, &my_allocator, 8, lrand48()) == false) { + common_srand48((long int)time(NULL)); + if (ck_ht_init(&ht, CK_HT_MODE_BYTESTRING, NULL, &my_allocator, 8, common_lrand48()) == false) { perror("ck_ht_init"); exit(EXIT_FAILURE); } diff --git a/regressions/ck_pr/benchmark/benchmark.h b/regressions/ck_pr/benchmark/benchmark.h index 197ae8c..24cd42c 100644 --- a/regressions/ck_pr/benchmark/benchmark.h +++ b/regressions/ck_pr/benchmark/benchmark.h @@ -103,7 +103,7 @@ main(int argc, char *argv[]) fprintf(stderr, "done\n"); ck_pr_store_uint(&ready, 1); - sleep(10); + common_sleep(10); ck_pr_store_uint(&ready, 0); fprintf(stderr, "Waiting for threads to finish acquisition regression..."); diff --git a/regressions/ck_pr/validate/ck_pr_add.c b/regressions/ck_pr/validate/ck_pr_add.c index 755a1c3..31f1893 100644 --- a/regressions/ck_pr/validate/ck_pr_add.c +++ b/regressions/ck_pr/validate/ck_pr_add.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -56,8 +57,8 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = random() % ((uint##w##_t)-1 / 2); \ - uint##w##_t b = random() % ((uint##w##_t)-1 / 2); \ + uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \ + uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \ CK_PR_ADD_T(w, a, b); \ } \ rg_width(w); \ @@ -127,7 +128,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_ADD_64 CK_PR_ADD_B(64); @@ -147,3 +148,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_and.c b/regressions/ck_pr/validate/ck_pr_and.c index 792ffe9..4c569bb 100644 --- a/regressions/ck_pr/validate/ck_pr_and.c +++ b/regressions/ck_pr/validate/ck_pr_and.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -58,8 +59,8 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = (uint##w##_t)random(); \ - uint##w##_t b = (uint##w##_t)random(); \ + uint##w##_t a = (uint##w##_t)common_rand(); \ + uint##w##_t b = (uint##w##_t)common_rand(); \ CK_PR_AND_T(w, a, b); \ } \ rg_width(w); \ @@ -123,7 +124,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_AND_64 CK_PR_AND_B(64); @@ -143,3 +144,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_bin.c b/regressions/ck_pr/validate/ck_pr_bin.c index ef3f7d2..31868f4 100644 --- a/regressions/ck_pr/validate/ck_pr_bin.c +++ b/regressions/ck_pr/validate/ck_pr_bin.c @@ -29,6 +29,7 @@ #include #include +#include "../../common.h" #define REPEAT 2000000 #define TEST_BINARY(K, S, T, P, D) \ @@ -40,9 +41,9 @@ T ck_result = 65535; \ \ puts("***TESTING ck_pr_" #K "_" #S "***"); \ - srandom((unsigned int)getpid()); \ + common_srand((unsigned int)getpid()); \ for (i = 0; i < REPEAT; ++i) { \ - r = random(); \ + r = common_rand(); \ serial_result = serial_result P r; \ ck_pr_##K##_##S(&ck_result, r); \ } \ @@ -90,3 +91,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_btc.c b/regressions/ck_pr/validate/ck_pr_btc.c index 0b799f6..0edec98 100644 --- a/regressions/ck_pr/validate/ck_pr_btc.c +++ b/regressions/ck_pr/validate/ck_pr_btc.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -62,7 +63,7 @@ unsigned int i; \ printf("ck_pr_btc_" #w ": "); \ for (i = 0; i < R_REPEAT; i++) { \ - o = (uint##w##_t)random(); \ + o = (uint##w##_t)common_rand(); \ CK_PR_BTC_T(w, o); \ } \ printf(" SUCCESS\n"); \ @@ -72,7 +73,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_BTC_64 CK_PR_BTC_B(64); @@ -92,3 +93,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_btr.c b/regressions/ck_pr/validate/ck_pr_btr.c index 63e1fdb..91abb30 100644 --- a/regressions/ck_pr/validate/ck_pr_btr.c +++ b/regressions/ck_pr/validate/ck_pr_btr.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -63,7 +64,7 @@ unsigned int i; \ printf("ck_pr_btr_" #w ": "); \ for (i = 0; i < R_REPEAT; i++) { \ - o = (uint##w##_t)random(); \ + o = (uint##w##_t)common_rand(); \ CK_PR_BTR_T(w, o); \ } \ printf(" SUCCESS\n"); \ @@ -73,7 +74,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_BTR_64 CK_PR_BTR_B(64); @@ -93,3 +94,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_bts.c b/regressions/ck_pr/validate/ck_pr_bts.c index 6a1085f..1e62165 100644 --- a/regressions/ck_pr/validate/ck_pr_bts.c +++ b/regressions/ck_pr/validate/ck_pr_bts.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -63,7 +64,7 @@ unsigned int i; \ printf("ck_pr_bts_" #w ": "); \ for (i = 0; i < R_REPEAT; i++) { \ - o = (uint##w##_t)random(); \ + o = (uint##w##_t)common_rand(); \ CK_PR_BTS_T(w, o); \ } \ printf(" SUCCESS\n"); \ @@ -73,7 +74,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_BTS_64 CK_PR_BTS_B(64); @@ -93,3 +94,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_btx.c b/regressions/ck_pr/validate/ck_pr_btx.c index e0fb732..2bb3964 100644 --- a/regressions/ck_pr/validate/ck_pr_btx.c +++ b/regressions/ck_pr/validate/ck_pr_btx.c @@ -30,6 +30,7 @@ #include #include +#include "../../common.h" #define REPEAT 2000000 #define TEST_BTX(K, S, M, T, L, P, D, R) \ @@ -50,12 +51,12 @@ bool serial_t, ck_pr_t; \ T x = 65535, y = 65535; \ \ - srandom((unsigned int)getpid()); \ + common_srand((unsigned int)getpid()); \ m = sizeof(T) * 8; \ \ puts("***TESTING ck_pr_"#K"_"#S"***"); \ for (i = 0; i < REPEAT; ++i) { \ - offset = random() % m; \ + offset = common_rand() % m; \ serial_t = test_##K##_##S(&x, offset); \ ck_pr_t = ck_pr_##K##_##S(&y, offset); \ \ @@ -108,3 +109,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_cas.c b/regressions/ck_pr/validate/ck_pr_cas.c index 2069c82..132d1e5 100644 --- a/regressions/ck_pr/validate/ck_pr_cas.c +++ b/regressions/ck_pr/validate/ck_pr_cas.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -60,7 +61,7 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = random() % (uint##w##_t)-1; \ + uint##w##_t a = common_rand() % (uint##w##_t)-1; \ CK_PR_CAS_T(w, a, a + 1, (a - 1)); \ CK_PR_CAS_T(w, a, a, (a - 1)); \ CK_PR_CAS_T(w, a, a + 1, a); \ @@ -126,7 +127,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_CAS_64 CK_PR_CAS_B(64); @@ -154,3 +155,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_dec.c b/regressions/ck_pr/validate/ck_pr_dec.c index 6898c34..86ce088 100644 --- a/regressions/ck_pr/validate/ck_pr_dec.c +++ b/regressions/ck_pr/validate/ck_pr_dec.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -55,7 +56,7 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = random() % ((uint##w##_t)-1); \ + uint##w##_t a = common_rand() % ((uint##w##_t)-1); \ CK_PR_DEC_T(w, a); \ } \ rg_width(w); \ @@ -119,7 +120,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_DEC_64 CK_PR_DEC_B(64); @@ -139,3 +140,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_faa.c b/regressions/ck_pr/validate/ck_pr_faa.c index ce7bae4..1d10bb9 100644 --- a/regressions/ck_pr/validate/ck_pr_faa.c +++ b/regressions/ck_pr/validate/ck_pr_faa.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -57,8 +58,8 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = random() % ((uint##w##_t)-1 / 2); \ - uint##w##_t b = random() % ((uint##w##_t)-1 / 2); \ + uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \ + uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \ CK_PR_FAA_T(w, a, b); \ } \ rg_width(w); \ @@ -128,7 +129,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_FAA_64 CK_PR_FAA_B(64); @@ -148,3 +149,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_fas.c b/regressions/ck_pr/validate/ck_pr_fas.c index 56d674f..00cef4e 100644 --- a/regressions/ck_pr/validate/ck_pr_fas.c +++ b/regressions/ck_pr/validate/ck_pr_fas.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -59,8 +60,8 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = random(); \ - uint##w##_t b = random(); \ + uint##w##_t a = common_rand(); \ + uint##w##_t b = common_rand(); \ CK_PR_FAS_T(w, a, b); \ } \ rg_width(w); \ @@ -124,7 +125,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_FAS_64 CK_PR_FAS_B(64); @@ -144,3 +145,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_fax.c b/regressions/ck_pr/validate/ck_pr_fax.c index 4a1aca5..9d8c94f 100644 --- a/regressions/ck_pr/validate/ck_pr_fax.c +++ b/regressions/ck_pr/validate/ck_pr_fax.c @@ -29,6 +29,7 @@ #include #include +#include "../../common.h" #define REPEAT 2000000 #define TEST_FAX_FN(S, T, M) \ @@ -65,9 +66,9 @@ TEST_FAX_FN_S(uint, unsigned int) T x = 0, y = 0, x_b, y_b; \ \ puts("***TESTING ck_pr_"#K"_"#S"***"); \ - srandom((unsigned int)getpid()); \ + common_srand((unsigned int)getpid()); \ for (i = 0; i < REPEAT; ++i) { \ - r = random(); \ + r = common_rand(); \ x_b = test_##K##_##S(&x, r); \ y_b = ck_pr_##K##_##S(&y, r); \ \ @@ -117,3 +118,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_inc.c b/regressions/ck_pr/validate/ck_pr_inc.c index 62afc33..e8524a5 100644 --- a/regressions/ck_pr/validate/ck_pr_inc.c +++ b/regressions/ck_pr/validate/ck_pr_inc.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -55,7 +56,7 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = random() % ((uint##w##_t)-1); \ + uint##w##_t a = common_rand() % ((uint##w##_t)-1); \ CK_PR_INC_T(w, a); \ } \ rg_width(w); \ @@ -119,7 +120,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_INC_64 CK_PR_INC_B(64); @@ -139,3 +140,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_load.c b/regressions/ck_pr/validate/ck_pr_load.c index c112b81..a15acd0 100644 --- a/regressions/ck_pr/validate/ck_pr_load.c +++ b/regressions/ck_pr/validate/ck_pr_load.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -50,7 +51,7 @@ exit(EXIT_FAILURE); \ } \ for (i = 0; i < R_REPEAT; i++) { \ - t = (uint##w##_t)random(); \ + t = (uint##w##_t)common_rand(); \ a = ck_pr_load_##w(&t); \ if (a != t) { \ printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t);\ @@ -118,7 +119,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_LOAD_64 CK_PR_LOAD_B(64); @@ -145,3 +146,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_n.c b/regressions/ck_pr/validate/ck_pr_n.c index 17ea1c6..81e3639 100644 --- a/regressions/ck_pr/validate/ck_pr_n.c +++ b/regressions/ck_pr/validate/ck_pr_n.c @@ -29,6 +29,7 @@ #include #include +#include "../../common.h" #define REPEAT 2000000 #define TEST_N(K, S, T, P, D) \ @@ -39,9 +40,9 @@ T x = 0, y = 0; \ \ puts("***TESTING ck_pr_"#K"_"#S"***"); \ - srandom((unsigned int)getpid()); \ + common_srand((unsigned int)getpid()); \ for (i = 0; i < REPEAT; ++i) { \ - r = random(); \ + r = common_rand(); \ x += r; \ x = P x; \ y += r; \ @@ -86,3 +87,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_or.c b/regressions/ck_pr/validate/ck_pr_or.c index 37f552d..8c797a2 100644 --- a/regressions/ck_pr/validate/ck_pr_or.c +++ b/regressions/ck_pr/validate/ck_pr_or.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -58,8 +59,8 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = (uint##w##_t)random(); \ - uint##w##_t b = (uint##w##_t)random(); \ + uint##w##_t a = (uint##w##_t)common_rand(); \ + uint##w##_t b = (uint##w##_t)common_rand(); \ CK_PR_OR_T(w, a, b); \ } \ rg_width(w); \ @@ -123,7 +124,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_OR_64 CK_PR_OR_B(64); @@ -143,3 +144,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_store.c b/regressions/ck_pr/validate/ck_pr_store.c index b286b1a..23b6d47 100644 --- a/regressions/ck_pr/validate/ck_pr_store.c +++ b/regressions/ck_pr/validate/ck_pr_store.c @@ -51,7 +51,7 @@ exit(EXIT_FAILURE); \ } \ for (i = 0; i < R_REPEAT; i++) { \ - t = (uint##w##_t)random(); \ + t = (uint##w##_t)common_rand(); \ ck_pr_store_##w(&a, t); \ if (a != t) { \ printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t);\ @@ -127,7 +127,7 @@ main(void) } #endif - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_STORE_64 CK_PR_STORE_B(64); diff --git a/regressions/ck_pr/validate/ck_pr_sub.c b/regressions/ck_pr/validate/ck_pr_sub.c index d6303ba..f515914 100644 --- a/regressions/ck_pr/validate/ck_pr_sub.c +++ b/regressions/ck_pr/validate/ck_pr_sub.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -56,8 +57,8 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = random() % ((uint##w##_t)-1 / 2); \ - uint##w##_t b = random() % ((uint##w##_t)-1 / 2); \ + uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \ + uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \ CK_PR_SUB_T(w, a, b); \ } \ rg_width(w); \ @@ -127,7 +128,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_SUB_64 CK_PR_SUB_B(64); @@ -147,3 +148,4 @@ main(void) return (0); } + diff --git a/regressions/ck_pr/validate/ck_pr_xor.c b/regressions/ck_pr/validate/ck_pr_xor.c index e395cfe..4515cc4 100644 --- a/regressions/ck_pr/validate/ck_pr_xor.c +++ b/regressions/ck_pr/validate/ck_pr_xor.c @@ -33,6 +33,7 @@ #include +#include "../../common.h" #ifndef R_REPEAT #define R_REPEAT 200000 #endif @@ -58,8 +59,8 @@ if (w < 10) \ printf(" "); \ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \ - uint##w##_t a = (uint##w##_t)random(); \ - uint##w##_t b = (uint##w##_t)random(); \ + uint##w##_t a = (uint##w##_t)common_rand(); \ + uint##w##_t b = (uint##w##_t)common_rand(); \ CK_PR_XOR_T(w, a, b); \ } \ rg_width(w); \ @@ -123,7 +124,7 @@ int main(void) { - srandom((unsigned int)getpid()); + common_srand((unsigned int)getpid()); #ifdef CK_F_PR_XOR_64 CK_PR_XOR_B(64); @@ -143,3 +144,4 @@ main(void) return (0); } + diff --git a/regressions/ck_rwlock/benchmark/throughput.c b/regressions/ck_rwlock/benchmark/throughput.c index 133f13d..bb244f5 100644 --- a/regressions/ck_rwlock/benchmark/throughput.c +++ b/regressions/ck_rwlock/benchmark/throughput.c @@ -146,7 +146,7 @@ main(int argc, char *argv[]) } fprintf(stderr, "done\n"); - sleep(10); + common_sleep(10); ck_pr_store_uint(&flag, 1); fprintf(stderr, "Waiting for threads to finish acquisition regression..."); diff --git a/regressions/ck_spinlock/benchmark/throughput.h b/regressions/ck_spinlock/benchmark/throughput.h index a66091c..f2a8c63 100644 --- a/regressions/ck_spinlock/benchmark/throughput.h +++ b/regressions/ck_spinlock/benchmark/throughput.h @@ -117,7 +117,7 @@ fairness(void *null) count[i].value++; if (critical) { - base = lrand48() % critical; + base = common_lrand48() % critical; for (j = 0; j < base; j++); } @@ -189,7 +189,7 @@ main(int argc, char *argv[]) fprintf(stderr, "done\n"); ck_pr_store_uint(&ready, 1); - sleep(10); + common_sleep(10); ck_pr_store_uint(&ready, 0); fprintf(stderr, "Waiting for threads to finish acquisition regression..."); diff --git a/regressions/ck_stack/validate/pair.c b/regressions/ck_stack/validate/pair.c index 26c8dbe..c26b11c 100644 --- a/regressions/ck_stack/validate/pair.c +++ b/regressions/ck_stack/validate/pair.c @@ -120,7 +120,7 @@ stack_thread(void *buffer) #endif if (critical) { - j = rand_r(&seed) % critical; + j = common_rand_r(&seed) % critical; while (j--) __asm__ __volatile__("" ::: "memory"); } diff --git a/regressions/ck_stack/validate/pop.c b/regressions/ck_stack/validate/pop.c index 46b22eb..3d06aef 100644 --- a/regressions/ck_stack/validate/pop.c +++ b/regressions/ck_stack/validate/pop.c @@ -127,7 +127,7 @@ stack_thread(void *unused CK_CC_UNUSED) #endif if (critical) { - j = rand_r(&seed) % critical; + j = common_rand_r(&seed) % critical; while (j--) __asm__ __volatile__("" ::: "memory"); } diff --git a/regressions/ck_stack/validate/push.c b/regressions/ck_stack/validate/push.c index 3e0deb6..44d515b 100644 --- a/regressions/ck_stack/validate/push.c +++ b/regressions/ck_stack/validate/push.c @@ -122,7 +122,7 @@ stack_thread(void *buffer) #endif if (critical) { - j = rand_r(&seed) % critical; + j = common_rand_r(&seed) % critical; while (j--) __asm__ __volatile__("" ::: "memory"); } diff --git a/regressions/common.h b/regressions/common.h index a7c5599..df256b3 100644 --- a/regressions/common.h +++ b/regressions/common.h @@ -38,12 +38,165 @@ #elif defined(__MACH__) #include #include +#include +#elif defined(_WIN32) +#include +#include #endif #ifndef CORES #define CORES 8 #endif +CK_CC_INLINE static void +common_srand(unsigned int i) +{ +#ifdef _WIN32 + srand(i); +#else + srandom(i); +#endif +} + +CK_CC_INLINE static int +common_rand(void) +{ +#ifdef _WIN32 + return rand(); +#else + return random(); +#endif +} + +CK_CC_INLINE static int +common_rand_r(unsigned int *i) +{ +#ifdef _WIN32 + (void)i; + + /* + * When linked with -mthreads, rand() is thread-safe. + * rand_s is also an option. + */ + return rand(); +#else + return rand_r(i); +#endif +} + +CK_CC_INLINE static void +common_srand48(long int i) +{ +#ifdef _WIN32 + srand(i); +#else + srand48(i); +#endif +} + +CK_CC_INLINE static long int +common_lrand48(void) +{ +#ifdef _WIN32 + return rand(); +#else + return lrand48(); +#endif +} + +CK_CC_INLINE static double +common_drand48(void) +{ +#ifdef _WIN32 + return (double)rand()/RAND_MAX; +#else + return drand48(); +#endif +} + +CK_CC_INLINE static void +common_sleep(unsigned int n) +{ +#ifdef _WIN32 + Sleep(n * 1000); +#else + sleep(n); +#endif +} + +CK_CC_UNUSED static unsigned int +common_alarm(void (*sig_handler)(int), void *alarm_event, unsigned int duration) +{ +#ifdef _WIN32 + (void)sig_handler; + (void)duration; + bool success; + HANDLE *alarm_handle = (HANDLE *)alarm_event; + success = SetEvent(*alarm_handle); + assert(success != false); + return 0; +#else + (void)alarm_event; + signal(SIGALRM, sig_handler); + return alarm(duration); +#endif +} + +#ifdef _WIN32 +#ifndef SECOND_TIMER +#define SECOND_TIMER 10000000 +#endif +#define COMMON_ALARM_DECLARE_GLOBAL(alarm_event_name, flag_name) \ +static HANDLE common_win_alarm_timer; \ +static HANDLE alarm_event_name; \ +static LARGE_INTEGER timer_length; \ + \ +static void CALLBACK \ +common_win_alarm_handler(LPVOID arg, DWORD timer_low_value, DWORD timer_high_value) \ +{ \ + (void)arg; \ + (void)timer_low_value; \ + (void)timer_high_value; \ + flag_name = true; \ + return; \ +} \ + \ +static void * \ +common_win_alarm(void *unused) \ +{ \ + (void)unused; \ + bool timer_success = false; \ + for (;;) { \ + WaitForSingleObjectEx(alarm_event_name, INFINITE, true); \ + timer_success = SetWaitableTimer(common_win_alarm_timer, &timer_length, 0, common_win_alarm_handler, NULL, false); \ + assert(timer_success != false); \ + WaitForSingleObjectEx(common_win_alarm_timer, INFINITE, true); \ + } \ + \ + return NULL; \ +} + +#define COMMON_ALARM_DECLARE_LOCAL(alarm_event_name) \ + __int64 tl; \ + pthread_t common_win_alarm_thread; + +#define COMMON_ALARM_INIT(alarm_event_name, duration) \ + tl = -1 * duration * SECOND_TIMER; \ + timer_length.LowPart = (DWORD) (tl & 0xFFFFFFFF); \ + timer_length.HighPart = (LONG) (tl >> 32); \ + alarm_event_name = CreateEvent(NULL, false, false, NULL); \ + assert(alarm_event_name != NULL); \ + common_win_alarm_timer = CreateWaitableTimer(NULL, true, NULL); \ + assert(common_win_alarm_timer != NULL); \ + if (pthread_create(&common_win_alarm_thread, NULL, common_win_alarm, NULL) != 0) \ + ck_error("ERROR: Failed to create common_win_alarm thread.\n"); +#else +#define COMMON_ALARM_DECLARE_GLOBAL(alarm_event_name, flag_name) +#define COMMON_ALARM_DECLARE_LOCAL(alarm_event_name) \ + int alarm_event_name = 0; +#define COMMON_ALARM_INIT(alarm_event_name, duration) +#endif + struct affinity { unsigned int delta; unsigned int request; @@ -161,3 +314,4 @@ ck_error(const char *message, ...) exit(EXIT_FAILURE); } +