diff options
author | sfraser%netscape.com <devnull@localhost> | 2001-12-07 23:57:59 +0000 |
---|---|---|
committer | sfraser%netscape.com <devnull@localhost> | 2001-12-07 23:57:59 +0000 |
commit | 29217a577b23546b22459429429d8c64ceeb3f79 (patch) | |
tree | b12918d1459c726a673fd321cc765e29b56b9b79 | |
parent | 8c665f982e5c406b6fae99f557d2da646d1c35f6 (diff) | |
download | nspr-hg-29217a577b23546b22459429429d8c64ceeb3f79.tar.gz |
Fix bug 106999 -- implement Mac atomic operations using Open Transport routines for speed. r=wtc.
-rw-r--r-- | pr/include/md/_macos.h | 19 | ||||
-rw-r--r-- | pr/src/md/mac/macthr.c | 20 |
2 files changed, 39 insertions, 0 deletions
diff --git a/pr/include/md/_macos.h b/pr/include/md/_macos.h index caf73cb9..f1f0f8aa 100644 --- a/pr/include/md/_macos.h +++ b/pr/include/md/_macos.h @@ -44,6 +44,7 @@ #define PR_DLL_SUFFIX "" #define _PR_LOCAL_THREADS_ONLY #define _PR_NO_PREEMPT 1 +#define _PR_HAVE_ATOMIC_OPS 1 #include "prinit.h" #include "prio.h" @@ -61,7 +62,9 @@ #include <stddef.h> #include <setjmp.h> + #include <Errors.h> +#include <OpenTransport.h> #define _PR_HAVE_PEEK_BUFFER #define _PR_PEEK_BUFFER_MAX (16 * 1024) @@ -678,4 +681,20 @@ extern void LeaveCritialRegion(); #endif +/* + * Atomic operations + */ +#ifdef _PR_HAVE_ATOMIC_OPS + +extern PRInt32 _MD_AtomicSet(PRInt32 *val, PRInt32 newval); + +#define _MD_INIT_ATOMIC() +#define _MD_ATOMIC_INCREMENT(val) OTAtomicAdd32(1, (SInt32 *)val) +#define _MD_ATOMIC_ADD(ptr, val) OTAtomicAdd32(val, (SInt32 *)ptr) +#define _MD_ATOMIC_DECREMENT(val) OTAtomicAdd32(-1, (SInt32 *)val) +#define _MD_ATOMIC_SET(val, newval) _MD_AtomicSet(val, newval) + +#endif /* _PR_HAVE_ATOMIC_OPS */ + + #endif /* prmacos_h___ */ diff --git a/pr/src/md/mac/macthr.c b/pr/src/md/mac/macthr.c index b01eda61..0df8a590 100644 --- a/pr/src/md/mac/macthr.c +++ b/pr/src/md/mac/macthr.c @@ -433,6 +433,26 @@ PRStatus _MD_KillProcess(PRProcess *process) PR_SetError(PR_NOT_IMPLEMENTED_ERROR, unimpErr); return PR_FAILURE; } + +//############################################################################## +//############################################################################## +#pragma mark - +#pragma mark ATOMIC OPERATIONS + +#ifdef _PR_HAVE_ATOMIC_OPS +PRInt32 +_MD_AtomicSet(PRInt32 *val, PRInt32 newval) +{ + PRInt32 rv; + do { + rv = *val; + } while (!OTCompareAndSwap32(rv, newval, (UInt32*)val)); + + return rv; +} + +#endif // _PR_HAVE_ATOMIC_OPS + //############################################################################## //############################################################################## #pragma mark - |