Class: Winipc::Mutex
- Inherits:
-
Object
- Object
- Winipc::Mutex
- Defined in:
- lib/winipc.rb,
ext/winipc/winipc.c
Class Method Summary collapse
Instance Method Summary collapse
- #_unlock ⇒ Object
- #abandoned? ⇒ Boolean
-
#lock(timeout: nil) ⇒ Object
NOTE: a Windows mutex is owned by the acquiring THREAD, so Mutex waits are NOT offloaded to a worker (that would acquire on the wrong thread).
- #synchronize(timeout: nil) ⇒ Object
- #try_lock ⇒ Object
- #unlock ⇒ Object
Class Method Details
Instance Method Details
#_unlock ⇒ Object
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 |
# File 'ext/winipc/winipc.c', line 1107
static VALUE
mutex_unlock(VALUE self)
{
sync_t *s = sync_live(self);
if (!ReleaseMutex(s->h)) {
DWORD e = GetLastError();
if (e == ERROR_NOT_OWNER) raise_code(eNotOwner, "ReleaseMutex", e);
raise_gle("ReleaseMutex", e);
}
return self;
}
|
#abandoned? ⇒ Boolean
1149 |
# File 'ext/winipc/winipc.c', line 1149
static VALUE sync_abandoned_p(VALUE self) { return sync_get(self)->abandoned ? Qtrue : Qfalse; }
|
#lock(timeout: nil) ⇒ Object
NOTE: a Windows mutex is owned by the acquiring THREAD, so Mutex waits are NOT offloaded to a worker (that would acquire on the wrong thread). They release the GVL but, under a fiber scheduler, block the loop for the wait. Use Event/Semaphore for fiber-cooperative coordination.
254 255 256 |
# File 'lib/winipc.rb', line 254 def lock(timeout: nil) _wait(Winipc.ms_for(timeout)) != :timeout # :ok or :abandoned both acquire end |
#synchronize(timeout: nil) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/winipc.rb', line 267 def synchronize(timeout: nil) result = _wait(Winipc.ms_for(timeout)) raise TimeoutError, "winipc: mutex not acquired within timeout" if result == :timeout begin if result == :abandoned raise Abandoned, "winipc: mutex was abandoned by a dead owner; shared state may be inconsistent" end yield ensure _unlock end end |
#try_lock ⇒ Object
258 259 260 |
# File 'lib/winipc.rb', line 258 def try_lock lock(timeout: 0) end |
#unlock ⇒ Object
262 263 264 265 |
# File 'lib/winipc.rb', line 262 def unlock _unlock self end |