remove \r
[extl.git] / extl / win / synch / event_lock.h
blob54e2feccae06ca5f0245e8cfd9170c81b9771732
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: event_lock.h
4 * Created: 08.03.21
5 * Updated: 08.05.05
7 * Brief: event_lock class
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_WIN_SYNCH_EVENT_LOCK_H
13 #define EXTL_WIN_SYNCH_EVENT_LOCK_H
15 /*!\file event_lock.h
16 * \brief event_lock class
18 #ifndef __cplusplus
19 # error event_lock.h need be supported by c++.
20 #endif
22 /* ///////////////////////////////////////////////////////////////////////
23 * Includes
25 #include "../win.h"
26 #include "../../synch/lock_base.h"
27 #include "event.h"
29 /* ///////////////////////////////////////////////////////////////////////
30 * ::extl::platform::win namespace
32 EXTL_WIN_BEGIN_WHOLE_NAMESPACE
34 /*!\brief event_lock class
35 * \ingroup extl_group_synch
37 class event_lock
38 : public lock_base< event_lock >
40 public:
41 typedef lock_base< event_lock > base_type;
42 typedef event_lock class_type;
43 typedef base_type::size_type size_type;
45 private:
46 event m_event_obj;
48 public:
49 event_lock()
50 : m_event_obj(e_false_v, e_true_v), /* reset event automaticly */
51 base_type()
53 EXTL_ASSERT(is_valid());
56 ~event_lock()
58 if(base_type::is_locked())
60 base_type::unlock();
64 public:
65 void do_lock()
67 EXTL_ASSERT(is_valid());
69 /* Waits the event object */
70 ::WaitForSingleObject(m_event_obj, INFINITE);
73 e_bool_t do_trylock()
75 EXTL_ASSERT(is_valid());
77 /* Try waiting the event object for 100 milliseconds */
78 return (WAIT_TIMEOUT != ::WaitForSingleObject(m_event_obj, 100));
80 void do_unlock()
82 EXTL_ASSERT(is_valid());
83 /* Sets the event object */
84 m_event_obj.set_event();
86 private:
87 e_bool_t is_valid()
89 return ((m_event_obj != NULL) && (m_event_obj != INVALID_HANDLE_VALUE));
93 /* ///////////////////////////////////////////////////////////////////////
94 * Unit-testing
96 #ifdef EXTL_SYNCH_LOCK_TEST_ENABLE
97 # include "unit_test/event_lock_test.h"
98 #endif
99 /* ///////////////////////////////////////////////////////////////////////
100 * ::extl::platform::win namespace
102 EXTL_WIN_END_WHOLE_NAMESPACE
104 /* //////////////////////////////////////////////////////////////////// */
105 #endif /* EXTL_WIN_SYNCH_EVENT_LOCK_H */
106 /* //////////////////////////////////////////////////////////////////// */