semaphore semantics WINCE_NSPRPUB_RELEASE_4_2_BETA1
authorblythe%netscape.com
Wed, 06 Feb 2002 23:01:21 +0000
branchWINCE_NSPRPUB_RELEASE_4_2_BETA1
changeset 2222 5446ba777c4afeeb08ae379c65fcdffbbf4b22d4
parent 2221 49b565bc07baa7821a49fe3a141a2fb6ec2fd132
child 2224 f9706e37cd09efeaeea00ae47e83b4e5fd15cc96
push idunknown
push userunknown
push dateunknown
semaphore semantics
pr/src/md/windows/w32ipcsem.c
--- a/pr/src/md/windows/w32ipcsem.c
+++ b/pr/src/md/windows/w32ipcsem.c
@@ -139,32 +139,37 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
     if (flags & PR_SEM_CREATE) {
         if (_PR_NT_MakeSecurityDescriptorACL(mode, semAccessTable,
                 &pSD, &pACL) == PR_SUCCESS) {
             sa.nLength = sizeof(sa);
             sa.lpSecurityDescriptor = pSD;
             sa.bInheritHandle = FALSE;
             lpSA = &sa;
         }
+#if !defined(WINCE)
         sem->sem = CreateSemaphore(lpSA, value, 0x7fffffff, osname);
+#else
+        sem->sem = CreateSemaphoreA(lpSA, value, 0x7fffffff, osname);
+#endif
         if (lpSA != NULL) {
             _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
         }
         if (sem->sem == NULL) {
             _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
             PR_DELETE(sem);
             return NULL;
         }
         if ((flags & PR_SEM_EXCL) && (GetLastError() == ERROR_ALREADY_EXISTS)) {
             PR_SetError(PR_FILE_EXISTS_ERROR, ERROR_ALREADY_EXISTS);
             CloseHandle(sem->sem);
             PR_DELETE(sem);
             return NULL;
         }
     } else {
+#if !defined(WINCE)
         sem->sem = OpenSemaphore(
                 SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, FALSE, osname);
         if (sem->sem == NULL) {
             DWORD err = GetLastError();
 
             /*
              * If we open a nonexistent named semaphore, NT
              * returns ERROR_FILE_NOT_FOUND, while Win95
@@ -173,16 +178,46 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
             if (err == ERROR_INVALID_NAME) {
                 PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
             } else {
                 _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
             }
             PR_DELETE(sem);
             return NULL;
         }
+#else
+        /*
+         * WinCE has odd sematics regarding opening a semaphore.
+         * We create the semaphore.  If it existed previouisly, the
+         *  state is signaled by GetLastError....
+         */
+        sem->sem = CreateSemaphoreA(lpSA, 0, 0x7fffffff, osname);
+        if(NULL != sem->sem)
+        {
+            DWORD lastErr = GetLastError();
+
+            if(ERROR_ALREADY_EXISTS != lastErr)
+            {
+                /*
+                 * We created, not opened.
+                 * Fail....
+                 */
+                CloseHandle(sem->sem);
+                PR_DELETE(sem);
+                PR_SetError(PR_FILE_NOT_FOUND_ERROR, 0);
+                return NULL;
+            }
+        }
+        else
+        {
+            _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+            PR_DELETE(sem);
+            return NULL;
+        }
+#endif
     }
     return sem;
 }
 
 PRStatus _PR_MD_WAIT_SEMAPHORE(PRSem *sem)
 {
     DWORD rv;