Files
harbour-core/harbour/include/hbthread.h
Przemyslaw Czerpak fa31aa6f70 2008-12-11 19:48 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbthread.h
  * harbour/source/vm/thread.c
    + added hb_atomic_set(), hb_atomic_get(), hb_atomic_inc() and
      hb_atomic_dec() functions which operates on HB_COUNTER or smaller
      type if it's necessary for some platforms which can be access/assign
      increment/decrement in MT safe atom operations.
      hb_atomic_dec() returns true if counter is 0 after decrementation

  * harbour/include/hbatomic.h
    ! fixed compilation in Linux and OpenWatcom

  * harbour/include/hbapiitm.h
  * harbour/source/rtl/itemseri.c
    + make hb_itemSerialize() and hb_itemDeserialize() public functions
    ! fixed serialization items with internal item references

  * harbour/source/vm/hvm.c
    * release memvars after closing RDDs

  * harbour/source/debug/dbgentry.c
    ! fixed buffer overflow reported by Rodrigo

  * harbour/source/vm/macro.c
  * harbour/source/compiler/hbmain.c
    * formatting

  * harbour/include/hbexprb.c
    ! fixed wrongly recognized functions with HB_I18N_ prefix as
      HB_I18N_GETTEXT()

  * harbour/include/hbapi.h
  * harbour/include/hbstack.h
  * harbour/include/hbthread.h
  * harbour/source/vm/estack.c
  * harbour/source/vm/thread.c
  * harbour/source/vm/hvm.c
    + added support for I18N in HVM.
      Each thread can have it's own i18n set.
      When new thread is created then it inherits i18n set from parent
      thread and both uses the same set (please remember about it if you
      will want to make some direct modifications on active i18n set
      internals).
      When thread change active i18n set then it effects only this thread
      and new threads which will be create later. It does not change i18n
      in other existing threads.
    + added functions to set/get pointer to active i18n set in HVM
         void * hb_vmI18N( void )
         void   hb_vmSetI18N( void * )

  * harbour/include/hbapi.h
  * harbour/source/rtl/hbi18n.c
    + added i18n module. Now only for internal Harbour usage without support
      for optional switching to alternative implementations.
      I'll add such functionality later when I will work on native gettext
      support.

      The following public .prg functions has been added:
         HB_I18N_GETTEXT[_STRICT]( <cMsgID> [, <cContext> ] )
               -> <cTranslatedMsgID> | <cMsgID>
         HB_I18N_NGETTEXT[_STRICT]( <nValue>, <cMsgID> | <acMsgID> ;
                                    [, <cContext> ] )
               -> <cTranslatedMsgID> | <cMsgID> | <acMsgID>[ <nIndex> ]
      This is minimal support necessary for .prg code which has to exists
      in each i18n module working with Harbour.

      The following functions had been added as public C API:
         PHB_ITEM hb_i18n_gettext( PHB_ITEM pMsgID, PHB_ITEM pContext )
         PHB_ITEM hb_i18n_ngettext( PHB_ITEM pNum,
                                    PHB_ITEM pMsgID, PHB_ITEM pContext )

      The following functions had been added as private HVM C API:
         void   hb_i18n_init( void )
         void   hb_i18n_exit( void )
         void   hb_i18n_release( void * cargo )
         void * hb_i18n_alloc( void * cargo )
      They have to be supported by alternative i18n modules

      The following functions has been added to manage Harbour i18n
      translations sets:

         HB_I18N_CREATE()
                  -> <pI18N>
            Creates new empty I18N translation set

         HB_I18N_CODEPAGE( [<pI18N>,] [<cNewCP>], [<lBase>], [<lTranslate>] )
                  -> <cOldCP>
            Gets or sets Harbour codepage used by translation set
            <pI18N> - I18N translation set,
                      if it's not given then currently active I18N set is used
            <cNewCP> - new CP ID. Must be linked with application
            <lBase> - when it's .T. then get/set base massages CP instead of
                      translated massages CP
            <lTranslate> - if it's .T. then translate base (<lBase>==.T.) or
                           final messages in I18N set from previous CP to
                           given one. Base messages translation in synced
                           with context ID translation.

         HB_I18N_PLURALFORM( [<pI18N>,] [<cNewForm>|<bNewForm>], [<lBase>] )
                  -> <cOldForm>|<bOldForm>
            Gets or sets plural form used for final or base messages
            <pI18N> - I18N translation set,
                      if it's not given then currently active I18N set is used
            <cNewForm> - language ID of plural form, f.e.: "EN", "PL", "LT".
                         Now only three above are supported. Please add rules
                         for other languages to source/rtl/hbi18n.c.
            <bNewForm> - codeblock used to calculate plural form indexes.
                         can be used instead of character representation but
                         it's not storred in serialized I18N set
            <lBase> - when it's .T. then get/set base massages plural form
                      instead of translated massages one.

         HB_I18N_DESCRIPTION( [<pI18N>,] [<cNewDescription>] )
                  -> <cOldDescription>
            Gets or sets translation set description. After serialization
            up to 32 bytes is stored in header which can be easy used to
            determinate type of translation file.
            <pI18N> - I18N translation set,
                      if it's not given then currently active I18N set is used
            <cNewDescription> - new description

         HB_I18N_ADDTEXT( <pI18N>, <cMsgID>, <cTrans> | <acTrans> [, <cContext> ] )
                  -> NIL
            Adds new message with translation to i18n translation set
            <pI18N> - I18N translation set
            <cMsgID> - original message
            <cTrans> - translated message
            <acTrans> - array with translated messages used for plural forms
            <cContext> - message context

         HB_I18N_SET( [ <pI18N> | NIL ] )
                  -> <lActive>
            Sets given I18N translation set as default one used by
            HB_I18N_[N]GETTEXT[_STRICT]() functions or remove translation
            set for calling thread when passed parameter is NIL
            <pI18N> - I18N translation set
            Returns logical value which is .T. when i18n set is active

         HB_I18N_SAVETABLE( [<pI18N>] )
                  -> <cTable>
            Returns I18N translation as string item which can be stored
            in file or database
            <pI18N> - I18N translation set, if it's not given then currently
                      active I18N set is used

         HB_I18N_RESTORETABLE( <cTable> )
                  -> <pI18N> | NIL
            Restores I18N translation set from strin item.
            <cTable> - I18N translation set in string representation
            On success it returns new <pI18N> set otherwise NIL if <cTable>
            is not valid item created by HB_I18N_SAVETABLE() or it's corrupted.

         HB_I18N_HEADERSIZE()
                  -> <nHeaderSize>
            Returns size of header used by i18n serialized version

         HB_I18N_CHEK( <cTable> | <cHeader> [, @<cDescription> ] )
                  -> <lValid>
            <cTable> - i18n translation set serialized by HB_I18N_SAVETABLE
            <cHeader> - header of i18n translation set
                        ( LEFT( <cTable>, HB_I18N_HEADERSIZE() )
            <cDescription> - optional parameter passed by reference where
                             will be sored i18n translation set description
                             extracted from valid header
            Returns logical value indicating if given table or header is
            valid serialized by HB_I18N_SAVETABLE() data. It does not
            decode the table though it validates size and control sums.

      These functions are optional and some future alternative implementations
      may not support all of them and/or may provide some other functions.

    + added unofficial .prg function __I18N_HASHTABLE() which allows to
      access hash table used by i18n translation set or create new translation
      set with given hash table. It's helper functions for developers which
      will work on Harbour i18n tools and should not be used by Harbour users.

      Unlike original gettext Harbour allows to use language with many
      plural forms as base one. In such case programmer should activate
      at application startup default i18n translation set with base plural
      form valid for base application language, f.e. by:
         pI18N := hb_i18n_create()
         hb_i18n_pluralForm( pI18N, <cLangID> | <bForm>, .t. )
         hb_i18n_set( pI18N )
      .prg code example:

         #xtranslate _( <x,...> ) => hb_i18n_gettext_strict( <x> )
         #xtranslate _N( <x,...> ) => hb_i18n_ngettext_strict( <x> )

         proc main()
            local pI18N, i

            pI18N := hb_i18n_create()
            hb_i18n_pluralForm( pI18N, "PL", .t. )
            hb_i18n_set( pI18N )

            for i := 0 to 30
               ? i, _N( i, {"grosz", "grosze", "groszy"} )
               if i > 0 .and. i % 10 == 0
                  wait
               endif
            next
         return

      In .pot files created during compilation by Harbour with -j option
      for above code we have the following entries for message with plural
      forms:
            msgid "grosz"
            msgid_plural "grosze"
            msgid_plural2 "groszy"
            msgstr[0] ""
      The msgid_plural2 (and others if language has more plural forms)
      is Harbour extension which is not gettext compatible.


      The above implementation is base version but should be fully functional.
      Now we will need functions to safe/read i18n files and tools to mange
      .pot files: merge them, edit translations, create final binary i18n
      translation sets. Because we are using gettext compatible .pot files
      then for some of such jobs we can use original gettext tools but we
      need at least function which will create translation set from one or
      more .pot files.
      We should also agree some default localization(s) for files containing
      translated data, their name convention and environment variable(s)
      to set default language. It's not strictly necessary and each user
      can have his own implementation but it would help in adding new
      translations by final users to any Harbour application which will
      respect them. We can use LANG envvar to extract preferred language
      and use the same path as executed application looking for files
      <appname>-<lang>.hil files though it may create some problems for
      OSes which support only 8.3 file names so we can also define that
      HB_I18N envvar has higher priority and points to expected translation
      file.

  * harbour/include/hbextern.ch
    - removed old __i18n_*() functions
    + added current i18n functions
2008-12-11 18:47:46 +00:00

384 lines
14 KiB
C

/*
* $Id$
*/
/*
* Harbour Project source code:
* header file with MT mode functions
*
* Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#ifndef HB_THREAD_H_
#define HB_THREAD_H_
#include "hbapi.h"
#include "hbset.h"
#if ( defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) ) || \
defined( HB_OS_DARWIN )
# include <pthread.h>
# define HB_PTHREAD_API
#elif defined( HB_OS_WIN_32 )
# include <windows.h>
# include <process.h>
#elif defined( HB_OS_OS2 )
# if defined( __WATCOMC__ )
# include <process.h>
# endif
#endif
HB_EXTERN_BEGIN
#if defined( HB_PTHREAD_API )
typedef HB_LONG HB_THREAD_NO;
typedef pthread_t HB_THREAD_ID;
typedef pthread_t HB_THREAD_HANDLE;
typedef pthread_mutex_t HB_RAWCRITICAL_T;
typedef pthread_cond_t HB_RAWCOND_T;
# define HB_THREAD_STARTFUNC( func ) void * func( void * Cargo )
# define HB_THREAD_END return NULL;
# define HB_THREAD_RAWEND return NULL;
# define HB_THREAD_SELF() pthread_self()
# define HB_THREAD_EQUAL( x, y ) pthread_equal( x, y )
# define HB_CRITICAL_INIT(v) pthread_mutex_init( &(v), NULL )
# define HB_CRITICAL_DESTROY(v) pthread_mutex_destroy( &(v) )
# define HB_CRITICAL_LOCK(v) pthread_mutex_lock( &(v) )
# define HB_CRITICAL_UNLOCK(v) pthread_mutex_unlock( &(v) )
# define HB_COND_INIT(v) pthread_cond_init( &(v), NULL )
# define HB_COND_DESTROY(v) pthread_cond_destroy( &(v) )
# define HB_COND_SIGNAL(v) pthread_cond_signal( &(v) )
# define HB_COND_SIGNALN(v,n) pthread_cond_broadcast( &(v) )
# define HB_COND_OS_SUPPORT /* OS support for conditional variables */
# if defined( PTHREAD_MUTEX_INITIALIZER ) && !defined( HB_CRITICAL_NEED_INIT )
typedef pthread_mutex_t HB_CRITICAL_T;
# define HB_CRITICAL_NEW( name ) HB_CRITICAL_T name = PTHREAD_MUTEX_INITIALIZER
# define HB_CRITICAL_GET(v) ( v )
# else
/* platform does not support static mutex initialization */
# if !defined( HB_CRITICAL_NEED_INIT )
# define HB_CRITICAL_NEED_INIT
# endif
# define HB_CRITICAL_GET(v) ( &( (v)->critical ) )
# define HB_CRITICAL_INITVAL { }
# endif
# if defined( PTHREAD_COND_INITIALIZER ) && !defined( HB_COND_NEED_INIT )
typedef pthread_cond_t HB_COND_T;
# define HB_COND_NEW( name ) HB_COND_T name = PTHREAD_COND_INITIALIZER
# define HB_COND_GET(v) ( v )
# else
/* platform does not support static condition var initialization */
# if !defined( HB_COND_NEED_INIT )
# define HB_COND_NEED_INIT
# endif
# define HB_COND_GET(v) ( &( (v)->cond ) )
# define HB_COND_INITVAL { }
# endif
#elif defined( HB_OS_WIN_32 ) && ! defined( HB_WINCE )
# define HB_MAX_THREAD 32768
typedef HB_LONG HB_THREAD_NO;
typedef unsigned HB_THREAD_ID;
typedef HANDLE HB_THREAD_HANDLE;
typedef CRITICAL_SECTION HB_RAWCRITICAL_T;
typedef HANDLE HB_RAWCOND_T;
# define HB_THREAD_STARTFUNC( func ) unsigned __stdcall func( void * Cargo )
# define HB_THREAD_END _endthreadex( 0 ); return 0;
# define HB_THREAD_RAWEND return 0;
# define HB_THREAD_SELF() GetCurrentThreadId()
# define HB_CRITICAL_INITVAL { 0, 0, 0, 0, 0, 0 }
# define HB_COND_INITVAL ( ( HANDLE ) NULL )
# define HB_CRITICAL_INIT(v) InitializeCriticalSection( &(v) )
# define HB_CRITICAL_DESTROY(v) DeleteCriticalSection( &(v) )
# define HB_CRITICAL_LOCK(v) EnterCriticalSection( &(v) )
# define HB_CRITICAL_UNLOCK(v) LeaveCriticalSection( &(v) )
# define HB_COND_INIT(v) do { (v) = CreateSemaphore( NULL, 0, HB_MAX_THREAD, NULL ); } while(0)
# define HB_COND_DESTROY(v) CloseHandle( v )
# define HB_COND_SIGNAL(v) ReleaseSemaphore( (v), 1, NULL )
# define HB_COND_SIGNALN(v,n) ReleaseSemaphore( (v), (n), NULL )
# define HB_COND_WAIT(v) ( WaitForSingleObject( (v), INFINITE ) != WAIT_FAILED )
# define HB_COND_TIMEDWAIT(v,n) ( WaitForSingleObject( (v), (n) ) != WAIT_FAILED )
# undef HB_COND_OS_SUPPORT
# define HB_CRITICAL_NEED_INIT
# define HB_COND_NEED_INIT
# define HB_THREAD_INFINITE_WAIT INFINITE
#elif defined( HB_OS_OS2 )
/* In OS2 thread ID is continuous integer number so we can use it directly
* anyhow I'd prefer to not make such strict binding to OS values because
* it make cause troubles when code will be ported to other platforms.
*/
/* typedef TID HB_THREAD_NO; */
typedef HB_LONG HB_THREAD_NO;
typedef TID HB_THREAD_ID;
typedef TID HB_THREAD_HANDLE;
typedef HMTX HB_RAWCRITICAL_T;
typedef HEV HB_RAWCOND_T;
extern ULONG _hb_gettid( void );
# define HB_THREAD_STARTFUNC( func ) void func( void * Cargo )
# define HB_THREAD_END _endthread(); return;
# define HB_THREAD_RAWEND return;
# define HB_CRITICAL_INITVAL ( ( HMTX ) 0 )
# define HB_COND_INITVAL ( ( HEV ) 0 )
# if defined( __GNUC__ )
# define HB_THREAD_SELF() ( ( TID ) _gettid() )
# else
# define HB_THREAD_SELF() ( ( TID ) _hb_gettid() )
# endif
# define HB_CRITICAL_INIT(v) DosCreateMutexSem( NULL, &(v), 0L, FALSE )
# define HB_CRITICAL_DESTROY(v) DosCloseMutexSem( v )
# define HB_CRITICAL_LOCK(v) DosRequestMutexSem( (v), SEM_INDEFINITE_WAIT )
# define HB_CRITICAL_UNLOCK(v) DosReleaseMutexSem( v )
# define HB_COND_INIT(v) DosCreateEventSem( NULL, &(v), 0L, FALSE );
# define HB_COND_DESTROY(v) DosCloseEventSem( v )
# define HB_COND_SIGNAL(v) DosPostEventSem( v )
# define HB_COND_SIGNALN(v,n) do { int i = (n); while( --i >= 0 ) DosPostEventSem( v ); } while(0)
# define HB_COND_WAIT(v) ( DosWaitEventSem( (v), SEM_INDEFINITE_WAIT ) == NO_ERROR )
# define HB_COND_TIMEDWAIT(v,n) ( DosWaitEventSem( (v), (n) ) == NO_ERROR )
# undef HB_COND_OS_SUPPORT
# define HB_CRITICAL_NEED_INIT
# define HB_COND_NEED_INIT
# define HB_THREAD_INFINITE_WAIT SEM_INDEFINITE_WAIT
#else
typedef int HB_THREAD_NO;
typedef int HB_THREAD_ID;
typedef int HB_THREAD_HANDLE;
typedef int HB_CRITICAL_T;
typedef int HB_RAWCRITICAL_T;
typedef int HB_COND_T;
typedef int HB_RAWCOND_T;
# define HB_THREAD_STARTFUNC( func ) void func( void * Cargo )
# define HB_THREAD_END return;
# define HB_THREAD_RAWEND return;
# define HB_CRITICAL_NEW( name ) HB_CRITICAL_T name = 0
# define HB_COND_NEW( name ) HB_COND_T name = 0
# define HB_THREAD_SELF() (-1)
# define HB_CRITICAL_LOCK(v)
# define HB_CRITICAL_UNLOCK(v)
# define HB_COND_SIGNAL(v)
# define HB_COND_SIGNALN(v,n)
# define HB_COND_WAIT(v) ( FALSE )
# define HB_COND_TIMEDWAIT(v,n) ( FALSE )
#endif
#ifdef HB_CRITICAL_NEED_INIT
typedef struct
{
BOOL fInit;
HB_RAWCRITICAL_T critical;
} HB_CRITICAL_T;
# define HB_CRITICAL_NEW( name ) HB_CRITICAL_T name = { FALSE, HB_CRITICAL_INITVAL }
#endif /* HB_CRITICAL_NEED_INIT */
#ifdef HB_COND_NEED_INIT
# if defined( HB_COND_OS_SUPPORT )
typedef struct
{
BOOL fInit;
HB_RAWCOND_T cond;
} HB_COND_T;
# define HB_COND_NEW( name ) HB_COND_T name = { FALSE, HB_COND_INITVAL }
# else
typedef struct
{
BOOL fInit;
int waiters;
HB_RAWCOND_T cond;
HB_RAWCRITICAL_T critical;
} HB_COND_T;
# define HB_COND_NEW( name ) HB_COND_T name = { FALSE, 0, HB_COND_INITVAL, HB_CRITICAL_INITVAL }
# endif
#endif /* HB_COND_NEED_INIT */
#ifndef HB_THREAD_EQUAL
# define HB_THREAD_EQUAL( x, y ) ( (x) == (y) )
#endif
#ifndef HB_THREAD_INFINITE_WAIT
# define HB_THREAD_INFINITE_WAIT ( ( ULONG ) -1 )
#endif
typedef HB_THREAD_STARTFUNC( PHB_THREAD_STARTFUNC );
typedef struct _HB_THREADSTATE
{
const char * pszCDP;
const char * pszLang;
const char * pszDefRDD;
PHB_SET_STRUCT pSet;
void * pI18N;
void * hGT;
void * pStackId;
BOOL fActive;
BOOL fFinished;
PHB_ITEM pParams;
PHB_ITEM pMemvars;
PHB_ITEM pResult;
PHB_ITEM pThItm;
HB_THREAD_NO th_no;
HB_THREAD_ID th_id;
HB_THREAD_HANDLE th_h;
struct _HB_THREADSTATE * pPrev;
struct _HB_THREADSTATE * pNext;
} HB_THREADSTATE, * PHB_THREADSTATE;
extern void hb_threadInit( void );
extern void hb_threadExit( void );
extern PHB_THREADSTATE hb_threadStateNew( void );
/* atomic oprtations */
void hb_atomic_set( volatile HB_COUNTER * pCounter, HB_COUNTER value );
HB_COUNTER hb_atomic_get( volatile HB_COUNTER * pCounter );
void hb_atomic_inc( volatile HB_COUNTER * pCounter );
BOOL hb_atomic_dec( volatile HB_COUNTER * pCounter ); /* returns TRUE when counter reach after decrementation */
/* Critical sections or fast non recursive MUTEXes */
extern void hb_threadEnterCriticalSection( HB_CRITICAL_T * critical );
extern void hb_threadLeaveCriticalSection( HB_CRITICAL_T * critical );
/* conditional variables */
extern BOOL hb_threadCondSignal( HB_COND_T * cond );
extern BOOL hb_threadCondBroadcast( HB_COND_T * cond );
extern BOOL hb_threadCondWait( HB_COND_T * cond, HB_CRITICAL_T * mutex );
extern BOOL hb_threadCondTimedWait( HB_COND_T * cond, HB_CRITICAL_T * mutex, ULONG ulMilliSec );
extern HB_THREAD_HANDLE hb_threadCreate( HB_THREAD_ID * th_id, PHB_THREAD_STARTFUNC start_func, void * Cargo );
extern BOOL hb_threadJoin( HB_THREAD_HANDLE th_h );
extern BOOL hb_threadDetach( HB_THREAD_HANDLE th_h );
/* used by .prg code */
extern PHB_ITEM hb_threadMutexCreate( BOOL fSync );
extern BOOL hb_threadMutexLock( PHB_ITEM pItem );
extern BOOL hb_threadMutexTimedLock( PHB_ITEM pItem, ULONG ulMilliSec );
extern BOOL hb_threadMutexUnlock( PHB_ITEM pItem );
extern void hb_threadMutexNotify( PHB_ITEM pItem, PHB_ITEM pNotifier, BOOL fWaiting );
extern PHB_ITEM hb_threadMutexSubscribe( PHB_ITEM pItem, BOOL fClear );
extern PHB_ITEM hb_threadMutexTimedSubscribe( PHB_ITEM pItem, ULONG ulMilliSec, BOOL fClear );
#if defined( HB_MT_VM ) && defined( _HB_API_INTERNAL_ )
extern void hb_threadMutexUnlockAll( void );
#if defined( HB_NO_TLS )
# undef HB_USE_TLS
#elif !defined( HB_USE_TLS )
/* enable native compiler TLS support be default for this compilers
* which are known that it will work correctly
*/
# if defined( _MSC_VER ) && !defined( __POCC__ ) && !defined( __XCC__ )
# define HB_USE_TLS
# elif defined( __GNUC__ ) && __GNUC__ >= 3 && \
defined( __GLIBC__ ) && defined( __GLIBC_MINOR__ ) && \
( __GLIBC__ > 2 || ( __GLIBC__ == 2 && __GLIBC_MINOR__ >= 6 ) ) && \
defined( HB_OS_LINUX ) && \
( defined( __i386__ ) || defined( __x86_64__ ) )
# define HB_USE_TLS
# endif
#endif
#ifdef HB_USE_TLS
# if ( defined( __GNUC__ ) && __GNUC__ >= 3 ) || defined( __BORLANDC__ )
# define HB_TLS_ATTR __thread
# elif defined( _MSC_VER ) || defined( __WATCOMC__ ) || defined( __DMC__ )
# define HB_TLS_ATTR __declspec( thread )
# else
# undef HB_USE_TLS
# error "TLS support undefined for this compiler" /* */
# endif
#endif
#ifndef HB_USE_TLS
# if defined( HB_PTHREAD_API )
# define HB_TLS_KEY pthread_key_t
# define hb_tls_init(k) pthread_key_create( &k, NULL )
# define hb_tls_set(k,v) pthread_setspecific( k, ( void * ) (v) )
# define hb_tls_get(k) pthread_getspecific( k )
# elif defined( HB_OS_WIN_32 )
# define HB_TLS_KEY DWORD
# define hb_tls_init(k) do { k = TlsAlloc(); } while( 0 )
# define hb_tls_set(k,v) TlsSetValue( k, ( void * ) (v) )
# define hb_tls_get(k) TlsGetValue( k )
# elif defined( HB_OS_OS2 )
# define HB_TLS_KEY PULONG
# define hb_tls_init(k) DosAllocThreadLocalMemory( 1, &k )
# define hb_tls_set(k,v) do { *k = ( ULONG ) (v); } while( 0 )
# define hb_tls_get(k) ( *k )
# endif
#endif
#endif
HB_EXTERN_END
#endif /* HB_THREAD_H_ */