File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ class Foundation_API Mutex: private MutexImpl
52
52
{
53
53
public:
54
54
using ScopedLock = Poco::ScopedLock<Mutex>;
55
+ using ScopedLockWithUnlock = Poco::ScopedLockWithUnlock<Mutex>;
55
56
56
57
Mutex ();
57
58
// / creates the Mutex.
@@ -107,6 +108,7 @@ class Foundation_API FastMutex: private FastMutexImpl
107
108
{
108
109
public:
109
110
using ScopedLock = Poco::ScopedLock<FastMutex>;
111
+ using ScopedLockWithUnlock = Poco::ScopedLockWithUnlock<FastMutex>;
110
112
111
113
FastMutex ();
112
114
// / creates the Mutex.
@@ -165,6 +167,7 @@ class Foundation_API SpinlockMutex
165
167
{
166
168
public:
167
169
using ScopedLock = Poco::ScopedLock<SpinlockMutex>;
170
+ using ScopedLockWithUnlock = Poco::ScopedLockWithUnlock<SpinlockMutex>;
168
171
169
172
SpinlockMutex ();
170
173
// / Creates the SpinlockMutex.
@@ -209,6 +212,7 @@ class Foundation_API NullMutex
209
212
{
210
213
public:
211
214
using ScopedLock = Poco::ScopedLock<NullMutex>;
215
+ using ScopedLockWithUnlock = Poco::ScopedLockWithUnlock<NullMutex>;
212
216
213
217
NullMutex ()
214
218
// / Creates the NullMutex.
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ class Foundation_API NamedMutex: private NamedMutexImpl
54
54
{
55
55
public:
56
56
using ScopedLock = Poco::ScopedLock<NamedMutex>;
57
+ using ScopedLockWithUnlock = Poco::ScopedLockWithUnlock<NamedMutex>;
57
58
58
59
NamedMutex (const std::string& name);
59
60
// / creates the Mutex.
Original file line number Diff line number Diff line change @@ -77,12 +77,18 @@ class ScopedLockWithUnlock
77
77
public:
78
78
explicit ScopedLockWithUnlock (M& mutex): _pMutex(&mutex)
79
79
{
80
+ poco_assert (_pMutex != nullptr );
81
+
80
82
_pMutex->lock ();
83
+ _locked = true ;
81
84
}
82
85
83
86
ScopedLockWithUnlock (M& mutex, long milliseconds): _pMutex(&mutex)
84
87
{
88
+ poco_assert (_pMutex != nullptr );
89
+
85
90
_pMutex->lock (milliseconds);
91
+ _locked = true ;
86
92
}
87
93
88
94
~ScopedLockWithUnlock ()
@@ -97,17 +103,29 @@ class ScopedLockWithUnlock
97
103
}
98
104
}
99
105
106
+ void lock ()
107
+ {
108
+ poco_assert (_pMutex != nullptr );
109
+ poco_assert (_locked == false );
110
+
111
+ _pMutex->lock ();
112
+ _locked = true ;
113
+ }
114
+
100
115
void unlock ()
101
116
{
102
- if (_pMutex )
117
+ if (_locked )
103
118
{
119
+ poco_assert (_pMutex != nullptr );
120
+
104
121
_pMutex->unlock ();
105
- _pMutex = 0 ;
122
+ _locked = false ;
106
123
}
107
124
}
108
125
109
126
private:
110
127
M* _pMutex;
128
+ bool _locked = false ;
111
129
112
130
ScopedLockWithUnlock ();
113
131
ScopedLockWithUnlock (const ScopedLockWithUnlock&);
You can’t perform that action at this time.
0 commit comments