remove \r
[extl.git] / extl / platform_ / windows / synch / critical_section.h
blob775c171c703e2bdb24c03760cb6d49b893fc2c21
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: critical_section.h
4 * Created: 08.03.20
5 * Updated: 08.11.26
7 * Brief: The Critical Section
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_PLATFORM_WINDOWS_SYNCH_CRITICAL_SECTION_H
13 #define EXTL_PLATFORM_WINDOWS_SYNCH_CRITICAL_SECTION_H
15 /*!\file critical_section.h
16 * \brief The Critical Section
18 #ifndef __cplusplus
19 # error critical_section.h need be supported by c++.
20 #endif
22 /* ///////////////////////////////////////////////////////////////////////
23 * Includes
25 #include "prefix.h"
26 #include "../../utility/uncopyable.h"
28 /* ///////////////////////////////////////////////////////////////////////
29 * ::extl::platform::windows namespace
31 EXTL_WINDOWS_BEGIN_WHOLE_NAMESPACE
34 /*!\brief critical_section class
36 * \ingroup extl_group_synch
38 class critical_section
39 : private uncopyable<critical_section>
41 /// \name Types
42 /// @{
43 public:
44 typedef critical_section class_type;
45 typedef LPCRITICAL_SECTION handle_type;
46 typedef CRITICAL_SECTION crsec_type;
47 typedef e_bool_t bool_type;
48 /// @}
50 /// \name Members
51 /// @{
52 private:
53 crsec_type m_cs;
54 ///@}
56 /// \name Constructors
57 /// @{
58 public:
59 critical_section()
60 : m_cs(initialize_critical_section())
63 virtual ~critical_section() EXTL_THROW_0()
65 ::DeleteCriticalSection(&m_cs);
67 /// @}
69 /// \name Methods
70 /// @{
71 public:
72 /// initialize critical section
73 static crsec_type initialize_critical_section()
75 crsec_type cs;
76 ::InitializeCriticalSection(&cs);
77 return cs;
79 /// enter critical section
80 void enter()
82 ::EnterCriticalSection(&m_cs);
85 /// try entering critical section
86 bool_type try_enter()
88 #if(_WIN_WINNT >= 0x0400)
89 return (BOOL2bool(::TryEnterCriticalSection(&m_cs)));
90 #else
91 return e_false_v;
92 #endif
95 /// leave critical section
96 void leave()
98 ::LeaveCriticalSection(&m_cs);
100 /// @}
102 /// \name Accessors
103 /// @{
104 public:
105 /// gets object handle
106 operator handle_type() const { return const_cast<handle_type>(&m_cs); }
107 /// gets object handle
108 handle_type handle() const { return const_cast<handle_type>(&m_cs); }
109 /// @}
112 /* ///////////////////////////////////////////////////////////////////////
113 * ::extl::platform::windows namespace
115 EXTL_WINDOWS_END_WHOLE_NAMESPACE
117 /* //////////////////////////////////////////////////////////////////// */
118 #endif /* EXTL_PLATFORM_WINDOWS_SYNCH_CRITICAL_SECTION_H */
119 /* //////////////////////////////////////////////////////////////////// */