Implement CreateSemaphoreExA/W
authorStephen Toub <stoub@microsoft.com>
Fri, 13 Feb 2015 20:36:51 +0000 (15:36 -0500)
committerStephen Toub <stoub@microsoft.com>
Fri, 13 Feb 2015 20:45:00 +0000 (15:45 -0500)
Any managed code that touches the ThreadPool is currently crashing when the ThreadPool tries to initialize. This is due to it creating a semaphore via CreateSemaphoreExA/W in the pal, and those functions not being implemented.

This commit just implements those functions by delegating to their non-Ex counterparts. With this change, ThreadPool.QueueUserWorkItem, Task.Run, etc. are able to successfully schedule work and have it executed.

src/pal/inc/pal.h
src/pal/src/synchobj/semaphore.cpp

index b5ee386..22a4cf2 100644 (file)
@@ -1492,6 +1492,17 @@ CreateSemaphoreA(
 PALIMPORT
 HANDLE
 PALAPI
+CreateSemaphoreExA(
+         IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
+         IN LONG lInitialCount,
+         IN LONG lMaximumCount,
+         IN LPCSTR lpName,
+         IN /*_Reserved_*/  DWORD dwFlags,
+         IN DWORD dwDesiredAccess);
+
+PALIMPORT
+HANDLE
+PALAPI
 CreateSemaphoreW(
          IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
          IN LONG lInitialCount,
index 64905ad..a5fe3b8 100644 (file)
@@ -61,7 +61,7 @@ Function:
 CreateSemaphoreExA
 
 Note:
-lpSemaphoreAttributes currentely ignored:
+lpSemaphoreAttributes currently ignored:
 -- Win32 object security not supported
 -- handles to semaphore objects are not inheritable
 
@@ -75,11 +75,20 @@ CreateSemaphoreExA(
         IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
         IN LONG lInitialCount,
         IN LONG lMaximumCount,
-        IN LPCSTR lpName)
+        IN LPCSTR lpName,
+        IN /*_Reserved_*/  DWORD dwFlags,
+        IN DWORD dwDesiredAccess)
 {
-    // TODO: Implement this!
-    ERROR("Needs Implementation!!!");
-    return NULL;
+    // dwFlags is reserved and unused, and dwDesiredAccess is currently
+    // only ever used as SEMAPHORE_ALL_ACCESS.  The other parameters
+    // all map to CreateSemaphoreA.
+    _ASSERTE(SEMAPHORE_ALL_ACCESS == dwDesiredAccess);
+
+    return CreateSemaphoreA(
+        lpSemaphoreAttributes,
+        lInitialCount,
+        lMaximumCount,
+        lpName);
 }
 
 /*++
@@ -87,7 +96,7 @@ Function:
   CreateSemaphoreA
 
 Note:
-  lpSemaphoreAttributes currentely ignored:
+  lpSemaphoreAttributes currently ignored:
   -- Win32 object security not supported
   -- handles to semaphore objects are not inheritable
 
@@ -190,9 +199,16 @@ CreateSemaphoreExW(
         IN /*_Reserved_*/  DWORD dwFlags,
         IN DWORD dwDesiredAccess)
 {
-    // TODO: Implement this!
-    ERROR("Needs Implementation!!!");
-    return NULL;
+    // dwFlags is reserved and unused, and dwDesiredAccess is currently
+    // only ever used as SEMAPHORE_ALL_ACCESS.  The other parameters
+    // all map to CreateSemaphoreW.
+    _ASSERTE(SEMAPHORE_ALL_ACCESS == dwDesiredAccess);
+
+    return CreateSemaphoreW(
+        lpSemaphoreAttributes,
+        lInitialCount,
+        lMaximumCount,
+        lpName);
 }
 
 /*++