MLIB
Loading...
Searching...
No Matches
critsect.h
Go to the documentation of this file.
1#pragma once
9#if __has_include("defs.h")
10#include "defs.h"
11#endif
12#include "safe_winsock.h"
13
14namespace mlib {
15
25{
26public:
29 virtual void enter ();
30 virtual bool try_enter ();
31 virtual void leave ();
32
33private:
34 CRITICAL_SECTION section;
35
36 // critical sections cannot be copied or assigned
37 criticalsection (const criticalsection&) = delete;
38 criticalsection& operator= (const criticalsection&) = delete;
39};
40
68class lock
69{
70public:
73
75 lock (const lock& t);
76
78 ~lock ();
79
80private:
81 criticalsection& section;
82};
83
86{
87 InitializeCriticalSection (&section);
88}
89
92{
93 DeleteCriticalSection (&section);
94}
95
98{
99 EnterCriticalSection (&section);
100}
101
104{
105 return (TryEnterCriticalSection (&section) != 0);
106}
107
110{
111 LeaveCriticalSection (&section);
112}
113
115 : section (cs)
116{
117 section.enter ();
118}
119
120inline lock::lock (const lock& t)
121 : section (t.section)
122{
123 section.enter ();
124}
125
126inline lock::~lock ()
127{
128 section.leave ();
129}
130
131} // namespace mlib
Lightweight inter-thread synchronization.
Definition critsect.h:25
virtual bool try_enter()
Return true if critical section was entered.
Definition critsect.h:103
~criticalsection()
Deletes the critical section object.
Definition critsect.h:91
criticalsection()
Initializes critical section object.
Definition critsect.h:85
virtual void enter()
Enter critical section.
Definition critsect.h:97
virtual void leave()
Leave critical section.
Definition critsect.h:109
Automatic wrapper for critical sections.
Definition critsect.h:69
lock(criticalsection &cs)
Acquire critical section.
Definition critsect.h:114
~lock()
Leave critical section.
Definition critsect.h:126