diff --git a/include/boost/interprocess/detail/os_thread_functions.hpp b/include/boost/interprocess/detail/os_thread_functions.hpp index 624321f..498dde9 100644 --- a/include/boost/interprocess/detail/os_thread_functions.hpp +++ b/include/boost/interprocess/detail/os_thread_functions.hpp @@ -188,7 +188,7 @@ inline void thread_sleep_tick() inline void thread_yield() { winapi::sched_yield(); } -inline void thread_sleep(unsigned int ms) +inline void thread_sleep_ms(unsigned int ms) { winapi::sleep(ms); } //systemwide thread @@ -425,7 +425,7 @@ inline void thread_sleep_tick() ::nanosleep(&rqt, 0); } -inline void thread_sleep(unsigned int ms) +inline void thread_sleep_ms(unsigned int ms) { struct timespec rqt; rqt.tv_sec = ms/1000u; diff --git a/test/condition_test_template.hpp b/test/condition_test_template.hpp index 659a974..0e45003 100644 --- a/test/condition_test_template.hpp +++ b/test/condition_test_template.hpp @@ -97,7 +97,7 @@ void do_test_condition_notify_one() boost::interprocess::ipcdetail::OS_thread_t thread; boost::interprocess::ipcdetail::thread_launch(thread, bind_function(&condition_test_thread, &data)); //Make sure thread is blocked - boost::interprocess::ipcdetail::thread_sleep(1000); + boost::interprocess::ipcdetail::thread_sleep_ms(1*BaseMs); { boost::interprocess::scoped_lock lock(data.mutex); @@ -123,7 +123,7 @@ void do_test_condition_notify_all() } //Make sure all threads are blocked - boost::interprocess::ipcdetail::thread_sleep(1000); + boost::interprocess::ipcdetail::thread_sleep_ms(1*BaseMs); { boost::interprocess::scoped_lock lock(data.mutex); @@ -143,7 +143,7 @@ void do_test_condition_waits_step( condition_test_data &data , boost::interprocess::scoped_lock &lock , int awoken) { - boost::interprocess::ipcdetail::thread_sleep(1000); + boost::interprocess::ipcdetail::thread_sleep_ms(1*BaseMs); data.notified++; data.condition.notify_one(); while (data.awoken != awoken) @@ -176,7 +176,7 @@ void condition_test_waits(condition_test_data* data) // Test timed_wait while (data->notified != 3) - data->condition.timed_wait(lock, ptime_delay(5)); + data->condition.timed_wait(lock, ptime_delay_ms(5*BaseMs)); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 3); data->awoken++; @@ -184,7 +184,7 @@ void condition_test_waits(condition_test_data* data) // Test predicate timed_wait. { - bool ret = data->condition.timed_wait(lock, boost_systemclock_delay(5), cond_predicate (data->notified, 4)); + bool ret = data->condition.timed_wait(lock, boost_systemclock_delay_ms(5*BaseMs), cond_predicate (data->notified, 4)); BOOST_INTERPROCESS_CHECK(ret);(void)ret; BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 4); @@ -194,7 +194,7 @@ void condition_test_waits(condition_test_data* data) // Test timed_wait while (data->notified != 5) - data->condition.timed_wait(lock, std_systemclock_delay(5)); + data->condition.timed_wait(lock, std_systemclock_delay_ms(5*BaseMs)); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 5); data->awoken++; @@ -202,7 +202,7 @@ void condition_test_waits(condition_test_data* data) // Test wait_until while (data->notified != 6) - data->condition.wait_until(lock, ptime_delay(5)); + data->condition.wait_until(lock, ptime_delay_ms(5*BaseMs)); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 6); data->awoken++; @@ -210,7 +210,7 @@ void condition_test_waits(condition_test_data* data) // Test predicate wait_until. { - bool ret = data->condition.wait_until(lock, boost_systemclock_delay(5), cond_predicate (data->notified, 7)); + bool ret = data->condition.wait_until(lock, boost_systemclock_delay_ms(5*BaseMs), cond_predicate (data->notified, 7)); BOOST_INTERPROCESS_CHECK(ret);(void)ret; BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 7); @@ -220,7 +220,7 @@ void condition_test_waits(condition_test_data* data) // Test wait_for while (data->notified != 8) - data->condition.wait_for(lock, ptime_seconds(5)); + data->condition.wait_for(lock, ptime_ms(5*BaseMs)); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 8); data->awoken++; @@ -228,7 +228,7 @@ void condition_test_waits(condition_test_data* data) // Test predicate wait_for. { - bool ret = data->condition.wait_for(lock, ptime_seconds(5), cond_predicate (data->notified, 9)); + bool ret = data->condition.wait_for(lock, ptime_ms(5*BaseMs), cond_predicate (data->notified, 9)); BOOST_INTERPROCESS_CHECK(ret);(void)ret; BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 9); @@ -238,7 +238,7 @@ void condition_test_waits(condition_test_data* data) // Test wait_for while (data->notified != 10) - data->condition.wait_for(lock, boost_systemclock_seconds(5)); + data->condition.wait_for(lock, boost_systemclock_ms(5*BaseMs)); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 10); data->awoken++; @@ -246,7 +246,7 @@ void condition_test_waits(condition_test_data* data) // Test predicate wait_for. { - bool ret = data->condition.wait_for(lock, boost_systemclock_seconds(5), cond_predicate (data->notified, 11)); + bool ret = data->condition.wait_for(lock, boost_systemclock_ms(5*BaseMs), cond_predicate (data->notified, 11)); BOOST_INTERPROCESS_CHECK(ret);(void)ret; BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 11); @@ -256,7 +256,7 @@ void condition_test_waits(condition_test_data* data) // Test wait_for while (data->notified != 12) - data->condition.wait_for(lock, std_systemclock_seconds(5)); + data->condition.wait_for(lock, std_systemclock_ms(5*BaseMs)); BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 12); data->awoken++; @@ -264,7 +264,7 @@ void condition_test_waits(condition_test_data* data) // Test predicate wait_for. { - bool ret = data->condition.wait_for(lock, std_systemclock_seconds(5), cond_predicate (data->notified, 13)); + bool ret = data->condition.wait_for(lock, std_systemclock_ms(5*BaseMs), cond_predicate (data->notified, 13)); BOOST_INTERPROCESS_CHECK(ret);(void)ret; BOOST_INTERPROCESS_CHECK(lock ? true : false); BOOST_INTERPROCESS_CHECK(data->notified == 13); diff --git a/test/file_lock_test.cpp b/test/file_lock_test.cpp index cc0c373..b7d2de8 100644 --- a/test/file_lock_test.cpp +++ b/test/file_lock_test.cpp @@ -48,13 +48,13 @@ int main () scoped_lock sl(flock, try_to_lock); } { - scoped_lock sl(flock, test::ptime_delay(1)); + scoped_lock sl(flock, test::ptime_delay_ms(1)); } { - scoped_lock sl(flock, test::boost_systemclock_delay(1)); + scoped_lock sl(flock, test::boost_systemclock_delay_ms(1)); } { - scoped_lock sl(flock, test::std_systemclock_delay(1)); + scoped_lock sl(flock, test::std_systemclock_delay_ms(1)); } } #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) diff --git a/test/mutex_owner_dead_test.cpp b/test/mutex_owner_dead_test.cpp index e7e6507..e831c6f 100644 --- a/test/mutex_owner_dead_test.cpp +++ b/test/mutex_owner_dead_test.cpp @@ -59,7 +59,7 @@ void test_owner_dead_mutex_do_lock(M &mtx, EOwnerDeadLockType lock_type) break; case OwnerDeadTimedLock: - mtx.timed_lock(boost_systemclock_delay(10)); + mtx.timed_lock(boost_systemclock_delay_ms(10)); break; } } diff --git a/test/mutex_test_template.hpp b/test/mutex_test_template.hpp index 18b2044..f0a6fbb 100644 --- a/test/mutex_test_template.hpp +++ b/test/mutex_test_template.hpp @@ -106,7 +106,7 @@ struct test_timedlock // Test the lock's constructors. { // Construct and initialize an ptime for a fast time out. - timed_lock_type lock(interprocess_mutex, ptime_delay(1*BaseSeconds)); + timed_lock_type lock(interprocess_mutex, ptime_delay_ms(unsigned(1*BaseMs))); BOOST_INTERPROCESS_CHECK(lock ? true : false); } { @@ -123,7 +123,7 @@ struct test_timedlock BOOST_INTERPROCESS_CHECK(lock ? true : false); lock.unlock(); BOOST_INTERPROCESS_CHECK(!lock); - BOOST_INTERPROCESS_CHECK(lock.timed_lock(boost_systemclock_delay(3*BaseSeconds))); + BOOST_INTERPROCESS_CHECK(lock.timed_lock(boost_systemclock_delay_ms(1*BaseMs))); BOOST_INTERPROCESS_CHECK(lock ? true : false); } }; @@ -158,15 +158,15 @@ struct test_recursive_lock } { //This should always lock - lock_twice_timed(mx, ptime_delay(2*BaseSeconds)); + lock_twice_timed(mx, ptime_delay_ms(2*BaseMs)); } { //This should always lock - lock_twice_timed(mx, boost_systemclock_delay(2*BaseSeconds)); + lock_twice_timed(mx, boost_systemclock_delay_ms(2*BaseMs)); } { //This should always lock - lock_twice_timed(mx, std_systemclock_delay(2*BaseSeconds)); + lock_twice_timed(mx, std_systemclock_delay_ms(2*BaseMs)); } } }; @@ -179,11 +179,11 @@ void lock_and_sleep(void *arg, M &sm) { data *pdata = static_cast*>(arg); boost::interprocess::scoped_lock l(sm); - if(pdata->m_secs){ - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*pdata->m_secs)); + if(pdata->m_msecs){ + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(pdata->m_msecs)); } else{ - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*2*BaseSeconds)); + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(2*BaseMs)); } ++shared_val; @@ -193,21 +193,13 @@ void lock_and_sleep(void *arg, M &sm) template void lock_and_catch_errors(void *arg, M &sm) { - data *pdata = static_cast*>(arg); BOOST_TRY { - boost::interprocess::scoped_lock l(sm); - if(pdata->m_secs){ - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*pdata->m_secs)); - } - else{ - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*2*BaseSeconds)); - } - ++shared_val; - pdata->m_value = shared_val; + lock_and_sleep(arg, sm); } BOOST_CATCH(interprocess_exception const & e) { + data* pdata = static_cast*>(arg); pdata->m_error = e.get_error_code(); } BOOST_CATCH_END } @@ -218,7 +210,7 @@ void try_lock_and_sleep(void *arg, M &sm) data *pdata = static_cast*>(arg); boost::interprocess::scoped_lock l(sm, boost::interprocess::defer_lock); if (l.try_lock()){ - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*2*BaseSeconds)); + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(2*BaseMs)); ++shared_val; pdata->m_value = shared_val; } @@ -240,17 +232,17 @@ void timed_lock_and_sleep(void *arg, M &sm) l (sm, boost::interprocess::defer_lock); bool r = false; if(pdata->m_flags == (int)TimedLock){ - r = l.timed_lock(std_systemclock_delay(pdata->m_secs)); + r = l.timed_lock(std_systemclock_delay_ms(unsigned(pdata->m_msecs))); } else if (pdata->m_flags == (int)TryLockUntil) { - r = l.try_lock_until(ptime_delay(pdata->m_secs)); + r = l.try_lock_until(ptime_delay_ms(unsigned(pdata->m_msecs))); } else if (pdata->m_flags == (int)TryLockFor) { - r = l.try_lock_for(boost_systemclock_seconds(pdata->m_secs)); + r = l.try_lock_for(boost_systemclock_ms(unsigned(pdata->m_msecs))); } if (r){ - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*2*BaseSeconds)); + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(2*BaseMs)); ++shared_val; pdata->m_value = shared_val; } @@ -266,21 +258,21 @@ void test_mutex_lock() data d1(1); data d2(2); - // Locker one launches, holds the lock for 2*BaseSeconds seconds. + // Locker one launches, holds the lock for 2*BaseMs seconds. boost::interprocess::ipcdetail::OS_thread_t tm1; boost::interprocess::ipcdetail::thread_launch(tm1, thread_adapter(&lock_and_sleep, &d1, mtx)); - //Wait 1*BaseSeconds - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*1*BaseSeconds)); + //Wait 1*BaseMs + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); - // Locker two launches, but it won't hold the lock for 2*BaseSeconds seconds. + // Locker two launches, but it won't hold the lock for 2*BaseMs seconds. boost::interprocess::ipcdetail::OS_thread_t tm2; boost::interprocess::ipcdetail::thread_launch(tm2, thread_adapter(&lock_and_sleep, &d2, mtx)); //Wait completion boost::interprocess::ipcdetail::thread_join(tm1); - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*1*BaseSeconds)); + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); boost::interprocess::ipcdetail::thread_join(tm2); BOOST_INTERPROCESS_CHECK(d1.m_value == 1); @@ -294,28 +286,25 @@ void test_mutex_lock_timeout() M mtx; - int wait_time_s = BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS / 1000; - if (wait_time_s == 0 ) - wait_time_s = 1; + unsigned wait_time_ms = BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS; - data d1(1, wait_time_s * 3); - data d2(2, wait_time_s * 2); + data d1(1, (int)wait_time_ms * 3); + data d2(2, (int)wait_time_ms * 1); - // Locker one launches, and holds the lock for wait_time_s * 2 seconds. + // Locker one launches, and holds the lock for wait_time_ms * 3. boost::interprocess::ipcdetail::OS_thread_t tm1; boost::interprocess::ipcdetail::thread_launch(tm1, thread_adapter(&lock_and_sleep, &d1, mtx)); - //Wait 1*BaseSeconds - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*wait_time_s)); + //Wait until tm1 acquires the lock + boost::interprocess::ipcdetail::thread_sleep_ms(wait_time_ms); - // Locker two launches, and attempts to hold the lock for wait_time_s * 2 seconds. + // Locker two launches, and attempts to hold the lock for wait_time_ms * 2. boost::interprocess::ipcdetail::OS_thread_t tm2; boost::interprocess::ipcdetail::thread_launch(tm2, thread_adapter(&lock_and_catch_errors, &d2, mtx)); //Wait completion - boost::interprocess::ipcdetail::thread_join(tm1); - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*1*BaseSeconds)); boost::interprocess::ipcdetail::thread_join(tm2); + boost::interprocess::ipcdetail::thread_join(tm1); BOOST_INTERPROCESS_CHECK(d1.m_value == 1); BOOST_INTERPROCESS_CHECK(d2.m_value == -1); @@ -333,12 +322,12 @@ void test_mutex_try_lock() data d1(1); data d2(2); - // Locker one launches, holds the lock for 2*BaseSeconds seconds. + // Locker one launches, holds the lock for 2*BaseMs seconds. boost::interprocess::ipcdetail::OS_thread_t tm1; boost::interprocess::ipcdetail::thread_launch(tm1, thread_adapter(&try_lock_and_sleep, &d1, mtx)); - //Wait 1*BaseSeconds - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*1*BaseSeconds)); + //Wait 1*BaseMs + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); // Locker two launches, but it should fail acquiring the lock boost::interprocess::ipcdetail::OS_thread_t tm2; @@ -362,17 +351,17 @@ void test_mutex_timed_lock() M mtx, m2; - data d1(1, 2*BaseSeconds, flag); - data d2(2, 2*BaseSeconds, flag); + data d1(1, 2*BaseMs, flag); + data d2(2, 2*BaseMs, flag); - // Locker one launches, holds the lock for 2*BaseSeconds seconds. + // Locker one launches, holds the lock for 2*BaseMs seconds. boost::interprocess::ipcdetail::OS_thread_t tm1; boost::interprocess::ipcdetail::thread_launch(tm1, thread_adapter(&timed_lock_and_sleep, &d1, mtx)); - //Wait 1*BaseSeconds - boost::interprocess::ipcdetail::thread_sleep(unsigned(1000*1*BaseSeconds)); + //Wait 1*BaseMs + boost::interprocess::ipcdetail::thread_sleep_ms(unsigned(1*BaseMs)); - // Locker two launches, holds the lock for 2*BaseSeconds seconds. + // Locker two launches, holds the lock for 2*BaseMs seconds. boost::interprocess::ipcdetail::OS_thread_t tm2; boost::interprocess::ipcdetail::thread_launch(tm2, thread_adapter(&timed_lock_and_sleep, &d2, mtx)); diff --git a/test/mutex_timeout_test.cpp b/test/mutex_timeout_test.cpp index 4999cee..8f7427c 100644 --- a/test/mutex_timeout_test.cpp +++ b/test/mutex_timeout_test.cpp @@ -9,9 +9,10 @@ ////////////////////////////////////////////////////////////////////////////// // enable timeout feature +#define BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS boost::interprocess::test::BaseMs #define BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING -#define BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS 6000 +#include "util.hpp" #include #include #include diff --git a/test/upgradable_mutex_test.cpp b/test/upgradable_mutex_test.cpp index 9678b22..2bd2e1b 100644 --- a/test/upgradable_mutex_test.cpp +++ b/test/upgradable_mutex_test.cpp @@ -68,13 +68,13 @@ int main () { upgradable_lock u_lock(mut); //This calls timed_unlock_upgradable_and_lock() - scoped_lock e_lock(boost::move(u_lock), test::boost_systemclock_delay(10)); + scoped_lock e_lock(boost::move(u_lock), test::boost_systemclock_delay_ms(10)); } { upgradable_lock u_lock(mut); //This calls timed_unlock_upgradable_and_lock() scoped_lock e_lock(mut2); - scoped_lock moved(boost::move(u_lock), test::ptime_delay(10)); + scoped_lock moved(boost::move(u_lock), test::ptime_delay_ms(10)); e_lock = boost::move(moved); } {