static void sem_timedwait_helper(clockid_t clock, int (*wait_function)(sem_t* __sem, const timespec* __ts)) { sem_t s; ASSERT_EQ(0, sem_init(&s, 0, 0)); timespec ts; ASSERT_EQ(0, clock_gettime(clock, &ts)); timespec_add_ms(ts, 100); errno = 0; ASSERT_EQ(-1, wait_function(&s, &ts)); ASSERT_EQ(ETIMEDOUT, errno); // A negative timeout is an error. errno = 0; ts.tv_nsec = -1; ASSERT_EQ(-1, wait_function(&s, &ts)); ASSERT_EQ(EINVAL, errno); errno = 0; ts.tv_nsec = NS_PER_S; ASSERT_EQ(-1, wait_function(&s, &ts)); ASSERT_EQ(EINVAL, errno); errno = 0; ts.tv_nsec = NS_PER_S - 1; ts.tv_sec = -1; ASSERT_EQ(-1, wait_function(&s, &ts)); ASSERT_EQ(ETIMEDOUT, errno); ASSERT_EQ(0, sem_destroy(&s)); }
void thread_pool::thread_pool_common_data_t::add_waiting_threads_no_lock(std::shared_ptr<thread_pool::thread_pool_common_data_t> const & data, size_t number) { for (size_t i = 0; i < number; ++ i) { std::shared_ptr<thread_pool_thread_info> th_info = MakeSharedPtr<thread_pool_thread_info>(data); joiner<void> j = data->threader_(wait_function(th_info)); th_info->set_thread_id(j.get_thread_id()); data->threads_.push_back(th_info); j.detach(); } }