Skip to content

Commit def701c

Browse files
committed
MB-47166: Use correct SPIN_INITIALIZER value for AArch64
AArch64 (64bit ARM) was using the same SPIN_INITIALIZER value (1) as x86; which is incorrect. Update arch.h to use the correct value of 0. This allows most of the forestdb tests to pass on AArch64, where previously they hung in filemgr init: (gdb) bt #0 0x0000ffff981a3b40 in pthread_spin_lock () from /lib64/libpthread.so.0 #1 0x000000000041871c in filemgr_init (config=config@entry=0xfffffe6e3d00) at ../forestdb/src/filemgr.cc:269 #2 0x000000000042ccf0 in filemgr_open (filename=filename@entry=0x468f80 "./bcache_testfile", ops=0x4f6aa0 <linux_ops>, config=config@entry=0xfffffe6e3d00, log_callback=log_callback@entry=0x0) at ../forestdb/src/filemgr.cc:828 #3 0x000000000040532c in basic_test2 () at ../forestdb/tests/unit/bcache_test.cc:102 #4 0x0000000000405de8 in main () at ../forestdb/tests/unit/bcache_test.cc:258 Change-Id: Ia5fb533a0809fc5215d7563b664ac1bbd1e9fac7 Reviewed-on: http://review.couchbase.org/c/forestdb/+/159301 Reviewed-by: Srinath Duvuru <[email protected]> Reviewed-by: James H <[email protected]> Tested-by: Dave Rigby <[email protected]>
1 parent 49cf5bc commit def701c

File tree

1 file changed

+7
-63
lines changed

1 file changed

+7
-63
lines changed

src/arch.h

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -238,68 +238,6 @@
238238
#endif
239239
#define assert(a) (a)
240240

241-
#elif __linux__ && __arm__
242-
#include <inttypes.h>
243-
#include <alloca.h>
244-
245-
#define INLINE static __inline
246-
247-
#define _X64 "llx"
248-
#define _F64 "lld"
249-
#define _FSEC "ld"
250-
#define _FUSEC "ld"
251-
252-
#define _ARCH_O_DIRECT (O_DIRECT)
253-
#define malloc_align(addr, align, size) \
254-
(addr = memalign((align), (size)))
255-
#define free_align(addr) free(addr)
256-
257-
#ifndef spin_t
258-
// spinlock
259-
#include <pthread.h>
260-
#define spin_t pthread_spinlock_t
261-
#define spin_init(arg) pthread_spin_init(arg, PTHREAD_PROCESS_SHARED)
262-
#define spin_lock(arg) pthread_spin_lock(arg)
263-
#define spin_trylock(arg) \
264-
(pthread_spin_trylock(arg) == 0)
265-
#define spin_unlock(arg) pthread_spin_unlock(arg)
266-
#define spin_destroy(arg) pthread_spin_destroy(arg)
267-
#define SPIN_INITIALIZER (spin_t)(0)
268-
#endif
269-
#ifndef mutex_t
270-
// mutex
271-
#include <pthread.h>
272-
#define mutex_t pthread_mutex_t
273-
#define mutex_init(arg) pthread_mutex_init(arg, NULL)
274-
#define mutex_lock(arg) pthread_mutex_lock(arg)
275-
#define mutex_trylock(arg) \
276-
(pthread_mutex_trylock(arg) == 0)
277-
#define mutex_unlock(arg) pthread_mutex_unlock(arg)
278-
#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
279-
#define mutex_destroy(arg) pthread_mutex_destroy(arg)
280-
#endif
281-
#ifndef thread_t
282-
// thread
283-
#include <pthread.h>
284-
#define thread_t pthread_t
285-
#define thread_cond_t pthread_cond_t
286-
#define thread_create(tid, func, args) \
287-
pthread_create((tid), NULL, (func), (args))
288-
#define thread_join(tid, ret) pthread_join(tid, ret)
289-
#define thread_cancel(tid) pthread_cancel(tid)
290-
#define thread_exit(code) pthread_exit(code)
291-
#define thread_cond_init(cond) pthread_cond_init(cond, NULL)
292-
#define thread_cond_destroy(cond) pthread_cond_destroy(cond)
293-
#define thread_cond_wait(cond, mutex) pthread_cond_wait(cond, mutex)
294-
#define thread_cond_timedwait(cond, mutex, ms) \
295-
{ \
296-
struct timespec ts = convert_reltime_to_abstime(ms); \
297-
pthread_cond_timedwait(cond, mutex, &ts); \
298-
}
299-
#define thread_cond_signal(cond) pthread_cond_signal(cond)
300-
#define thread_cond_broadcast(cond) pthread_cond_broadcast(cond)
301-
#endif
302-
303241
#elif __linux__
304242
#include <inttypes.h>
305243
#include <alloca.h>
@@ -329,7 +267,13 @@
329267
(pthread_spin_trylock(arg) == 0)
330268
#define spin_unlock(arg) pthread_spin_unlock(arg)
331269
#define spin_destroy(arg) pthread_spin_destroy(arg)
332-
#define SPIN_INITIALIZER (spin_t)(1)
270+
#if defined(__i386__) || defined(__x86_64__)
271+
#define SPIN_INITIALIZER (spin_t)(1)
272+
#elif defined(__arm__) || defined(__aarch64__)
273+
#define SPIN_INITIALIZER (spin_t)(0)
274+
#else
275+
#error Unsupported architecture for SPIN_INITIALIZER
276+
#endif
333277
#endif
334278
#ifndef mutex_t
335279
// mutex

0 commit comments

Comments
 (0)