ReactOS  0.4.14-dev-77-gd9e7c48
semphobj.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for semphobj.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI KeInitializeSemaphore (IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
 
LONG NTAPI KeReadStateSemaphore (IN PKSEMAPHORE Semaphore)
 
LONG NTAPI KeReleaseSemaphore (IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file semphobj.c.

Function Documentation

◆ KeInitializeSemaphore()

VOID NTAPI KeInitializeSemaphore ( IN PKSEMAPHORE  Semaphore,
IN LONG  Count,
IN LONG  Limit 
)

Definition at line 22 of file semphobj.c.

25 {
26  /* Simply Initialize the Header */
27  Semaphore->Header.Type = SemaphoreObject;
28  Semaphore->Header.Size = sizeof(KSEMAPHORE) / sizeof(ULONG);
29  Semaphore->Header.SignalState = Count;
30  InitializeListHead(&(Semaphore->Header.WaitListHead));
31 
32  /* Set the Limit */
33  Semaphore->Limit = Limit;
34 }
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
struct _KSEMAPHORE KSEMAPHORE
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int ULONG
Definition: retypes.h:1
_In_ LONG _In_ LONG Limit
Definition: kefuncs.h:328

Referenced by DLDAcquireShared(), DriverEntry(), ExpAllocateSharedWaiterSemaphore(), ExReinitializeResourceLite(), FsRtlInitSystem(), HDA_InitCodec(), InitializeMessageWaiterQueue(), KeInitThread(), LpcpInitializePortQueue(), NtCreateSemaphore(), PspCreateThread(), SacInitializeLock(), USBH_AddDevice(), USBH_StartHubFdoDevice(), and USBPORT_AddDevice().

◆ KeReadStateSemaphore()

LONG NTAPI KeReadStateSemaphore ( IN PKSEMAPHORE  Semaphore)

Definition at line 41 of file semphobj.c.

42 {
43  ASSERT_SEMAPHORE(Semaphore);
44 
45  /* Just return the Signal State */
46  return Semaphore->Header.SignalState;
47 }
#define ASSERT_SEMAPHORE(Object)

Referenced by LpcpDestroyPortQueue(), NtQuerySemaphore(), and NtSecureConnectPort().

◆ KeReleaseSemaphore()

LONG NTAPI KeReleaseSemaphore ( IN PKSEMAPHORE  Semaphore,
IN KPRIORITY  Increment,
IN LONG  Adjustment,
IN BOOLEAN  Wait 
)

Definition at line 54 of file semphobj.c.

58 {
60  KIRQL OldIrql;
61  PKTHREAD CurrentThread;
62  ASSERT_SEMAPHORE(Semaphore);
64 
65  /* Lock the Dispatcher Database */
67 
68  /* Save the Old State and get new one */
69  InitialState = Semaphore->Header.SignalState;
71 
72  /* Check if the Limit was exceeded */
73  if ((Semaphore->Limit < State) || (InitialState > State))
74  {
75  /* Raise an error if it was exceeded */
78  }
79 
80  /* Now set the new state */
81  Semaphore->Header.SignalState = State;
82 
83  /* Check if we should wake it */
84  if (!(InitialState) && !(IsListEmpty(&Semaphore->Header.WaitListHead)))
85  {
86  /* Wake the Semaphore */
87  KiWaitTest(&Semaphore->Header, Increment);
88  }
89 
90  /* Check if the caller wants to wait after this release */
91  if (Wait == FALSE)
92  {
93  /* Release the Lock */
95  }
96  else
97  {
98  /* Set a wait */
99  CurrentThread = KeGetCurrentThread();
100  CurrentThread->WaitNext = TRUE;
101  CurrentThread->WaitIrql = OldIrql;
102  }
103 
104  /* Return the previous state */
105  return InitialState;
106 }
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
#define TRUE
Definition: types.h:120
#define STATUS_SEMAPHORE_LIMIT_EXCEEDED
Definition: ntstatus.h:293
#define ExRaiseStatus
Definition: ntoskrnl.h:95
VOID FASTCALL KiWaitTest(PVOID Object, KPRIORITY Increment)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ KPRIORITY _In_ LONG Adjustment
Definition: kefuncs.h:451
long LONG
Definition: pedump.c:60
#define ASSERT_SEMAPHORE(Object)
ULONG WaitNext
Definition: ketypes.h:1586
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE _In_ BOOLEAN InitialState
Definition: exfuncs.h:165
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
enum State_ State
Definition: pofuncs.h:54
FORCEINLINE VOID KiReleaseDispatcherLock(IN KIRQL OldIrql)
Definition: ke_x.h:152
FORCEINLINE KIRQL KiAcquireDispatcherLock(VOID)
Definition: ke_x.h:144
#define KeGetCurrentThread
Definition: hal.h:44
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
KIRQL WaitIrql
Definition: ketypes.h:1685
IN BOOLEAN Wait
Definition: fatprocs.h:1529

Referenced by CsqInsertIrp(), ExConvertExclusiveToSharedLite(), ExReleaseResourceForThreadLite(), FsRtlDeregisterUncProvider(), FsRtlRegisterUncProvider(), HDA_DpcForIsr(), IssueUniqueIdChangeNotify(), KsGenerateEvent(), LpcpDestroyPortQueue(), MountMgrCheckUnprocessedVolumes(), MountMgrDeviceControl(), MountMgrMountedDeviceArrival(), MountMgrMountedDeviceRemoval(), MountMgrQueryDosVolumePaths(), MountMgrShutdown(), MountMgrUniqueIdChangeRoutine(), MountMgrUnload(), NtReleaseSemaphore(), NtSignalAndWaitForSingleObject(), QueueWorkItem(), ReconcileThisDatabaseWithMasterWorker(), ReleaseRemoteDatabaseSemaphore(), RemoveWorkItem(), SacReleaseLock(), USBH_ChangeIndicationWorker(), USBH_CheckHubIdle(), USBH_CheckIdleAbort(), USBH_FdoIdleNotificationCallback(), USBH_FdoPnP(), USBH_FdoPower(), USBH_FdoQueryBusRelations(), USBH_FlushPortPwrList(), USBH_PdoIoctlGetPortStatus(), USBH_ResetDevice(), USBH_ResetPortWorker(), USBH_SyncResetPort(), USBPORT_CreateDevice(), USBPORT_HandleSelectConfiguration(), USBPORT_HandleSelectInterface(), USBPORT_InitializeDevice(), USBPORT_RemoveDevice(), USBPORT_RestoreDevice(), and USBPORT_SynchronizeRootHubCallback().