22 #include <gtest/gtest.h> 28 #include <core/threading/wait_condition.h> 61 pthread_t threads[num_threads];
63 for (uint i = 0; i < num_threads; i++) {
65 params[i]->
cond = cond;
66 pthread_create(&threads[i], NULL, thread_func, params[i]);
71 for (uint i = 0; i < num_threads; i++) {
72 pthread_cancel(threads[i]);
74 ASSERT_NE(-1, clock_gettime(CLOCK_REALTIME, &ts));
77 ASSERT_EQ(0, pthread_timedjoin_np(threads[i], NULL, &ts));
84 const uint num_threads;
88 void * start_waiter_thread(
void * args)
95 void * start_abstimed_waiter_thread(
void * args)
99 EXPECT_NE(-1, clock_gettime(CLOCK_REALTIME, &ts));
105 void * start_reltimed_waiter_thread(
void * args)
114 start_test(start_waiter_thread);
119 start_test(start_abstimed_waiter_thread);
124 start_test(start_reltimed_waiter_thread);
Test class for WaitConditions This class tets basic functionality of WaitConditions, mainly thread cancellation problems.
Wait until a given condition holds.
bool reltimed_wait(unsigned int sec, unsigned int nanosec)
Wait with relative timeout.
Fawkes library namespace.
WaitCondition * cond
The thread's wait condition.
The parameters passed to the threads.
void start_test(void *(*thread_func)(void *))
Start threads with the given function, cancel the threads and assert they have terminated.
void wait()
Wait for the condition forever.
bool abstimed_wait(long int sec, long int nanosec)
Wait with absolute timeout.