Struct WriteGuard
Represents a disposable write guard over a ReadWriteLock.
Implements
Namespace: Singulink.Threading
Assembly: Singulink.Threading.dll
Syntax
public struct WriteGuard : IDisposable
Remarks
Guards returned from TryEnter methods may not have entered the lock, so check
IsEntered after acquiring. Disposing a guard that did not enter the lock is a safe no-op,
so guards can always be assigned directly to a using declaration.
Disposal exits write mode. For guards obtained from EnterUpgradedWriteGuard(), this returns the thread to upgradeable read mode, and the thread can upgrade again, so write access can be scoped and repeated within one upgradeable read session. Write locks entered directly cannot be downgraded to read locks; enter the lock in upgradeable read mode instead if downgrading may be needed.
Guards are thread-affine: an entered guard must be disposed on the thread that entered the lock, which is enforced with an InvalidOperationException when violated.
Properties
| Name | Description |
|---|---|
| IsDefault | Gets a value indicating whether the instance is in its default, uninitialized state. |
| IsDisposed | Gets a value indicating whether the object has been disposed. |
| IsEntered | Gets a value indicating whether the guard entered the lock. Always true for guards
obtained from unconditional |
Methods
| Name | Description |
|---|---|
| Dispose() | Releases the write guard, exiting write mode. No-op if the guard did not enter the lock. If the guard was obtained by upgrading an upgradeable read guard, the thread returns to upgradeable read mode. |