MCPcopy Create free account
hub / github.com/ReadyTalk/avian / Monitor

Class Monitor

src/system/windows.cpp:220–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218 };
219
220 class Monitor : public System::Monitor {
221 public:
222 Monitor(System* s) : s(s), owner_(0), first(0), last(0), depth(0)
223 {
224 mutex = CreateMutex(0, false, 0);
225 assertT(s, mutex);
226 }
227
228 virtual bool tryAcquire(System::Thread* context)
229 {
230 Thread* t = static_cast<Thread*>(context);
231 assertT(s, t);
232
233 if (owner_ == t) {
234 ++depth;
235 return true;
236 } else {
237 switch (WaitForSingleObject(mutex, 0)) {
238 case WAIT_TIMEOUT:
239 return false;
240
241 case WAIT_OBJECT_0:
242 owner_ = t;
243 ++depth;
244 return true;
245
246 default:
247 sysAbort(s);
248 }
249 }
250 }
251
252 virtual void acquire(System::Thread* context)
253 {
254 Thread* t = static_cast<Thread*>(context);
255 assertT(s, t);
256
257 if (owner_ != t) {
258 int r UNUSED = WaitForSingleObject(mutex, INFINITE);
259 assertT(s, r == WAIT_OBJECT_0);
260 owner_ = t;
261 }
262 ++depth;
263 }
264
265 virtual void release(System::Thread* context)
266 {
267 Thread* t = static_cast<Thread*>(context);
268 assertT(s, t);
269
270 if (owner_ == t) {
271 if (--depth == 0) {
272 owner_ = 0;
273 bool success UNUSED = ReleaseMutex(mutex);
274 assertT(s, success);
275 }
276 } else {
277 sysAbort(s);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected