apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject [PATCH] apr_atomic.h on Linux
Date Thu, 18 Apr 2002 12:58:29 GMT
There are issues with use of asm/atomic.h on Linux: according to the
kernel gurus here this is a header for internal use of the kernel,
and shouldn't be used from userspace.

The problems are, if I understand them correctly:

- with newer kernel/glibc combinations (e.g the RHL7.3 beta) this stuff
really isn't exported to userspace, so they can't be used at all. (this
is the most serious problem, it prevents APR from building)

- it's not a portable assumption to expect anything of this header
merely if "defined(__linux)"; some Linux ports may not contain the right
things. I'd expect it may 

- with the current atomic.h I have, the operations aren't SMP-safe
unless you define CONFIG_SMP, so currently if you build on a UP box, it
won't work on an SMP box.  (With a 2.2 kernel it looks like you have to
define __SMP__)

I suggest this patch:

--- include/apr_atomic.h	9 Apr 2002 11:13:00 -0000	1.22
+++ include/apr_atomic.h	18 Apr 2002 12:46:11 -0000
@@ -154,24 +154,6 @@
 #define apr_atomic_cas(mem,with,cmp) InterlockedCompareExchange(mem,with,cmp)
 #define apr_atomic_init(pool)        APR_SUCCESS
-#elif defined(__linux)
-#include <asm/atomic.h>
-#include <asm/system.h>
-#define apr_atomic_t atomic_t
-#define apr_atomic_add(mem, val)     atomic_add(val,mem)
-#define apr_atomic_dec(mem)          !atomic_dec_and_test(mem)
-#define apr_atomic_inc(mem)          atomic_inc(mem)
-#define apr_atomic_set(mem, val)     atomic_set(mem, val)
-#define apr_atomic_read(mem)         atomic_read(mem)
-#if defined(cmpxchg)
-#define apr_atomic_init(pool)        APR_SUCCESS
-#define apr_atomic_cas(mem,with,cmp) cmpxchg(mem,cmp,with)
 #elif defined(NETWARE)
 #include <stdlib.h>
@@ -246,7 +228,7 @@
 #endif /* APR_HAS_THREADS */
-#endif /* !defined(WIN32) && !defined(__linux) */
+#endif /* !defined(WIN32) */
 #define apr_atomic_t apr_uint32_t

The mutex-based apr_atomic.c code looks like it hasn't really been
finished, but with this patch, the "testatomic"  passes except for a "no
surprise"  result which I presume is supposed to happen. (without the
patch ATOMIC_HASH could be negative, which was... problematic)

--- atomic/unix/apr_atomic.c	9 Apr 2002 06:56:55 -0000	1.12
+++ atomic/unix/apr_atomic.c	18 Apr 2002 12:48:57 -0000
@@ -63,7 +63,7 @@
 #define NUM_ATOMIC_HASH 7
 /* shift by 2 to get rid of alignment issues */
-#define ATOMIC_HASH(x) (int)(((long)x>>2)%NUM_ATOMIC_HASH)
+#define ATOMIC_HASH(x) (unsigned int)(((unsigned long)(x))%(unsigned int)NUM_ATOMIC_HASH)
 static apr_thread_mutex_t **hash_mutex;
 apr_status_t apr_atomic_init(apr_pool_t *p )
@@ -92,7 +92,6 @@
 /*        return prev; */
-    printf("debug no workee\n");
 /*    return *mem; */
 void apr_atomic_set(volatile apr_atomic_t *mem, apr_uint32_t val) 

View raw message