From bef3ea48184b0d6b68e7636e21e72a07a66eefe9 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 9 Nov 2012 03:51:47 +0100 Subject: [PATCH] bench: squelch -Wstrict-aliasing warnings --- test/benchmark-async-pummel.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/benchmark-async-pummel.c b/test/benchmark-async-pummel.c index 49cf442b..a4eb48ca 100644 --- a/test/benchmark-async-pummel.c +++ b/test/benchmark-async-pummel.c @@ -25,19 +25,24 @@ #include #include -#define NUM_PINGS (1000 * 1000) +#define NUM_PINGS (1000 * 1000) +#define ACCESS_ONCE(type, var) (*(volatile type*) &(var)) static unsigned int callbacks; static volatile int done; +static const char running[] = "running"; +static const char stop[] = "stop"; +static const char stopped[] = "stopped"; + static void async_cb(uv_async_t* handle, int status) { if (++callbacks == NUM_PINGS) { /* Tell the pummel thread to stop. */ - handle->data = (void*) (intptr_t) 1; + ACCESS_ONCE(const char*, handle->data) = stop; /* Wait for for the pummel thread to acknowledge that it has stoppped. */ - while (*(volatile intptr_t*) &handle->data < 2) + while (ACCESS_ONCE(const char*, handle->data) != stopped) uv_sleep(0); uv_close((uv_handle_t*) handle, NULL); @@ -48,11 +53,11 @@ static void async_cb(uv_async_t* handle, int status) { static void pummel(void* arg) { uv_async_t* handle = (uv_async_t*) arg; - while (*(volatile intptr_t*) &handle->data == 0) + while (ACCESS_ONCE(const char*, handle->data) == running) uv_async_send(handle); /* Acknowledge that we've seen handle->data change. */ - handle->data = (void*) (intptr_t) 2; + ACCESS_ONCE(const char*, handle->data) = stopped; } @@ -66,7 +71,7 @@ static int test_async_pummel(int nthreads) { ASSERT(tids != NULL); ASSERT(0 == uv_async_init(uv_default_loop(), &handle, async_cb)); - handle.data = NULL; + ACCESS_ONCE(const char*, handle.data) = running; for (i = 0; i < nthreads; i++) ASSERT(0 == uv_thread_create(tids + i, pummel, &handle));