summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%google.com <devnull@localhost>2008-01-27 20:44:02 +0000
committerwtc%google.com <devnull@localhost>2008-01-27 20:44:02 +0000
commit49c5285a37fd603ffe8c956cec3226e60ec2320d (patch)
tree1c42445adb09efeb874501995ddcb624a3a791a9
parentc24e1d73867f047e79e4a927854cc051d8caf48e (diff)
downloadnspr-hg-49c5285a37fd603ffe8c956cec3226e60ec2320d.tar.gz
Bug 334826: use compiler's intrinsic atomic functions only when our ownNSPR_HEAD_20080127
PR_AtomicXXX functions are truly atomic, otherwise the macros and functions can't be used interchangeably. Add Nelson's suggested changes as a TODO comment. Modified files: pratom.h atomic.c
-rw-r--r--pr/include/pratom.h16
-rw-r--r--pr/tests/atomic.c8
2 files changed, 22 insertions, 2 deletions
diff --git a/pr/include/pratom.h b/pr/include/pratom.h
index 2e4967c2..9389ee38 100644
--- a/pr/include/pratom.h
+++ b/pr/include/pratom.h
@@ -102,6 +102,13 @@ NSPR_API(PRInt32) PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
** DESCRIPTION:
** Macro versions of the atomic operations. They may be implemented
** as compiler intrinsics.
+**
+** IMPORTANT NOTE TO NSPR MAINTAINERS:
+** Implement these macros with compiler intrinsics only on platforms
+** where the PR_AtomicXXX functions are truly atomic (i.e., where the
+** configuration macro _PR_HAVE_ATOMIC_OPS is defined). Otherwise,
+** the macros and functions won't be compatible and can't be used
+** interchangeably.
*/
#if defined(_WIN32) && (_MSC_VER >= 1310)
@@ -123,8 +130,13 @@ long __cdecl _InterlockedExchangeAdd(long volatile *Addend, long Value);
#define PR_ATOMIC_ADD(ptr, val) (_InterlockedExchangeAdd(ptr, val) + (val))
#elif ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && \
- (defined(__i386__) || defined(__ia64__) || defined(__x86_64__) || \
- defined(__powerpc__) || defined(__ppc__) || defined(__alpha))
+ ((defined(DARWIN) && \
+ (defined(__ppc__) || defined(__i386__))) || \
+ (defined(LINUX) && \
+ (defined(__i386__) || defined(__ia64__) || defined(__x86_64__) || \
+ (defined(__powerpc__) && !defined(__powerpc64__)) || \
+ defined(__alpha))))
+
/*
* Because the GCC manual warns that some processors may support
* reduced functionality of __sync_lock_test_and_set, we test for the
diff --git a/pr/tests/atomic.c b/pr/tests/atomic.c
index 4b454fee..5970fe0c 100644
--- a/pr/tests/atomic.c
+++ b/pr/tests/atomic.c
@@ -39,6 +39,14 @@
#include "prprf.h"
#include "pratom.h"
+/*
+ * TODO: create a macro to generate the six lines of code that are repeated
+ * for every test. Also rewrite the statement
+ * result = result | ((EXPRESSION) ? 0 : 1);
+ * as
+ * result |= !(EXPRESSION);
+ */
+
PRIntn main(PRIntn argc, char **argv)
{
PRInt32 rv, oldval, test, result = 0;