ReactOS  0.4.14-dev-77-gd9e7c48
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 }
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define GDITAG_SEMAPHORE
Definition: tags.h:158
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
smooth NULL
Definition: ftsmooth.c:416
DWORD_PTR HSEMAPHORE
Definition: axcore.idl:60
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG ERESOURCE
Definition: env_spec_w32.h:594
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

◆ _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 }
PVOID NTAPI PsGetThreadWin32Thread(IN PETHREAD Thread)
Definition: thread.c:795
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
smooth NULL
Definition: ftsmooth.c:416
#define DPRINT1
Definition: precomp.h:8
PVOID NTAPI ExEnterCriticalRegionAndAcquireResourceExclusive(IN PERESOURCE Resource)
Definition: resource.c:2189

◆ _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 }
PVOID NTAPI PsGetThreadWin32Thread(IN PETHREAD Thread)
Definition: thread.c:795
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
smooth NULL
Definition: ftsmooth.c:416
VOID FASTCALL ExReleaseResourceAndLeaveCriticalRegion(IN PERESOURCE Resource)
Definition: resource.c:2278
#define DPRINT1
Definition: precomp.h:8

◆ 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 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
_Requires_lock_not_held_ hsem VOID APIENTRY EngDeleteSemaphore(_Inout_ __drv_freesMem(Mem) HSEMAPHORE hsem)
Definition: semaphor.c:106
smooth NULL
Definition: ftsmooth.c:416
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
#define InterlockedDecrement
Definition: armddk.h:52

◆ 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 }
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
#define GDITAG_SEMAPHORE
Definition: tags.h:158
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

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 ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
#define TRUE
Definition: types.h:120
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
smooth NULL
Definition: ftsmooth.c:416
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
DWORD_PTR HSEMAPHORE
Definition: axcore.idl:60
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define InterlockedDecrement
Definition: armddk.h:52
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define InterlockedIncrement
Definition: armddk.h:53
HSEMAPHORE WINAPI EngCreateSemaphore(VOID)
Definition: eng.c:75

◆ 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 }
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

◆ 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 }
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
BOOLEAN NTAPI ExIsResourceAcquiredExclusiveLite(IN PERESOURCE Resource)
Definition: resource.c:1619
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)