11 EngCreateSemaphore ( VOID
)
13 // www.osr.com/ddk/graphics/gdifncs_95lz.htm
14 PERESOURCE psem
= ExAllocatePool ( NonPagedPool
, sizeof(ERESOURCE
) );
17 if ( !NT_SUCCESS(ExInitializeResourceLite ( psem
)) )
22 return (HSEMAPHORE
)psem
;
30 EngAcquireSemaphore ( IN HSEMAPHORE hsem
)
32 // www.osr.com/ddk/graphics/gdifncs_14br.htm
34 KeEnterCriticalRegion();
35 ExAcquireResourceExclusiveLite ( (PERESOURCE
)hsem
, TRUE
);
43 EngReleaseSemaphore ( IN HSEMAPHORE hsem
)
45 // www.osr.com/ddk/graphics/gdifncs_5u3r.htm
47 ExReleaseResourceLite ( (PERESOURCE
)hsem
);
48 KeLeaveCriticalRegion();
56 EngDeleteSemaphore ( IN HSEMAPHORE hsem
)
58 // www.osr.com/ddk/graphics/gdifncs_13c7.htm
60 ExFreePool ( (PVOID
)hsem
);
68 EngIsSemaphoreOwned ( IN HSEMAPHORE hsem
)
70 // www.osr.com/ddk/graphics/gdifncs_6wmf.htm
72 return (((PERESOURCE
)hsem
)->ActiveCount
> 0);
80 EngIsSemaphoreOwnedByCurrentThread ( IN HSEMAPHORE hsem
)
82 // www.osr.com/ddk/graphics/gdifncs_9yxz.htm
84 return ExIsResourceAcquiredExclusiveLite ( (PERESOURCE
)hsem
);
91 EngInitializeSafeSemaphore(
92 OUT ENGSAFESEMAPHORE
*Semaphore
)
96 if (InterlockedIncrement(&Semaphore
->lCount
) == 1)
98 /* Create the semaphore */
99 hSem
= EngCreateSemaphore();
102 InterlockedDecrement(&Semaphore
->lCount
);
105 InterlockedExchangePointer((volatile PVOID
*)&Semaphore
->hsem
, hSem
);
109 /* Wait for the other thread to create the semaphore */
110 ASSERT(Semaphore
->lCount
> 1);
111 ASSERT_IRQL(PASSIVE_LEVEL
);
112 while (Semaphore
->hsem
== NULL
);
122 EngDeleteSafeSemaphore(
123 IN OUT ENGSAFESEMAPHORE
*Semaphore
)
125 if (InterlockedDecrement(&Semaphore
->lCount
) == 0)
127 EngDeleteSemaphore(Semaphore
->hsem
);
128 InterlockedExchangePointer((volatile PVOID
*)&Semaphore
->hsem
, NULL
);