| OLD | NEW |
| (Empty) |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
| 4 #ifndef __SSLMUTEX_H_ | |
| 5 #define __SSLMUTEX_H_ 1 | |
| 6 | |
| 7 /* What SSL really wants is portable process-shared unnamed mutexes in | |
| 8 * shared memory, that have the property that if the process that holds | |
| 9 * them dies, they are released automatically, and that (unlike fcntl | |
| 10 * record locking) lock to the thread, not to the process. | |
| 11 * NSPR doesn't provide that. | |
| 12 * Windows has mutexes that meet that description, but they're not portable. | |
| 13 * POSIX mutexes are not automatically released when the holder dies, | |
| 14 * and other processes/threads cannot release the mutex on behalf of the | |
| 15 * dead holder. | |
| 16 * POSIX semaphores can be used to accomplish this on systems that implement | |
| 17 * process-shared unnamed POSIX semaphores, because a watchdog thread can | |
| 18 * discover and release semaphores that were held by a dead process. | |
| 19 * On systems that do not support process-shared POSIX unnamed semaphores, | |
| 20 * they can be emulated using pipes. | |
| 21 * The performance cost of doing that is not yet measured. | |
| 22 * | |
| 23 * So, this API looks a lot like POSIX pthread mutexes. | |
| 24 */ | |
| 25 | |
| 26 #include "prtypes.h" | |
| 27 #include "prlock.h" | |
| 28 | |
| 29 #if defined(NETBSD) | |
| 30 #include <sys/param.h> /* for __NetBSD_Version__ */ | |
| 31 #endif | |
| 32 | |
| 33 #if defined(WIN32) | |
| 34 | |
| 35 #include <wtypes.h> | |
| 36 | |
| 37 typedef struct { | |
| 38 PRBool isMultiProcess; | |
| 39 #ifdef WINNT | |
| 40 /* on WINNT we need both the PRLock and the Win32 mutex for fibers */ | |
| 41 struct { | |
| 42 #else | |
| 43 union { | |
| 44 #endif | |
| 45 PRLock *sslLock; | |
| 46 HANDLE sslMutx; | |
| 47 } u; | |
| 48 } sslMutex; | |
| 49 | |
| 50 typedef int sslPID; | |
| 51 | |
| 52 #elif defined(LINUX) || defined(AIX) || defined(BEOS) || defined(BSDI) || (defin
ed(NETBSD) && __NetBSD_Version__ < 500000000) || defined(OPENBSD) | |
| 53 | |
| 54 #include <sys/types.h> | |
| 55 #include "prtypes.h" | |
| 56 | |
| 57 typedef struct { | |
| 58 PRBool isMultiProcess; | |
| 59 union { | |
| 60 PRLock *sslLock; | |
| 61 struct { | |
| 62 int mPipes[3]; | |
| 63 PRInt32 nWaiters; | |
| 64 } pipeStr; | |
| 65 } u; | |
| 66 } sslMutex; | |
| 67 typedef pid_t sslPID; | |
| 68 | |
| 69 /* other types of unix, except OS X */ | |
| 70 #elif defined(XP_UNIX) && !defined(DARWIN) | |
| 71 | |
| 72 #include <sys/types.h> /* for pid_t */ | |
| 73 #include <semaphore.h> /* for sem_t, and sem_* functions */ | |
| 74 | |
| 75 typedef struct { | |
| 76 PRBool isMultiProcess; | |
| 77 union { | |
| 78 PRLock *sslLock; | |
| 79 sem_t sem; | |
| 80 } u; | |
| 81 } sslMutex; | |
| 82 | |
| 83 typedef pid_t sslPID; | |
| 84 | |
| 85 #else /* no support for cross-process locking */ | |
| 86 | |
| 87 /* what platform is this ?? */ | |
| 88 | |
| 89 typedef struct { | |
| 90 PRBool isMultiProcess; | |
| 91 union { | |
| 92 PRLock *sslLock; | |
| 93 /* include cross-process locking mechanism here */ | |
| 94 } u; | |
| 95 } sslMutex; | |
| 96 | |
| 97 #ifdef DARWIN | |
| 98 typedef pid_t sslPID; | |
| 99 #else | |
| 100 typedef int sslPID; | |
| 101 #endif | |
| 102 | |
| 103 #endif | |
| 104 | |
| 105 #include "seccomon.h" | |
| 106 | |
| 107 SEC_BEGIN_PROTOS | |
| 108 | |
| 109 extern SECStatus sslMutex_Init(sslMutex *sem, int shared); | |
| 110 | |
| 111 /* If processLocal is set to true, then just free resources which are *only* ass
ociated | |
| 112 * with the current process. Leave any shared resources (including the state of | |
| 113 * shared memory) intact. */ | |
| 114 extern SECStatus sslMutex_Destroy(sslMutex *sem, PRBool processLocal); | |
| 115 | |
| 116 extern SECStatus sslMutex_Unlock(sslMutex *sem); | |
| 117 | |
| 118 extern SECStatus sslMutex_Lock(sslMutex *sem); | |
| 119 | |
| 120 #ifdef WINNT | |
| 121 | |
| 122 extern SECStatus sslMutex_2LevelInit(sslMutex *sem); | |
| 123 | |
| 124 #endif | |
| 125 | |
| 126 SEC_END_PROTOS | |
| 127 | |
| 128 #endif | |
| OLD | NEW |