summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornelsonb%netscape.com <devnull@localhost>2001-06-12 22:53:00 +0000
committernelsonb%netscape.com <devnull@localhost>2001-06-12 22:53:00 +0000
commitc5f6da7456254631e0954d085967080983b3bc66 (patch)
treeb8db38b4fce8015914d9c1fbdfc870044bff15da
parent0124fc891a2fdbd6e8ebe433c662aa15aca6501d (diff)
downloadnss-hg-c5f6da7456254631e0954d085967080983b3bc66.tar.gz
Don't use PR_Atomic functions on AIX since PPC cpus require memory
barrier instructions.
-rw-r--r--security/nss/lib/ssl/sslmutex.c70
1 files changed, 68 insertions, 2 deletions
diff --git a/security/nss/lib/ssl/sslmutex.c b/security/nss/lib/ssl/sslmutex.c
index 1000a3f3b..d382ea99e 100644
--- a/security/nss/lib/ssl/sslmutex.c
+++ b/security/nss/lib/ssl/sslmutex.c
@@ -103,11 +103,15 @@ sslMutex_Init(sslMutex *pMutex, int shared)
goto loser;
#endif
- /* Pipe starts out empty */
-
pMutex->mPipes[2] = SSL_MUTEX_MAGIC;
+#if defined(LINUX) && defined(i386)
+ /* Pipe starts out empty */
return SECSuccess;
+#else
+ /* Pipe starts with one byte. */
+ return sslMutex_Unlock(pMutex);
+#endif
loser:
nss_MD_unix_map_default_error(errno);
@@ -134,6 +138,9 @@ sslMutex_Destroy(sslMutex *pMutex)
return SECSuccess;
}
+#if defined(LINUX) && defined(i386)
+/* No memory barrier needed for this platform */
+
SECStatus
sslMutex_Unlock(sslMutex *pMutex)
{
@@ -190,6 +197,65 @@ sslMutex_Lock(sslMutex *pMutex)
return SECSuccess;
}
+#else
+
+/* Using Atomic operations requires the use of a memory barrier instruction
+** on PowerPC, Sparc, and Alpha. NSPR's PR_Atomic functions do not perform
+** them, and NSPR does not provide a function that does them (e.g. PR_Barrier).
+** So, we don't use them on those platforms.
+*/
+
+SECStatus
+sslMutex_Unlock(sslMutex *pMutex)
+{
+ int cc;
+ char c = 1;
+
+ if (pMutex->mPipes[2] != SSL_MUTEX_MAGIC) {
+ PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
+ return SECFailure;
+ }
+ do {
+ cc = write(pMutex->mPipes[1], &c, 1);
+ } while (cc < 0 && (errno == EINTR || errno == EAGAIN));
+ if (cc != 1) {
+ if (cc < 0)
+ nss_MD_unix_map_default_error(errno);
+ else
+ PORT_SetError(PR_UNKNOWN_ERROR);
+ return SECFailure;
+ }
+
+ return SECSuccess;
+}
+
+SECStatus
+sslMutex_Lock(sslMutex *pMutex)
+{
+ int cc;
+ char c;
+
+ if (pMutex->mPipes[2] != SSL_MUTEX_MAGIC) {
+ PORT_SetError(PR_INVALID_ARGUMENT_ERROR);
+ return SECFailure;
+ }
+
+ do {
+ cc = read(pMutex->mPipes[0], &c, 1);
+ } while (cc < 0 && errno == EINTR);
+ if (cc != 1) {
+ if (cc < 0)
+ nss_MD_unix_map_default_error(errno);
+ else
+ PORT_SetError(PR_UNKNOWN_ERROR);
+ return SECFailure;
+ }
+
+ return SECSuccess;
+}
+
+#endif
+
#elif defined(WIN32)
#include "win32err.h"