Skip to content

Commit

Permalink
Switch back to regular (non-atomic) counter variables
Browse files Browse the repository at this point in the history
Signed-off-by: Quincey Koziol <[email protected]>
  • Loading branch information
qkoziol committed Aug 31, 2024
1 parent f2d7d2b commit d15e428
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions test/ttsafe_semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

typedef struct {
H5TS_semaphore_t ping_sem, pong_sem;
H5TS_atomic_uint_t ping_counter;
H5TS_atomic_uint_t pong_counter;
unsigned ping_counter;
unsigned pong_counter;
} pingpong_t;

typedef struct {
Expand All @@ -48,11 +48,11 @@ ping(void *_test_info)
result = H5TS_semaphore_wait(&test_info->ping_sem);
CHECK_I(result, "H5TS_semaphore_wait");

H5TS_atomic_fetch_add_uint(&test_info->ping_counter, (unsigned)1);
test_info->ping_counter++;

result = H5TS_semaphore_signal(&test_info->pong_sem);
CHECK_I(result, "H5TS_semaphore_signal");
} while (H5TS_atomic_load_uint(&test_info->ping_counter) < NUM_PINGPONG);
} while (test_info->ping_counter < NUM_PINGPONG);

return ret_value;
}
Expand All @@ -68,11 +68,11 @@ pong(void *_test_info)
result = H5TS_semaphore_wait(&test_info->pong_sem);
CHECK_I(result, "H5TS_semaphore_wait");

H5TS_atomic_fetch_add_uint(&test_info->pong_counter, (unsigned)1);
test_info->pong_counter++;

result = H5TS_semaphore_signal(&test_info->ping_sem);
CHECK_I(result, "H5TS_semaphore_signal");
} while (H5TS_atomic_load_uint(&test_info->pong_counter) < NUM_PINGPONG);
} while (test_info->pong_counter < NUM_PINGPONG);

return ret_value;
}
Expand All @@ -94,8 +94,8 @@ tts_semaphore_pingpong(void)
CHECK_I(result, "H5TS_semaphore_init");
result = H5TS_semaphore_init(&test_info.pong_sem, 0);
CHECK_I(result, "H5TS_semaphore_init");
H5TS_atomic_init_uint(&test_info.ping_counter, (unsigned)0);
H5TS_atomic_init_uint(&test_info.pong_counter, (unsigned)0);
test_info.ping_counter = 0;
test_info.pong_counter = 0;

/* Start ping & pong threads */
result = H5TS_thread_create(&ping_thread, ping, &test_info);
Expand All @@ -113,17 +113,14 @@ tts_semaphore_pingpong(void)
result = H5TS_thread_join(pong_thread, NULL);
CHECK_I(result, "H5TS_thread_join");

VERIFY(H5TS_atomic_load_uint(&test_info.ping_counter), NUM_PINGPONG, "ping counter");
VERIFY(H5TS_atomic_load_uint(&test_info.pong_counter), NUM_PINGPONG, "pong counter");
VERIFY(test_info.ping_counter, NUM_PINGPONG, "ping counter");
VERIFY(test_info.pong_counter, NUM_PINGPONG, "pong counter");

/* Destroy semaphores, etc. */
/* Destroy semaphores */
result = H5TS_semaphore_destroy(&test_info.ping_sem);
CHECK_I(result, "H5TS_semaphore_destroy");
result = H5TS_semaphore_destroy(&test_info.pong_sem);
CHECK_I(result, "H5TS_semaphore_destroy");

H5TS_atomic_destroy_uint(&test_info.ping_counter);
H5TS_atomic_destroy_uint(&test_info.pong_counter);
} /* end tts_semaphore_pingpong() */

static H5TS_THREAD_RETURN_TYPE
Expand Down

0 comments on commit d15e428

Please sign in to comment.