b16d86abf3b28397a8c9667eb38969b9fe334c0a
11 EngCreateSemaphore ( VOID
)
13 // www.osr.com/ddk/graphics/gdifncs_95lz.htm
14 PERESOURCE psem
= ExAllocatePoolWithTag( NonPagedPool
, sizeof(ERESOURCE
), TAG_GSEM
);
17 if ( !NT_SUCCESS(ExInitializeResourceLite ( psem
)) )
19 ExFreePoolWithTag ( psem
, TAG_GSEM
);
22 return (HSEMAPHORE
)psem
;
27 IntGdiAcquireSemaphore ( HSEMAPHORE hsem
)
29 KeEnterCriticalRegion();
30 ExAcquireResourceExclusiveLite ( (PERESOURCE
)hsem
, TRUE
);
38 EngAcquireSemaphore ( IN HSEMAPHORE hsem
)
40 // www.osr.com/ddk/graphics/gdifncs_14br.htm
43 IntGdiAcquireSemaphore ( hsem
);
44 W32Thread
= PsGetThreadWin32Thread(PsGetCurrentThread());
45 if (W32Thread
) W32Thread
->dwEngAcquireCount
++;
51 IntGdiReleaseSemaphore ( HSEMAPHORE hsem
)
53 ExReleaseResourceLite ( (PERESOURCE
)hsem
);
54 KeLeaveCriticalRegion();
62 EngReleaseSemaphore ( IN HSEMAPHORE hsem
)
64 // www.osr.com/ddk/graphics/gdifncs_5u3r.htm
67 W32Thread
= PsGetThreadWin32Thread(PsGetCurrentThread());
68 if (W32Thread
) --W32Thread
->dwEngAcquireCount
;
69 IntGdiReleaseSemaphore ( hsem
);
77 EngDeleteSemaphore ( IN HSEMAPHORE hsem
)
79 // www.osr.com/ddk/graphics/gdifncs_13c7.htm
82 ExDeleteResourceLite((PERESOURCE
)hsem
);
84 ExFreePoolWithTag( (PVOID
)hsem
, TAG_GSEM
);
92 EngIsSemaphoreOwned ( IN HSEMAPHORE hsem
)
94 // www.osr.com/ddk/graphics/gdifncs_6wmf.htm
96 return (((PERESOURCE
)hsem
)->ActiveCount
> 0);
104 EngIsSemaphoreOwnedByCurrentThread ( IN HSEMAPHORE hsem
)
106 // www.osr.com/ddk/graphics/gdifncs_9yxz.htm
108 return ExIsResourceAcquiredExclusiveLite ( (PERESOURCE
)hsem
);
115 EngInitializeSafeSemaphore(
116 OUT ENGSAFESEMAPHORE
*Semaphore
)
120 if (InterlockedIncrement(&Semaphore
->lCount
) == 1)
122 /* Create the semaphore */
123 hSem
= EngCreateSemaphore();
126 InterlockedDecrement(&Semaphore
->lCount
);
129 /* FIXME - not thread-safe! Check result of InterlockedCompareExchangePointer
130 and delete semaphore if already initialized! */
131 (void)InterlockedExchangePointer((volatile PVOID
*)&Semaphore
->hsem
, hSem
);
135 /* Wait for the other thread to create the semaphore */
136 ASSERT(Semaphore
->lCount
> 1);
137 ASSERT_IRQL_LESS_OR_EQUAL(PASSIVE_LEVEL
);
138 while (Semaphore
->hsem
== NULL
);
148 EngDeleteSafeSemaphore(
149 IN OUT ENGSAFESEMAPHORE
*Semaphore
)
151 if (InterlockedDecrement(&Semaphore
->lCount
) == 0)
153 /* FIXME - not thread-safe! Use result of InterlockedCompareExchangePointer! */
154 EngDeleteSemaphore(Semaphore
->hsem
);
155 (void)InterlockedExchangePointer((volatile PVOID
*)&Semaphore
->hsem
, NULL
);