Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / net / third_party / nss / ssl / sslmutex.h
blobb3f3212fb78c27675df00873b6d5f277dd4356c4
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 /* $Id: sslmutex.h,v 1.14 2012/04/25 14:50:12 gerv%gerv.net Exp $ */
5 #ifndef __SSLMUTEX_H_
6 #define __SSLMUTEX_H_ 1
8 /* What SSL really wants is portable process-shared unnamed mutexes in
9 * shared memory, that have the property that if the process that holds
10 * them dies, they are released automatically, and that (unlike fcntl
11 * record locking) lock to the thread, not to the process.
12 * NSPR doesn't provide that.
13 * Windows has mutexes that meet that description, but they're not portable.
14 * POSIX mutexes are not automatically released when the holder dies,
15 * and other processes/threads cannot release the mutex on behalf of the
16 * dead holder.
17 * POSIX semaphores can be used to accomplish this on systems that implement
18 * process-shared unnamed POSIX semaphores, because a watchdog thread can
19 * discover and release semaphores that were held by a dead process.
20 * On systems that do not support process-shared POSIX unnamed semaphores,
21 * they can be emulated using pipes.
22 * The performance cost of doing that is not yet measured.
24 * So, this API looks a lot like POSIX pthread mutexes.
27 #include "prtypes.h"
28 #include "prlock.h"
30 #if defined(NETBSD)
31 #include <sys/param.h> /* for __NetBSD_Version__ */
32 #endif
34 #if defined(WIN32)
36 #include <wtypes.h>
38 typedef struct
40 PRBool isMultiProcess;
41 #ifdef WINNT
42 /* on WINNT we need both the PRLock and the Win32 mutex for fibers */
43 struct {
44 #else
45 union {
46 #endif
47 PRLock* sslLock;
48 HANDLE sslMutx;
49 } u;
50 } sslMutex;
52 typedef int sslPID;
54 #elif defined(LINUX) || defined(AIX) || defined(BEOS) || defined(BSDI) || (defined(NETBSD) && __NetBSD_Version__ < 500000000) || defined(OPENBSD)
56 #include <sys/types.h>
57 #include "prtypes.h"
59 typedef struct {
60 PRBool isMultiProcess;
61 union {
62 PRLock* sslLock;
63 struct {
64 int mPipes[3];
65 PRInt32 nWaiters;
66 } pipeStr;
67 } u;
68 } sslMutex;
69 typedef pid_t sslPID;
71 #elif defined(XP_UNIX) /* other types of Unix */
73 #include <sys/types.h> /* for pid_t */
74 #include <semaphore.h> /* for sem_t, and sem_* functions */
76 typedef struct
78 PRBool isMultiProcess;
79 union {
80 PRLock* sslLock;
81 sem_t sem;
82 } u;
83 } sslMutex;
85 typedef pid_t sslPID;
87 #else
89 /* what platform is this ?? */
91 typedef struct {
92 PRBool isMultiProcess;
93 union {
94 PRLock* sslLock;
95 /* include cross-process locking mechanism here */
96 } u;
97 } sslMutex;
99 typedef int sslPID;
101 #endif
103 #include "seccomon.h"
105 SEC_BEGIN_PROTOS
107 extern SECStatus sslMutex_Init(sslMutex *sem, int shared);
109 /* If processLocal is set to true, then just free resources which are *only* associated
110 * with the current process. Leave any shared resources (including the state of
111 * shared memory) intact. */
112 extern SECStatus sslMutex_Destroy(sslMutex *sem, PRBool processLocal);
114 extern SECStatus sslMutex_Unlock(sslMutex *sem);
116 extern SECStatus sslMutex_Lock(sslMutex *sem);
118 #ifdef WINNT
120 extern SECStatus sslMutex_2LevelInit(sslMutex *sem);
122 #endif
124 SEC_END_PROTOS
126 #endif