Roll src/third_party/WebKit 8121bc6:918aba1 (svn 188871:188878)
[chromium-blink-merge.git] / net / third_party / nss / ssl / sslmutex.h
blobb784baf665bda5b876be759b9d520f1abf34b411
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
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.
23 * So, this API looks a lot like POSIX pthread mutexes.
26 #include "prtypes.h"
27 #include "prlock.h"
29 #if defined(NETBSD)
30 #include <sys/param.h> /* for __NetBSD_Version__ */
31 #endif
33 #if defined(WIN32)
35 #include <wtypes.h>
37 typedef struct
39 PRBool isMultiProcess;
40 #ifdef WINNT
41 /* on WINNT we need both the PRLock and the Win32 mutex for fibers */
42 struct {
43 #else
44 union {
45 #endif
46 PRLock* sslLock;
47 HANDLE sslMutx;
48 } u;
49 } sslMutex;
51 typedef int sslPID;
53 #elif defined(LINUX) || defined(AIX) || defined(BEOS) || defined(BSDI) || (defined(NETBSD) && __NetBSD_Version__ < 500000000) || defined(OPENBSD)
55 #include <sys/types.h>
56 #include "prtypes.h"
58 typedef struct {
59 PRBool isMultiProcess;
60 union {
61 PRLock* sslLock;
62 struct {
63 int mPipes[3];
64 PRInt32 nWaiters;
65 } pipeStr;
66 } u;
67 } sslMutex;
68 typedef pid_t sslPID;
70 #elif defined(XP_UNIX) /* other types of Unix */
72 #include <sys/types.h> /* for pid_t */
73 #include <semaphore.h> /* for sem_t, and sem_* functions */
75 typedef struct
77 PRBool isMultiProcess;
78 union {
79 PRLock* sslLock;
80 sem_t sem;
81 } u;
82 } sslMutex;
84 typedef pid_t sslPID;
86 #else
88 /* what platform is this ?? */
90 typedef struct {
91 PRBool isMultiProcess;
92 union {
93 PRLock* sslLock;
94 /* include cross-process locking mechanism here */
95 } u;
96 } sslMutex;
98 typedef int sslPID;
100 #endif
102 #include "seccomon.h"
104 SEC_BEGIN_PROTOS
106 extern SECStatus sslMutex_Init(sslMutex *sem, int shared);
108 /* If processLocal is set to true, then just free resources which are *only* associated
109 * with the current process. Leave any shared resources (including the state of
110 * shared memory) intact. */
111 extern SECStatus sslMutex_Destroy(sslMutex *sem, PRBool processLocal);
113 extern SECStatus sslMutex_Unlock(sslMutex *sem);
115 extern SECStatus sslMutex_Lock(sslMutex *sem);
117 #ifdef WINNT
119 extern SECStatus sslMutex_2LevelInit(sslMutex *sem);
121 #endif
123 SEC_END_PROTOS
125 #endif