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