From 23eae1e22cedddced1bb5b72b130db7b5ef83777 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Fri, 3 Oct 2008 18:20:50 +0000 Subject: [PATCH] 2008-10-03 20:20 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/vm/garbage.c * Use spinlock instead of mutex in OS2 builds - performance test. --- harbour/ChangeLog | 4 +++ harbour/source/vm/garbage.c | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8dcd60484c..e988a06c16 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,10 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-10-03 20:20 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/vm/garbage.c + * Use spinlock instead of mutex in OS2 builds - performance test. + 2008-10-03 13:50 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/vm/estack.c * pacified OS2 warning diff --git a/harbour/source/vm/garbage.c b/harbour/source/vm/garbage.c index 6097d9b840..91105342b4 100644 --- a/harbour/source/vm/garbage.c +++ b/harbour/source/vm/garbage.c @@ -50,6 +50,8 @@ * */ +#define INCL_DOSDATETIME + #include "hbvmopt.h" #include "hbapi.h" #include "hbstack.h" @@ -65,10 +67,74 @@ # include "hbthread.h" +/* Performance test. Use spinlock instead of mutex in OS2 builds */ + +#if defined( HB_OS_OS2 ) && \ + defined( __GNUC__ ) && \ + ( defined( i386 ) || defined( __i386__ ) || defined( __x86_64__ ) ) + +# if defined( HB_OS_UNIX ) +# include +# endif + + static __inline__ int hb_atomic_lock( volatile int * p ) + { + unsigned char c; + __asm__ __volatile__( + "lock\n\t" + "cmpxchgl %3, %1\n\t" + "sete %0" + :"=a" (c), "+m" (*p) + :"a" (0), "d" (1) + ); + return c; + } + + static __inline__ void hb_atomic_unlock( volatile int * p ) + { + __asm__ __volatile__( + "xchgl %0, %1" + :"+m" (*p) + :"a" (0), "r" (*p) + ); + } + + static int s_gcSpinLock = 0; + + static void hb_gc_acquire_lock( void ) + { + for( ;; ) + { + if( hb_atomic_lock( &s_gcSpinLock ) ) + return; +#if defined( HB_OS_WIN_32 ) + Sleep( 0 ); +#elif defined( HB_OS_OS2 ) + DosSleep( 0 ); +#elif defined( HB_OS_UNIX ) + sched_yield(); +#else + sleep( 0 ); +#endif + } + } + + static void hb_gc_release_lock( void ) + { + hb_atomic_unlock( &s_gcSpinLock ); + } + +# define HB_GC_LOCK hb_gc_acquire_lock(); +# define HB_GC_UNLOCK hb_gc_release_lock(); + +#else + static HB_CRITICAL_NEW( s_gcMtx ); # define HB_GC_LOCK hb_threadEnterCriticalSection( &s_gcMtx ); # define HB_GC_UNLOCK hb_threadLeaveCriticalSection( &s_gcMtx ); +#endif + #else # define HB_GC_LOCK