Process Hacker
queuedlock.h File Reference

Go to the source code of this file.

Data Structures

struct  _PH_QUEUED_LOCK
 

Macros

#define PH_QUEUED_LOCK_OWNED   ((ULONG_PTR)0x1)
 
#define PH_QUEUED_LOCK_OWNED_SHIFT   0
 
#define PH_QUEUED_LOCK_WAITERS   ((ULONG_PTR)0x2)
 
#define PH_QUEUED_LOCK_SHARED_INC   ((ULONG_PTR)0x4)
 
#define PH_QUEUED_LOCK_SHARED_SHIFT   2
 
#define PH_QUEUED_LOCK_TRAVERSING   ((ULONG_PTR)0x4)
 
#define PH_QUEUED_LOCK_MULTIPLE_SHARED   ((ULONG_PTR)0x8)
 
#define PH_QUEUED_LOCK_FLAGS   ((ULONG_PTR)0xf)
 
#define PhGetQueuedLockSharedOwners(Value)   ((ULONG_PTR)(Value) >> PH_QUEUED_LOCK_SHARED_SHIFT)
 
#define PhGetQueuedLockWaitBlock(Value)   ((PPH_QUEUED_WAIT_BLOCK)((ULONG_PTR)(Value) & ~PH_QUEUED_LOCK_FLAGS))
 
#define PH_QUEUED_LOCK_INIT   { 0 }
 
#define PH_QUEUED_WAITER_EXCLUSIVE   0x1
 
#define PH_QUEUED_WAITER_SPINNING   0x2
 
#define PH_QUEUED_WAITER_SPINNING_SHIFT   1
 
#define PhPulseCondition   PhfPulseCondition
 
#define PhPulseAllCondition   PhfPulseAllCondition
 
#define PhWaitForCondition   PhfWaitForCondition
 
#define PH_CONDITION_WAIT_QUEUED_LOCK   0x1
 
#define PH_CONDITION_WAIT_CRITICAL_SECTION   0x2
 
#define PH_CONDITION_WAIT_FAST_LOCK   0x4
 
#define PH_CONDITION_WAIT_LOCK_TYPE_MASK   0xfff
 
#define PH_CONDITION_WAIT_SHARED   0x1000
 
#define PH_CONDITION_WAIT_SPIN   0x2000
 
#define PhWaitForConditionEx   PhfWaitForConditionEx
 
#define PhQueueWakeEvent   PhfQueueWakeEvent
 
#define PhWaitForWakeEvent   PhfWaitForWakeEvent
 

Typedefs

typedef struct _PH_QUEUED_LOCK PH_QUEUED_LOCK
 
typedef struct _PH_QUEUED_LOCKPPH_QUEUED_LOCK
 

Functions

struct DECLSPEC_ALIGN (16) _PH_QUEUED_WAIT_BLOCK
 
BOOLEAN PhQueuedLockInitialization (VOID)
 
FORCEINLINE VOID PhInitializeQueuedLock (_Out_ PPH_QUEUED_LOCK QueuedLock)
 
PHLIBAPI VOID FASTCALL PhfAcquireQueuedLockExclusive (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 Acquires a queued lock in exclusive mode.
 
PHLIBAPI VOID FASTCALL PhfAcquireQueuedLockShared (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 Acquires a queued lock in shared mode.
 
PHLIBAPI VOID FASTCALL PhfReleaseQueuedLockExclusive (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 Releases a queued lock in exclusive mode.
 
PHLIBAPI VOID FASTCALL PhfReleaseQueuedLockShared (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 Releases a queued lock in shared mode.
 
PHLIBAPI VOID FASTCALL PhfTryWakeQueuedLock (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 Wakes waiters in a queued lock, making no assumptions about the state of the lock.
 
PHLIBAPI VOID FASTCALL PhfWakeForReleaseQueuedLock (_Inout_ PPH_QUEUED_LOCK QueuedLock, _In_ ULONG_PTR Value)
 Wakes waiters in a queued lock for releasing it in exclusive mode.
 
PHLIBAPI VOID FASTCALL PhfPulseCondition (_Inout_ PPH_QUEUED_LOCK Condition)
 Wakes one thread sleeping on a condition variable.
 
PHLIBAPI VOID FASTCALL PhfPulseAllCondition (_Inout_ PPH_QUEUED_LOCK Condition)
 Wakes all threads sleeping on a condition variable.
 
PHLIBAPI VOID FASTCALL PhfWaitForCondition (_Inout_ PPH_QUEUED_LOCK Condition, _Inout_ PPH_QUEUED_LOCK Lock, _In_opt_ PLARGE_INTEGER Timeout)
 Sleeps on a condition variable.
 
PHLIBAPI VOID FASTCALL PhfWaitForConditionEx (_Inout_ PPH_QUEUED_LOCK Condition, _Inout_ PVOID Lock, _In_ ULONG Flags, _In_opt_ PLARGE_INTEGER Timeout)
 Sleeps on a condition variable.
 
PHLIBAPI VOID FASTCALL PhfQueueWakeEvent (_Inout_ PPH_QUEUED_LOCK WakeEvent, _Out_ PPH_QUEUED_WAIT_BLOCK WaitBlock)
 Queues a wait block to a wake event.
 
PHLIBAPI VOID FASTCALL PhfSetWakeEvent (_Inout_ PPH_QUEUED_LOCK WakeEvent, _Inout_opt_ PPH_QUEUED_WAIT_BLOCK WaitBlock)
 Sets a wake event, unblocking all queued wait blocks.
 
PHLIBAPI NTSTATUS FASTCALL PhfWaitForWakeEvent (_Inout_ PPH_QUEUED_LOCK WakeEvent, _Inout_ PPH_QUEUED_WAIT_BLOCK WaitBlock, _In_ BOOLEAN Spin, _In_opt_ PLARGE_INTEGER Timeout)
 Waits for a wake event to be set.
 
_Acquires_exclusive_lock_
QueuedLock FORCEINLINE VOID 
PhAcquireQueuedLockExclusive (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 
_Acquires_shared_lock_
QueuedLock FORCEINLINE VOID 
PhAcquireQueuedLockShared (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 
 _When_ (return!=0, _Acquires_exclusive_lock_(*QueuedLock)) FORCEINLINE BOOLEAN PhTryAcquireQueuedLockExclusive(_Inout_ PPH_QUEUED_LOCK QueuedLock)
 
_Releases_exclusive_lock_
QueuedLock FORCEINLINE VOID 
PhReleaseQueuedLockExclusive (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 
_Releases_shared_lock_
QueuedLock FORCEINLINE VOID 
PhReleaseQueuedLockShared (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 
FORCEINLINE VOID PhAcquireReleaseQueuedLockExclusive (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 
FORCEINLINE BOOLEAN PhTryAcquireReleaseQueuedLockExclusive (_Inout_ PPH_QUEUED_LOCK QueuedLock)
 
FORCEINLINE VOID PhSetWakeEvent (_Inout_ PPH_QUEUED_LOCK WakeEvent, _Inout_opt_ PPH_QUEUED_WAIT_BLOCK WaitBlock)
 

Variables

 PH_QUEUED_WAIT_BLOCK
 
PPH_QUEUED_WAIT_BLOCK
 

Macro Definition Documentation

#define PH_CONDITION_WAIT_CRITICAL_SECTION   0x2

Definition at line 135 of file queuedlock.h.

#define PH_CONDITION_WAIT_FAST_LOCK   0x4

Definition at line 136 of file queuedlock.h.

#define PH_CONDITION_WAIT_LOCK_TYPE_MASK   0xfff

Definition at line 137 of file queuedlock.h.

#define PH_CONDITION_WAIT_QUEUED_LOCK   0x1

Definition at line 134 of file queuedlock.h.

#define PH_CONDITION_WAIT_SHARED   0x1000

Definition at line 139 of file queuedlock.h.

#define PH_CONDITION_WAIT_SPIN   0x2000

Definition at line 140 of file queuedlock.h.

#define PH_QUEUED_LOCK_FLAGS   ((ULONG_PTR)0xf)

Definition at line 20 of file queuedlock.h.

#define PH_QUEUED_LOCK_INIT   { 0 }

Definition at line 32 of file queuedlock.h.

#define PH_QUEUED_LOCK_MULTIPLE_SHARED   ((ULONG_PTR)0x8)

Definition at line 18 of file queuedlock.h.

#define PH_QUEUED_LOCK_OWNED   ((ULONG_PTR)0x1)

Definition at line 8 of file queuedlock.h.

#define PH_QUEUED_LOCK_OWNED_SHIFT   0

Definition at line 9 of file queuedlock.h.

#define PH_QUEUED_LOCK_SHARED_INC   ((ULONG_PTR)0x4)

Definition at line 13 of file queuedlock.h.

#define PH_QUEUED_LOCK_SHARED_SHIFT   2

Definition at line 14 of file queuedlock.h.

#define PH_QUEUED_LOCK_TRAVERSING   ((ULONG_PTR)0x4)

Definition at line 17 of file queuedlock.h.

#define PH_QUEUED_LOCK_WAITERS   ((ULONG_PTR)0x2)

Definition at line 10 of file queuedlock.h.

#define PH_QUEUED_WAITER_EXCLUSIVE   0x1

Definition at line 34 of file queuedlock.h.

#define PH_QUEUED_WAITER_SPINNING   0x2

Definition at line 35 of file queuedlock.h.

#define PH_QUEUED_WAITER_SPINNING_SHIFT   1

Definition at line 36 of file queuedlock.h.

#define PhGetQueuedLockSharedOwners (   Value)    ((ULONG_PTR)(Value) >> PH_QUEUED_LOCK_SHARED_SHIFT)

Definition at line 22 of file queuedlock.h.

#define PhGetQueuedLockWaitBlock (   Value)    ((PPH_QUEUED_WAIT_BLOCK)((ULONG_PTR)(Value) & ~PH_QUEUED_LOCK_FLAGS))

Definition at line 24 of file queuedlock.h.

#define PhPulseAllCondition   PhfPulseAllCondition

Definition at line 116 of file queuedlock.h.

#define PhPulseCondition   PhfPulseCondition

Definition at line 108 of file queuedlock.h.

#define PhQueueWakeEvent   PhfQueueWakeEvent

Definition at line 153 of file queuedlock.h.

#define PhWaitForCondition   PhfWaitForCondition

Definition at line 124 of file queuedlock.h.

#define PhWaitForConditionEx   PhfWaitForConditionEx

Definition at line 142 of file queuedlock.h.

#define PhWaitForWakeEvent   PhfWaitForWakeEvent

Definition at line 170 of file queuedlock.h.

Typedef Documentation

typedef struct _PH_QUEUED_LOCK * PPH_QUEUED_LOCK

Function Documentation

_When_ ( return!  = 0,
_Acquires_exclusive_lock_ *  QueuedLock 
)

Definition at line 210 of file queuedlock.h.

struct DECLSPEC_ALIGN ( 16  )
read

A pointer to the next wait block, i.e. the wait block pushed onto the list before this one.

A pointer to the previous wait block, i.e. the wait block pushed onto the list after this one.

A pointer to the last wait block, i.e. the first waiter pushed onto the list.

Definition at line 38 of file queuedlock.h.

_Acquires_exclusive_lock_ QueuedLock FORCEINLINE VOID PhAcquireQueuedLockExclusive ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Definition at line 184 of file queuedlock.h.

_Acquires_shared_lock_ QueuedLock FORCEINLINE VOID PhAcquireQueuedLockShared ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Definition at line 196 of file queuedlock.h.

FORCEINLINE VOID PhAcquireReleaseQueuedLockExclusive ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Definition at line 259 of file queuedlock.h.

PHLIBAPI VOID FASTCALL PhfAcquireQueuedLockExclusive ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Acquires a queued lock in exclusive mode.

Parameters
QueuedLockA queued lock.

Definition at line 678 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfAcquireQueuedLockShared ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Acquires a queued lock in shared mode.

Parameters
QueuedLockA queued lock.

Definition at line 730 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfPulseAllCondition ( _Inout_ PPH_QUEUED_LOCK  Condition)

Wakes all threads sleeping on a condition variable.

Parameters
ConditionA condition variable.
Remarks
The associated lock must be acquired before calling the function.

Definition at line 1017 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfPulseCondition ( _Inout_ PPH_QUEUED_LOCK  Condition)

Wakes one thread sleeping on a condition variable.

Parameters
ConditionA condition variable.
Remarks
The associated lock must be acquired before calling the function.

Definition at line 1001 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfQueueWakeEvent ( _Inout_ PPH_QUEUED_LOCK  WakeEvent,
_Out_ PPH_QUEUED_WAIT_BLOCK  WaitBlock 
)

Queues a wait block to a wake event.

Parameters
WakeEventA wake event.
WaitBlockA wait block.
Remarks
If you later determine that the wait should not occur, you must call PhfSetWakeEvent() to dequeue the wait block.

Definition at line 1179 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfReleaseQueuedLockExclusive ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Releases a queued lock in exclusive mode.

Parameters
QueuedLockA queued lock.

Definition at line 792 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfReleaseQueuedLockShared ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Releases a queued lock in shared mode.

Parameters
QueuedLockA queued lock.

Definition at line 852 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfSetWakeEvent ( _Inout_ PPH_QUEUED_LOCK  WakeEvent,
_Inout_opt_ PPH_QUEUED_WAIT_BLOCK  WaitBlock 
)

Sets a wake event, unblocking all queued wait blocks.

Parameters
WakeEventA wake event.
WaitBlockA wait block for a cancelled wait, otherwise NULL.

Definition at line 1213 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfTryWakeQueuedLock ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Wakes waiters in a queued lock, making no assumptions about the state of the lock.

Parameters
QueuedLockA queued lock.
Remarks
This function exists only for compatibility reasons.

Definition at line 935 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfWaitForCondition ( _Inout_ PPH_QUEUED_LOCK  Condition,
_Inout_ PPH_QUEUED_LOCK  Lock,
_In_opt_ PLARGE_INTEGER  Timeout 
)

Sleeps on a condition variable.

Parameters
ConditionA condition variable.
LockA queued lock to release/acquire in exclusive mode.
TimeoutNot implemented.
Remarks
The associated lock must be acquired before calling the function.

Definition at line 1035 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfWaitForConditionEx ( _Inout_ PPH_QUEUED_LOCK  Condition,
_Inout_ PVOID  Lock,
_In_ ULONG  Flags,
_In_opt_ PLARGE_INTEGER  Timeout 
)

Sleeps on a condition variable.

Parameters
ConditionA condition variable.
LockA pointer to a lock.
FlagsA combination of flags controlling the operation.
TimeoutNot implemented.

Definition at line 1086 of file queuedlock.c.

PHLIBAPI NTSTATUS FASTCALL PhfWaitForWakeEvent ( _Inout_ PPH_QUEUED_LOCK  WakeEvent,
_Inout_ PPH_QUEUED_WAIT_BLOCK  WaitBlock,
_In_ BOOLEAN  Spin,
_In_opt_ PLARGE_INTEGER  Timeout 
)

Waits for a wake event to be set.

Parameters
WakeEventA wake event.
WaitBlockA wait block previously queued to the wake event using PhfQueueWakeEvent().
SpinTRUE to spin on the wake event before blocking, FALSE to block immediately.
TimeoutA timeout value.
Remarks
Wake events are subject to spurious wakeups. You should call this function in a loop which checks a predicate.

Definition at line 1274 of file queuedlock.c.

PHLIBAPI VOID FASTCALL PhfWakeForReleaseQueuedLock ( _Inout_ PPH_QUEUED_LOCK  QueuedLock,
_In_ ULONG_PTR  Value 
)

Wakes waiters in a queued lock for releasing it in exclusive mode.

Parameters
QueuedLockA queued lock.
ValueThe current value of the queued lock.
Remarks
The function assumes the following flags are set: PH_QUEUED_LOCK_WAITERS. The function assumes the following flags are not set: PH_QUEUED_LOCK_MULTIPLE_SHARED, PH_QUEUED_LOCK_TRAVERSING.

Definition at line 974 of file queuedlock.c.

FORCEINLINE VOID PhInitializeQueuedLock ( _Out_ PPH_QUEUED_LOCK  QueuedLock)

Definition at line 58 of file queuedlock.h.

BOOLEAN PhQueuedLockInitialization ( VOID  )

Definition at line 110 of file queuedlock.c.

_Releases_exclusive_lock_ QueuedLock FORCEINLINE VOID PhReleaseQueuedLockExclusive ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Definition at line 226 of file queuedlock.h.

_Releases_shared_lock_ QueuedLock FORCEINLINE VOID PhReleaseQueuedLockShared ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Definition at line 241 of file queuedlock.h.

FORCEINLINE VOID PhSetWakeEvent ( _Inout_ PPH_QUEUED_LOCK  WakeEvent,
_Inout_opt_ PPH_QUEUED_WAIT_BLOCK  WaitBlock 
)

Definition at line 292 of file queuedlock.h.

FORCEINLINE BOOLEAN PhTryAcquireReleaseQueuedLockExclusive ( _Inout_ PPH_QUEUED_LOCK  QueuedLock)

Definition at line 276 of file queuedlock.h.

Variable Documentation

PH_QUEUED_WAIT_BLOCK

Definition at line 52 of file queuedlock.h.

* PPH_QUEUED_WAIT_BLOCK

Definition at line 52 of file queuedlock.h.