From ff6e21f3f586bab9104355ac4dcae75d58172ab7 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 10 Aug 2009 09:07:48 +0000 Subject: [PATCH] 2009-08-10 11:07 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbatomic.h % added architecture independent support for atomic operations and spinlocks in all SunOS builds * harbour/source/vm/dynlibhb.c ! reenabled dlopen interface for Sun C compilers * enabled dlopen interface for SunOS builds --- harbour/ChangeLog | 9 +++++++++ harbour/include/hbatomic.h | 37 ++++++++++++++++++++++++++++++++++-- harbour/source/vm/dynlibhb.c | 14 ++++++++++---- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8823d8431d..c7a97ab8bb 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,15 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-08-10 11:07 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbatomic.h + % added architecture independent support for atomic operations and + spinlocks in all SunOS builds + + * harbour/source/vm/dynlibhb.c + ! reenabled dlopen interface for Sun C compilers + * enabled dlopen interface for SunOS builds + 2009-08-10 03:58 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * make_gnu_os2.cmd * make_gnu.bat diff --git a/harbour/include/hbatomic.h b/harbour/include/hbatomic.h index 1a11a3d556..19b681e77b 100644 --- a/harbour/include/hbatomic.h +++ b/harbour/include/hbatomic.h @@ -59,6 +59,8 @@ # include #elif defined( HB_OS_DARWIN ) # include +#elif defined( HB_OS_SUNOS ) +# include #endif #if defined( __SVR4 ) # include @@ -368,9 +370,9 @@ HB_EXTERN_BEGIN # define HB_SPINLOCK_ACQUIRE(l) do { \ for( ;; ) \ { \ - if( !InterlockedExchange( (LONG *)(l), 1 ) ) \ + if( !InterlockedExchange( (l), 1 ) ) \ break; \ - if( !InterlockedExchange( (LONG *)(l), 1 ) ) \ + if( !InterlockedExchange( (l), 1 ) ) \ break; \ Sleep( 0 ); \ } \ @@ -411,6 +413,37 @@ HB_EXTERN_BEGIN # define HB_SPINLOCK_RELEASE(l) OSSpinLockUnlock(l) # endif +#elif defined( HB_OS_SUNOS ) + + /* Atomic operations on memory reference counters */ +# if !defined( HB_ATOM_INC ) || !defined( HB_ATOM_DEC ) +# undef HB_ATOM_DEC +# undef HB_ATOM_INC +# undef HB_ATOM_GET +# undef HB_ATOM_SET +# define HB_ATOM_INC( p ) atomic_inc_ulong((ulong_t *)(p)) +# define HB_ATOM_DEC( p ) atomic_dec_ulong_nv((ulong_t *)(p)) +# define HB_ATOM_GET( p ) (*(ulong_t volatile *)(p)) +# define HB_ATOM_SET( p, n ) do { *((ulong_t volatile *)(p)) = (n); } while(0) +# endif + + /* Spin locks */ +# if !defined( HB_SPINLOCK_T ) +# define HB_SPINLOCK_T volatile uint_t +# define HB_SPINLOCK_INIT 0 +# define HB_SPINLOCK_ACQUIRE(l) do { \ + for( ;; ) \ + { \ + if( !atomic_swap_uint( (l), 1 ) ) \ + break; \ + if( !atomic_swap_uint( (l), 1 ) ) \ + break; \ + thr_yield(); \ + } \ + } while(0) +# define HB_SPINLOCK_RELEASE(l) do { *(l) = 0; } while(0) +# endif + #endif /* HB_OS_??? */ HB_EXTERN_END diff --git a/harbour/source/vm/dynlibhb.c b/harbour/source/vm/dynlibhb.c index fce8e81539..57e21df0ce 100644 --- a/harbour/source/vm/dynlibhb.c +++ b/harbour/source/vm/dynlibhb.c @@ -64,7 +64,13 @@ #include "hbstack.h" #include "hbvm.h" -#if defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) && !defined( __SUNPRO_C ) && !defined( __SUNPRO_CC ) +#if !defined( HB_HAS_DLFCN ) && \ + ( ( defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) ) || \ + defined( HB_OS_SUNOS ) ) +# define HB_HAS_DLFCN +#endif + +#if defined( HB_HAS_DLFCN ) # include #endif @@ -104,7 +110,7 @@ HB_FUNC( HB_LIBLOAD ) ( PCSZ ) hb_parc( 1 ), &hDynModule ) == NO_ERROR ) hDynLib = ( void * ) hDynModule; } -#elif defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) && !defined( __SUNPRO_C ) && !defined( __SUNPRO_CC ) +#elif defined( HB_HAS_DLFCN ) hDynLib = ( void * ) dlopen( hb_parc( 1 ), RTLD_LAZY | RTLD_GLOBAL ); #endif /* set real marker */ @@ -144,7 +150,7 @@ HB_FUNC( HB_LIBFREE ) fResult = FreeLibrary( ( HMODULE ) hDynLib ); #elif defined( HB_OS_OS2 ) fResult = DosFreeModule( ( HMODULE ) hDynLib ) == NO_ERROR; -#elif defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) && !defined( __SUNPRO_C ) && !defined( __SUNPRO_CC ) +#elif defined( HB_HAS_DLFCN ) fResult = dlclose( hDynLib ) == 0; #endif } @@ -155,7 +161,7 @@ HB_FUNC( HB_LIBFREE ) HB_FUNC( HB_LIBERROR ) { -#if defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) && !defined( __SUNPRO_C ) && !defined( __SUNPRO_CC ) +#if defined( HB_HAS_DLFCN ) hb_retc( dlerror() ); #else hb_retc_null();