33#include <boost/chrono/duration.hpp>
34#include <boost/thread/condition_variable.hpp>
35#include <boost/thread/locks.hpp>
36#include <boost/thread/mutex.hpp>
37#include <boost/thread/recursive_mutex.hpp>
38#include <boost/thread/thread.hpp>
47 static unsigned int value = 0;
60 boost::unique_lock<boost::mutex> lock(m_mx);
62 m_cond_var.notify_one();
67 boost::unique_lock<boost::mutex> lock(m_mx);
69 m_cond_var.wait(lock);
75 boost::condition_variable m_cond_var;
79 class critical_region;
83 boost::recursive_mutex m_section;
112 return m_section.try_lock();
123 template<
class t_lock>
124 class critical_region_t
129 critical_region_t(
const critical_region_t&) {}
153#if defined(WINDWOS_PLATFORM)
154 class shared_critical_section
159 ::InitializeSRWLock(&m_srw_lock);
166 AcquireSRWLockShared(&m_srw_lock);
171 ReleaseSRWLockShared(&m_srw_lock);
176 ::AcquireSRWLockExclusive(&m_srw_lock);
181 ::ReleaseSRWLockExclusive(&m_srw_lock);
192 shared_guard(shared_critical_section& ref_sec):m_ref_sec(ref_sec)
194 m_ref_sec.lock_shared();
199 m_ref_sec.unlock_shared();
203 shared_critical_section& m_ref_sec;
212 m_ref_sec.lock_exclusive();
217 m_ref_sec.unlock_exclusive();
221 shared_critical_section& m_ref_sec;
225#define SHARED_CRITICAL_REGION_BEGIN(x) { shared_guard critical_region_var(x)
226#define EXCLUSIVE_CRITICAL_REGION_BEGIN(x) { exclusive_guard critical_region_var(x)
228#define CRITICAL_REGION_LOCAL(x) {boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} epee::critical_region_t<decltype(x)> critical_region_var(x)
229#define CRITICAL_REGION_BEGIN(x) { boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t<decltype(x)> critical_region_var(x)
230#define CRITICAL_REGION_LOCAL1(x) {boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} epee::critical_region_t<decltype(x)> critical_region_var1(x)
231#define CRITICAL_REGION_BEGIN1(x) { boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t<decltype(x)> critical_region_var1(x)
233#define CRITICAL_REGION_END() }
236#if defined(WINDWOS_PLATFORM)
241 case WAIT_ABANDONED:
return "WAIT_ABANDONED";
242 case WAIT_TIMEOUT:
return "WAIT_TIMEOUT";
243 case WAIT_OBJECT_0:
return "WAIT_OBJECT_0";
244 case WAIT_OBJECT_0+1:
return "WAIT_OBJECT_1";
245 case WAIT_OBJECT_0+2:
return "WAIT_OBJECT_2";
246 default:
return "UNKNOWN CODE";
critical_region_t(t_lock &cs)
critical_section & operator=(const critical_section §ion)
critical_section(const critical_section §ion)
exclusive_guard(shared_critical_section &ref_sec)
shared_critical_section()
~shared_critical_section()
shared_guard(shared_critical_section &ref_sec)
unsigned int & g_test_dbg_lock_sleep()
const char * get_wait_for_result_as_text(DWORD res)
const GenericPointer< typename T::ValueType > T2 value