1 /* ///////////////////////////////////////////////////////////////////////
7 * Brief: mutex_lock class
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_WIN_SYNCH_MUTEX_LOCK_H
13 #define EXTL_WIN_SYNCH_MUTEX_LOCK_H
16 * \brief mutex_lock class
19 # error mutex_lock.h need be supported by c++.
22 /* ///////////////////////////////////////////////////////////////////////
26 #include "../../synch/lock_base.h"
29 /* ///////////////////////////////////////////////////////////////////////
30 * ::extl::platform::win namespace
32 EXTL_WIN_BEGIN_WHOLE_NAMESPACE
34 /*!\brief mutex_lock class
35 * \ingroup extl_group_synch
38 : public lock_base
< mutex_lock
>
41 typedef lock_base
< mutex_lock
> base_type
;
42 typedef mutex_lock class_type
;
43 typedef base_type::size_type size_type
;
50 : base_type(), m_mutex_obj(e_false_v
)
53 EXTL_ASSERT(is_valid());
58 if(base_type::is_locked())
67 EXTL_ASSERT(is_valid());
69 /* Waits the mutex object */
70 ::WaitForSingleObject(m_mutex_obj
, INFINITE
);
75 EXTL_ASSERT(is_valid());
76 /* Try waiting the mutex object for 100 milliseconds */
77 return (WAIT_TIMEOUT
!= ::WaitForSingleObject(m_mutex_obj
, 100));
81 EXTL_ASSERT(is_valid());
82 /* Release the mutex object */
83 m_mutex_obj
.release();
88 return ((m_mutex_obj
!= NULL
) && (m_mutex_obj
!= INVALID_HANDLE_VALUE
));
92 /* ///////////////////////////////////////////////////////////////////////
95 #ifdef EXTL_SYNCH_LOCK_TEST_ENABLE
96 # include "unit_test/mutex_lock_test.h"
98 /* ///////////////////////////////////////////////////////////////////////
99 * ::extl::platform::win namespace
101 EXTL_WIN_END_WHOLE_NAMESPACE
103 /* //////////////////////////////////////////////////////////////////// */
104 #endif /* EXTL_WIN_SYNCH_MUTEX_LOCK_H */
105 /* //////////////////////////////////////////////////////////////////// */