ReactOS 0.4.15-dev-7953-g1f49173
semaphor.c File Reference
#include <win32k.h>
#include <debug.h>
Include dependency graph for semaphor.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

 __drv_allocatesMem (Mem)
 
_Requires_lock_not_held_ hsem _Acquires_exclusive_lock_ hsem _Acquires_lock_ (_Global_critical_region_)
 
_Requires_lock_held_ hsem _Releases_lock_ hsem _Releases_lock_ (_Global_critical_region_)
 
_Requires_lock_not_held_ hsem VOID APIENTRY EngDeleteSemaphore (_Inout_ __drv_freesMem(Mem) HSEMAPHORE hsem)
 
BOOL APIENTRY EngIsSemaphoreOwned (_In_ HSEMAPHORE hsem)
 
BOOL APIENTRY EngIsSemaphoreOwnedByCurrentThread (_In_ HSEMAPHORE hsem)
 
BOOL APIENTRY EngInitializeSafeSemaphore (_Out_ ENGSAFESEMAPHORE *Semaphore)
 
VOID APIENTRY EngDeleteSafeSemaphore (_Inout_ _Post_invalid_ ENGSAFESEMAPHORE *pssem)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 3 of file semaphor.c.

Function Documentation

◆ __drv_allocatesMem()

__drv_allocatesMem ( Mem  )

Definition at line 9 of file semaphor.c.

15{
16 // www.osr.com/ddk/graphics/gdifncs_95lz.htm
18 sizeof(ERESOURCE),
20 if (!psem)
21 return NULL;
22
24 {
26 return NULL;
27 }
28
29 return (HSEMAPHORE)psem;
30}
DWORD_PTR HSEMAPHORE
Definition: axcore.idl:60
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
#define NonPagedPool
Definition: env_spec_w32.h:307
ULONG ERESOURCE
Definition: env_spec_w32.h:594
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define GDITAG_SEMAPHORE
Definition: tags.h:159

◆ _Acquires_lock_()

_Requires_lock_not_held_ hsem _Acquires_exclusive_lock_ hsem _Acquires_lock_ ( _Global_critical_region_  )

Definition at line 37 of file semaphor.c.

42{
43 // www.osr.com/ddk/graphics/gdifncs_14br.htm
44 PTHREADINFO W32Thread;
45
46 /* On Windows a NULL hsem is ignored */
47 if (hsem == NULL)
48 {
49 DPRINT1("EngAcquireSemaphore called with hsem == NULL!\n");
50 return;
51 }
52
55 if (W32Thread) W32Thread->dwEngAcquireCount++;
56}
#define DPRINT1
Definition: precomp.h:8
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
PVOID NTAPI ExEnterCriticalRegionAndAcquireResourceExclusive(IN PERESOURCE Resource)
Definition: resource.c:2194
PVOID NTAPI PsGetThreadWin32Thread(IN PETHREAD Thread)
Definition: thread.c:795

◆ _Releases_lock_()

_Requires_lock_held_ hsem _Releases_lock_ hsem _Releases_lock_ ( _Global_critical_region_  )

Definition at line 63 of file semaphor.c.

68{
69 // www.osr.com/ddk/graphics/gdifncs_5u3r.htm
70 PTHREADINFO W32Thread;
71
72 /* On Windows a NULL hsem is ignored */
73 if (hsem == NULL)
74 {
75 DPRINT1("EngReleaseSemaphore called with hsem == NULL!\n");
76 return;
77 }
78
80 if (W32Thread) --W32Thread->dwEngAcquireCount;
82}
VOID FASTCALL ExReleaseResourceAndLeaveCriticalRegion(IN PERESOURCE Resource)
Definition: resource.c:2283

◆ EngDeleteSafeSemaphore()

VOID APIENTRY EngDeleteSafeSemaphore ( _Inout_ _Post_invalid_ ENGSAFESEMAPHORE pssem)

Definition at line 181 of file semaphor.c.

183{
184 if (InterlockedDecrement(&pssem->lCount) == 0)
185 {
186 /* FIXME: Not thread-safe! Use result of InterlockedCompareExchangePointer! */
187 EngDeleteSemaphore(pssem->hsem);
188 (void)InterlockedExchangePointer((volatile PVOID *)&pssem->hsem, NULL);
189 }
190}
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
_Requires_lock_not_held_ hsem VOID APIENTRY EngDeleteSemaphore(_Inout_ __drv_freesMem(Mem) HSEMAPHORE hsem)
Definition: semaphor.c:106

◆ EngDeleteSemaphore()

_Requires_lock_not_held_ hsem VOID APIENTRY EngDeleteSemaphore ( _Inout_ __drv_freesMem(Mem) HSEMAPHORE  hsem)

Definition at line 106 of file semaphor.c.

108{
109 // www.osr.com/ddk/graphics/gdifncs_13c7.htm
110 ASSERT(hsem);
111
114}
#define ExDeleteResourceLite(res)
Definition: env_spec_w32.h:647
#define ASSERT(a)
Definition: mode.c:44

Referenced by DdHmgCreate(), DdHmgDestroy(), DxDdCleanupDxGraphics(), DxDdStartupDxGraphics(), EngDeleteSafeSemaphore(), PDEVOBJ_vDeletePDEV(), Test_EngAcquireSemaphore(), Test_EngCreateSemaphore(), and Test_EngReleaseSemaphore().

◆ EngInitializeSafeSemaphore()

BOOL APIENTRY EngInitializeSafeSemaphore ( _Out_ ENGSAFESEMAPHORE Semaphore)

Definition at line 147 of file semaphor.c.

149{
150 HSEMAPHORE hSem;
151
152 if (InterlockedIncrement(&Semaphore->lCount) == 1)
153 {
154 /* Create the semaphore */
155 hSem = EngCreateSemaphore();
156 if (hSem == 0)
157 {
158 InterlockedDecrement(&Semaphore->lCount);
159 return FALSE;
160 }
161 /* FIXME: Not thread-safe! Check result of InterlockedCompareExchangePointer
162 and delete semaphore if already initialized! */
163 (void)InterlockedExchangePointer((volatile PVOID *)&Semaphore->hsem, hSem);
164 }
165 else
166 {
167 /* Wait for the other thread to create the semaphore */
168 ASSERT(Semaphore->lCount > 1);
170 while (Semaphore->hsem == NULL);
171 }
172
173 return TRUE;
174}
#define InterlockedIncrement
Definition: armddk.h:53
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
HSEMAPHORE WINAPI EngCreateSemaphore(VOID)
Definition: eng.c:75
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251

◆ EngIsSemaphoreOwned()

BOOL APIENTRY EngIsSemaphoreOwned ( _In_ HSEMAPHORE  hsem)

Definition at line 121 of file semaphor.c.

123{
124 // www.osr.com/ddk/graphics/gdifncs_6wmf.htm
125 ASSERT(hsem);
126 return (((PERESOURCE)hsem)->ActiveCount > 0);
127}

◆ EngIsSemaphoreOwnedByCurrentThread()

BOOL APIENTRY EngIsSemaphoreOwnedByCurrentThread ( _In_ HSEMAPHORE  hsem)

Definition at line 134 of file semaphor.c.

136{
137 // www.osr.com/ddk/graphics/gdifncs_9yxz.htm
138 ASSERT(hsem);
140}
BOOLEAN NTAPI ExIsResourceAcquiredExclusiveLite(IN PERESOURCE Resource)
Definition: resource.c:1624