> El 17/01/12 21:27, dormando escribió:
>
> > > could you please try 1.4.11 with the attached patch on all platforms? I'm
> > > taking a bit of a guess since google isn't very familiar with this macro.
> > >
> > > for bonus points; add an fprintf(stderr, etc) to make sure it's using the
> > > right path for each.
>
> Hello @dormando:
>
> Results after applying your patch to memcached 1.4.11 on different RHEL
> versions:
>
> - RHEL-4 (gcc 3.4.6) can be compiled without problems on both i386 and x86_64,
> thanks! :)
>
> - RHEL-5 (gcc 4.1.2) can't built on both i386 + x86_64, with a new error:
>
> https://gist.github.com/1632081
>
> - RHEL-6 (gcc 4.4.6):
>
> a) x86_64 = build without problems
>
> b) i386 = "manual" compilation works, but a I'm getting an error building
> the RPM package, it might be related with gcc flags, I'm working on it..
> rpmbuild error output:
>
> https://gist.github.com/1632139
Closer... Can you try the attached patch against 1.4.11? could've sworn
I'd tested the other path, but I guess not :(
I added some prints at the bottom that should print something to STDERR
when started in the foreground:
$ ./memcached
USING GCC ATOMICS
Any chance you could give me the output from each of your platforms as
well as the build test results? I'm a little worried that rhel-6 i386
should be using real atomics, but I haven't figured that out for sure yet.
Thanks!
diff --git a/thread.c b/thread.c
index 5735376..3c90ecb 100644
--- a/thread.c
+++ b/thread.c
@@ -43,7 +43,7 @@ pthread_mutex_t cache_lock;
/* Connection lock around accepting new connections */
pthread_mutex_t conn_lock = PTHREAD_MUTEX_INITIALIZER;
-#if !defined(__GNUC__) && !defined(__sun)
+#if !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2) && !defined(__sun)
pthread_mutex_t atomics_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
@@ -79,14 +79,14 @@ static pthread_cond_t init_cond;
static void thread_libevent_process(int fd, short which, void *arg);
inline unsigned short refcount_incr(unsigned short *refcount) {
-#ifdef __GNUC__
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
return __sync_add_and_fetch(refcount, 1);
#elif defined(__sun)
return atomic_inc_ushort_nv(refcount);
#else
unsigned short res;
mutex_lock(&atomics_mutex);
- *refcount++;
+ (*refcount)++;
res = *refcount;
pthread_mutex_unlock(&atomics_mutex);
return res;
@@ -94,14 +94,14 @@ inline unsigned short refcount_incr(unsigned short *refcount) {
}
inline unsigned short refcount_decr(unsigned short *refcount) {
-#ifdef __GNUC__
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
return __sync_sub_and_fetch(refcount, 1);
#elif defined(__sun)
return atomic_dec_ushort_nv(refcount);
#else
unsigned short res;
mutex_lock(&atomics_mutex);
- *refcount--;
+ (*refcount)--;
res = *refcount;
pthread_mutex_unlock(&atomics_mutex);
return res;
@@ -665,6 +665,14 @@ void thread_init(int nthreads, struct event_base *main_base) {
int i;
int power;
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+ fprintf(stderr, "USING GCC ATOMICS\n");
+#elif defined(__sun)
+ fprintf(stderr, "USING SUN ATOMICS\n");
+#else
+ fprintf(stderr, "USING EMULATED ATOMICS\n");
+#endif
+
pthread_mutex_init(&cache_lock, NULL);
pthread_mutex_init(&stats_lock, NULL);