Back to index

lightning-sunbird  0.9+nobinonly
sslmutex.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 /* $Id: sslmutex.h,v 1.10 2004/04/27 23:04:39 gerv%gerv.net Exp $ */
00037 #ifndef __SSLMUTEX_H_
00038 #define __SSLMUTEX_H_ 1
00039 
00040 /* What SSL really wants is portable process-shared unnamed mutexes in 
00041  * shared memory, that have the property that if the process that holds
00042  * them dies, they are released automatically, and that (unlike fcntl 
00043  * record locking) lock to the thread, not to the process.  
00044  * NSPR doesn't provide that.  
00045  * Windows has mutexes that meet that description, but they're not portable.  
00046  * POSIX mutexes are not automatically released when the holder dies, 
00047  * and other processes/threads cannot release the mutex on behalf of the 
00048  * dead holder.  
00049  * POSIX semaphores can be used to accomplish this on systems that implement 
00050  * process-shared unnamed POSIX semaphores, because a watchdog thread can 
00051  * discover and release semaphores that were held by a dead process.  
00052  * On systems that do not support process-shared POSIX unnamed semaphores, 
00053  * they can be emulated using pipes.  
00054  * The performance cost of doing that is not yet measured.
00055  *
00056  * So, this API looks a lot like POSIX pthread mutexes.
00057  */
00058 
00059 #include "prtypes.h"
00060 #include "prlock.h"
00061 
00062 #if defined(WIN32)
00063 
00064 #include <wtypes.h>
00065 
00066 typedef struct 
00067 {
00068     PRBool isMultiProcess;
00069 #ifdef WINNT
00070     /* on WINNT we need both the PRLock and the Win32 mutex for fibers */
00071     struct {
00072 #else
00073     union {
00074 #endif
00075         PRLock* sslLock;
00076         HANDLE sslMutx;
00077     } u;
00078 } sslMutex;
00079 
00080 typedef int    sslPID;
00081 
00082 #elif defined(LINUX) || defined(AIX) || defined(VMS) || defined(BEOS) || defined(BSDI) || defined(NETBSD) || defined(OPENBSD)
00083 
00084 #include <sys/types.h>
00085 #include "prtypes.h"
00086 
00087 typedef struct { 
00088     PRBool isMultiProcess;
00089     union {
00090         PRLock* sslLock;
00091         struct {
00092             int      mPipes[3]; 
00093             PRInt32  nWaiters;
00094         } pipeStr;
00095     } u;
00096 } sslMutex;
00097 typedef pid_t sslPID;
00098 
00099 #elif defined(XP_UNIX) /* other types of Unix */
00100 
00101 #include <sys/types.h>      /* for pid_t */
00102 #include <semaphore.h>  /* for sem_t, and sem_* functions */
00103 
00104 typedef struct
00105 {
00106     PRBool isMultiProcess;
00107     union {
00108         PRLock* sslLock;
00109         sem_t  sem;
00110     } u;
00111 } sslMutex;
00112 
00113 typedef pid_t sslPID;
00114 
00115 #else
00116 
00117 /* what platform is this ?? */
00118 
00119 typedef struct { 
00120     PRBool isMultiProcess;
00121     union {
00122         PRLock* sslLock;
00123         /* include cross-process locking mechanism here */
00124     } u;
00125 } sslMutex;
00126 
00127 typedef int sslPID;
00128 
00129 #endif
00130 
00131 #include "seccomon.h"
00132 
00133 SEC_BEGIN_PROTOS
00134 
00135 extern SECStatus sslMutex_Init(sslMutex *sem, int shared);
00136 
00137 extern SECStatus sslMutex_Destroy(sslMutex *sem);
00138 
00139 extern SECStatus sslMutex_Unlock(sslMutex *sem);
00140 
00141 extern SECStatus sslMutex_Lock(sslMutex *sem);
00142 
00143 #ifdef WINNT
00144 
00145 extern SECStatus sslMutex_2LevelInit(sslMutex *sem);
00146 
00147 #endif
00148 
00149 SEC_END_PROTOS
00150 
00151 #endif