30 #ifndef __WINH_OBJ_H__ 31 #define __WINH_OBJ_H__ 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>
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)
203 shared_critical_section& m_ref_sec;
207 class exclusive_guard
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";
exclusive_guard(shared_critical_section &ref_sec)
critical_section & operator=(const critical_section §ion)
~shared_critical_section()
unsigned int & g_test_dbg_lock_sleep()
const char * get_wait_for_result_as_text(DWORD res)
critical_region_t(t_lock &cs)
shared_guard(shared_critical_section &ref_sec)
shared_critical_section()
const GenericPointer< typename T::ValueType > T2 value
critical_section(const critical_section §ion)