Avoid LOCK/UNLOCK hard-coding in gc_locks.h for PS3 target
authorIvan Maidanski <ivmai@mail.ru>
Thu, 8 Nov 2012 16:48:17 +0000 (20:48 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 8 Nov 2012 16:48:17 +0000 (20:48 +0400)
* include/private/gc_locks.h (USE_PTHREAD_LOCKS): Define for
SN_TARGET_PS3 target.
* include/private/gcconfig.h (NO_PTHREAD_TRYLOCK): Likewise.
* include/private/gc_locks.h (GC_allocate_ml, LOCK, UNLOCK): Remove
explicit definition for SN_TARGET_PS3.
* include/private/gc_locks.h (UNCOND_LOCK): Define as
pthread_mutex_lock(...) instead of GC_lock() (which calls
pthread_mutex_lock) if USE_PTHREAD_LOCKS but not GC_ASSERTIONS and
not USE_SPIN_LOCK.

include/private/gc_locks.h
include/private/gcconfig.h

index f3b19e3..743fb09 100644 (file)
@@ -43,7 +43,8 @@
 #  endif
 
 #  if (!defined(AO_HAVE_test_and_set_acquire) || defined(GC_RTEMS_PTHREADS) \
-       || defined(GC_WIN32_THREADS)) && defined(GC_PTHREADS)
+       || defined(SN_TARGET_PS3) || defined(GC_WIN32_THREADS)) \
+      && defined(GC_PTHREADS)
 #    define USE_PTHREAD_LOCKS
 #  endif
 
                            || GC_lock_holder == GetCurrentThreadId())
 #    define I_DONT_HOLD_LOCK() (!GC_need_to_lock \
                            || GC_lock_holder != GetCurrentThreadId())
-#  elif defined(SN_TARGET_PS3)
-#    include <pthread.h>
-     GC_EXTERN pthread_mutex_t GC_allocate_ml;
-#    define LOCK() pthread_mutex_lock(&GC_allocate_ml)
-#    define UNLOCK() pthread_mutex_unlock(&GC_allocate_ml)
 #  elif defined(GC_PTHREADS)
 #    include <pthread.h>
 
                   GC_lock(); }
 #        define UNCOND_UNLOCK() AO_CLEAR(&GC_allocate_lock)
 #     endif /* !GC_ASSERTIONS */
-#    else /* THREAD_LOCAL_ALLOC  || USE_PTHREAD_LOCKS */
+#    else /* THREAD_LOCAL_ALLOC || USE_PTHREAD_LOCKS */
 #      ifndef USE_PTHREAD_LOCKS
 #        define USE_PTHREAD_LOCKS
 #      endif
-#    endif /* THREAD_LOCAL_ALLOC || USE_PTHREAD_LOCK */
+#    endif /* THREAD_LOCAL_ALLOC || USE_PTHREAD_LOCKS */
 #    ifdef USE_PTHREAD_LOCKS
 #      include <pthread.h>
        GC_EXTERN pthread_mutex_t GC_allocate_ml;
                   pthread_mutex_unlock(&GC_allocate_ml); }
 #      else /* !GC_ASSERTIONS */
 #        if defined(NO_PTHREAD_TRYLOCK)
-#          define UNCOND_LOCK() GC_lock()
-#        else /* !defined(NO_PTHREAD_TRYLOCK) */
-#        define UNCOND_LOCK() \
-           { if (0 != pthread_mutex_trylock(&GC_allocate_ml)) \
-               GC_lock(); }
+#          ifdef USE_SPIN_LOCK
+#            define UNCOND_LOCK() GC_lock()
+#          else
+#            define UNCOND_LOCK() pthread_mutex_lock(&GC_allocate_ml)
+#          endif
+#        else
+#          define UNCOND_LOCK() \
+              { if (0 != pthread_mutex_trylock(&GC_allocate_ml)) \
+                  GC_lock(); }
 #        endif
 #        define UNCOND_UNLOCK() pthread_mutex_unlock(&GC_allocate_ml)
 #      endif /* !GC_ASSERTIONS */
index d90ddad..a35f4ed 100644 (file)
 #     define DATAEND (ptr_t)(_end)
 #     define DATASTART (ptr_t)(__bss_start)
 #     define STACKBOTTOM ((ptr_t)ps3_get_stack_bottom())
+#     define NO_PTHREAD_TRYLOCK
+                /* Current GC LOCK() implementation for PS3 explicitly  */
+                /* use pthread_mutex_lock for some reason.              */
 #   endif
 #   ifdef AIX
 #     define OS_TYPE "AIX"