From 04c7d04111d06483d0f91b93235d94d022e5251e Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Sat, 19 Dec 2009 15:53:07 +0000 Subject: [PATCH] 2009-12-19 16:52 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/vm/thread.c * added hb_threadOnceInit() to .prg function list * harbour/include/hbinit.h * use HB_STATIC_STARTUP as default initialization method of all C++ compilers --- harbour/ChangeLog | 8 ++ harbour/include/hbinit.h | 153 ++++++++++++++++----------------------- harbour/src/vm/thread.c | 1 + 3 files changed, 70 insertions(+), 92 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index dde88b5cd3..5b147408e6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,14 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-19 16:52 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/src/vm/thread.c + * added hb_threadOnceInit() to .prg function list + + * harbour/include/hbinit.h + * use HB_STATIC_STARTUP as default initialization method of all + C++ compilers + 2009-12-19 15:18 UTC+0500 April White (april users.sourceforge.net) * contrib/hbbtree/hb_btree.c * add a union field to encapsulate a var and a pointer, to diff --git a/harbour/include/hbinit.h b/harbour/include/hbinit.h index 7fc7bc35bd..f5cff6b306 100644 --- a/harbour/include/hbinit.h +++ b/harbour/include/hbinit.h @@ -59,39 +59,15 @@ HB_EXTERN_BEGIN extern HB_EXPORT PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, USHORT uiSymbols, const char * szModuleName, ULONG ulID, USHORT uiPcodeVer ); /* module symbols initialization with extended information */ -#if defined( _MSC_VER ) && \ - !defined( __LCC__ ) && !defined( __POCC__ ) && !defined( __XCC__ ) - - #if !defined( __cplusplus ) - - /* we do not have better startup initialization method for pure - * C mode in MSC - */ - #define HB_MSC_STARTUP - - #elif !defined( HB_STRICT_ANSI_C ) && !defined( HB_STATIC_STARTUP ) && \ - !defined( HB_PRAGMA_STARTUP ) && !defined( HB_MSC_STARTUP ) - - /* Sat 07 Maj 2005 02:46:38 CEST - * This is only necessary when you want to create binary libs using - * MSC in C++ mode (-TP switch) and later this binaries will be linked - * by standard C linker with [x]Harbour programs. I strongly suggest - * to for 3-rd party developers to use MSC in standard C mode to create - * libraries which can be used with standard C compilers. This will - * eliminate the problem and we will be able to set C++ initialization - * as default for MSC in C++ mode. Druzus. - */ - /* Fri Mar 06 2009 16:43:26 CET - * disabled after nearly four years given for 3-rd party developers - */ - /* #define HB_MSC_STARTUP */ - - #endif - -#endif - #define HB_INIT_SYMBOLS_END( func ) HB_INIT_SYMBOLS_EX_END( func, __FILE__, 0L, 0x0000 ) +/* By default in all C++ builds use static vars initialization as startup code */ +#if defined( __cplusplus ) && !defined( HB_STATIC_STARTUP ) && \ + !defined( HB_PRAGMA_STARTUP ) && !defined( HB_GNUC_STARTUP ) && \ + !defined( HB_INITSEG_STARTUP ) && !defined( HB_DATASEG_STARTUP ) + #define HB_STATIC_STARTUP +#endif + #if defined( HB_STRICT_ANSI_C ) #define HB_INIT_SYMBOLS_BEGIN( func ) \ @@ -112,6 +88,33 @@ extern HB_EXPORT PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, USHORT uiSymbo #define HB_CALL_ON_STARTUP_END( func ) \ } +#elif defined( HB_STATIC_STARTUP ) + + #if defined( HB_PRAGMA_STARTUP ) || defined( HB_DATASEG_STARTUP ) + #error Wrong macros set for startup code - clean your make/env settings. + #endif + + #define HB_INIT_SYMBOLS_BEGIN( func ) \ + static HB_SYMB symbols_table[] = { + + #define HB_INIT_SYMBOLS_EX_END( func, module, id, vpcode ) \ + }; \ + static PHB_SYMB symbols = hb_vmProcessSymbols( symbols_table, (USHORT) ( sizeof( symbols_table ) / sizeof( HB_SYMB ) ), (module), (id), (vpcode) ); \ + + #define HB_CALL_ON_STARTUP_BEGIN( func ) \ + static int func( void ) \ + { + + /* this allows any macros to be preprocessed first + so that token pasting is handled correctly */ + #define HB_CALL_ON_STARTUP_END( func ) \ + _HB_CALL_ON_STARTUP_END( func ) + + #define _HB_CALL_ON_STARTUP_END( func ) \ + return 0; \ + } \ + static int static_int_##func = func(); + #elif defined( HB_INITSEG_STARTUP ) #if defined( HB_PRAGMA_STARTUP ) || defined( HB_DATASEG_STARTUP ) @@ -147,8 +150,8 @@ extern HB_EXPORT PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, USHORT uiSymbo return ( void * ) func; \ } -#elif ( defined( __GNUC__ ) || defined( __SUNPRO_C ) || defined( __SUNPRO_CC ) ) && \ - !defined( HB_STATIC_STARTUP ) +#elif defined( HB_GNUC_STARTUP ) || \ + defined( __GNUC__ ) || defined( __SUNPRO_C ) || defined( __SUNPRO_CC ) #if defined( HB_PRAGMA_STARTUP ) || defined( HB_DATASEG_STARTUP ) #error Wrong macros set for startup code - clean your make/env settings. @@ -172,12 +175,34 @@ extern HB_EXPORT PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, USHORT uiSymbo #define HB_CALL_ON_STARTUP_END( func ) \ } -#elif defined( HB_MSC_STARTUP ) +#elif defined( HB_PRAGMA_STARTUP ) || \ + defined( __BORLANDC__ ) || defined( __LCC__ ) || \ + defined( __POCC__ ) || defined( __XCC__ ) - #if defined( HB_PRAGMA_STARTUP ) - #error Wrong macros set for startup code - clean your make/env settings. + #if !defined( HB_PRAGMA_STARTUP ) + #define HB_PRAGMA_STARTUP #endif + #define HB_INIT_SYMBOLS_BEGIN( func ) \ + static HB_SYMB symbols_table[] = { + + #define HB_INIT_SYMBOLS_EX_END( func, module, id, vpcode ) \ + }; \ + static PHB_SYMB symbols = symbols_table; \ + static void func( void ) \ + { \ + symbols = hb_vmProcessSymbols( symbols_table, (USHORT) ( sizeof( symbols_table ) / sizeof( HB_SYMB ) ), (module), (id), (vpcode) ); \ + } + + #define HB_CALL_ON_STARTUP_BEGIN( func ) \ + static void func( void ) \ + { + + #define HB_CALL_ON_STARTUP_END( func ) \ + } + +#elif defined( _MSC_VER ) + #define HB_DATASEG_STARTUP #if _MSC_VER >= 1010 @@ -216,62 +241,6 @@ extern HB_EXPORT PHB_SYMB hb_vmProcessSymbols( PHB_SYMB pSymbols, USHORT uiSymbo * See the C output of a generated prg for example */ -#elif defined( HB_STATIC_STARTUP ) || defined( __cplusplus ) - - #if defined( HB_PRAGMA_STARTUP ) || defined( HB_DATASEG_STARTUP ) - #error Wrong macros set for startup code - clean your make/env settings. - #endif - - #define HB_INIT_SYMBOLS_BEGIN( func ) \ - static HB_SYMB symbols_table[] = { - - #define HB_INIT_SYMBOLS_EX_END( func, module, id, vpcode ) \ - }; \ - static PHB_SYMB symbols = hb_vmProcessSymbols( symbols_table, (USHORT) ( sizeof( symbols_table ) / sizeof( HB_SYMB ) ), (module), (id), (vpcode) ); \ - - #define HB_CALL_ON_STARTUP_BEGIN( func ) \ - static int func( void ) \ - { - - /* this allows any macros to be preprocessed first - so that token pasting is handled correctly */ - #define HB_CALL_ON_STARTUP_END( func ) \ - _HB_CALL_ON_STARTUP_END( func ) - - #define _HB_CALL_ON_STARTUP_END( func ) \ - return 0; \ - } \ - static int static_int_##func = func(); - -#elif defined( HB_PRAGMA_STARTUP ) || \ - defined( __BORLANDC__ ) || defined( __LCC__ ) || defined( __POCC__ ) || defined( __XCC__ ) - - #if defined( HB_DATASEG_STARTUP ) - #error Wrong macros set for startup code - clean your make/env settings. - #endif - - #if !defined( HB_PRAGMA_STARTUP ) - #define HB_PRAGMA_STARTUP - #endif - - #define HB_INIT_SYMBOLS_BEGIN( func ) \ - static HB_SYMB symbols_table[] = { - - #define HB_INIT_SYMBOLS_EX_END( func, module, id, vpcode ) \ - }; \ - static PHB_SYMB symbols = symbols_table; \ - static void func( void ) \ - { \ - symbols = hb_vmProcessSymbols( symbols_table, (USHORT) ( sizeof( symbols_table ) / sizeof( HB_SYMB ) ), (module), (id), (vpcode) ); \ - } - - #define HB_CALL_ON_STARTUP_BEGIN( func ) \ - static void func( void ) \ - { - - #define HB_CALL_ON_STARTUP_END( func ) \ - } - #elif defined( __WATCOMC__ ) #if defined( HB_PRAGMA_STARTUP ) diff --git a/harbour/src/vm/thread.c b/harbour/src/vm/thread.c index e13ce7c5f6..167b408cbc 100644 --- a/harbour/src/vm/thread.c +++ b/harbour/src/vm/thread.c @@ -63,6 +63,7 @@ hb_threadWaitForAll() -> NIL hb_threadWait( | , [ ] [, ] ) => | | 0 hb_threadOnce( @ [, ] ) -> + hb_threadOnceInit( @ ) -> hb_mutexCreate() -> hb_mutexLock( [, ] ) -> hb_mutexUnlock( ) ->