[Przemek]
> ../../thread.c(1240): Error! E029: col(60) symbol '_gettid' has not been declared
>
> _gettid() is GCC local function.
> I do not see function which returns directly thread ID in OS2 API.
> Probably it can be extracted from TIB structure returned by
> DosGetInfoBlocks(). I cannot find simpler method. Maurilio can you help?
>

[Maurilio]
> I've not tested this code, but something like this should give you the thread id.
> unsigned long _gettid()
> {
>    PTIB   ptib = NULL;
>    APIRET rc;
>
>    rc = DosGetInfoBlocks(&ptib, NULL);
>
>    return ptib->tib_ptib2->tib2_ultid;
> }
> Hope this help.

[Przemek]
>Yes, thanks. I hoped that maybe there is simpler version then using
>DosGetInfoBlocks() but we can also use this. Thank you very much.

Przemek, Maurilio:

I do not know if it is what you are looking for
I found in different places of documentation included in OW
---------
The macro _threadid can be used to determine the current thread identifier.
---------

The _threadid macro can be used to determine the current thread identifier. It is defined as follows.


     int *__threadid(void);
     #define _threadid (__threadid())

The header file stddef.h contains the definition of the _threadid macro.
---------

_threadid
Prototype in <stddef.h>.

This variable/function may be used to obtain the id of the current thread which is an int. In the 32-bit libraries, _threadid is a function that returns a pointer to an int. In the 16-bit libraries, _threadid is a far pointer to an int. Note that the value stored where _threadid points does not necessarily change when a thread context switch occurs (so do not make a copy of the pointer ... it may change). To obtain the current thread identifier, simply code:

     int tid = *_threadid;
-------------


So I tried in source\vm\thread.c

---------------
#if defined( HB_OS_OS2 )

#include <stddef.h>       <---- David was here !

ULONG _hb_gettid( void )
{
   ULONG tid = 0;
   PTIB  ptib = NULL;

   printf( "_hb_gettid()\r\n", tid ); fflush(stdout);
/*       <---- David was here !
   if( DosGetInfoBlocks( &ptib, NULL ) == NO_ERROR )
   {
      if( ! ptib )
         { printf( "ptib is NULL\r\n" ); fflush(stdout); }
      else if( !ptib->tib_ptib2 )
         { printf( "ptib->tib_ptib2 is NULL\r\n" ); fflush(stdout); }
      else
         tid = ptib->tib_ptib2->tib2_ultid;
   }
*/

   tid = *_threadid;         <---- David was here !

   printf( "TID=%lu\r\n", tid ); fflush(stdout);

   return tid;
}
#endif
---------------

and mttest02.exe result with values TID=1, 2
---------------
[...]
_hb_gettid()
TID=1
1. hb_threadMutexLock()
_hb_gettid()
TID=2
[...]
---------------

So if _threadid is useful giving same value as GCC _gettid(), then _hb_gettid() can be discarded and use in harbour\include\hbthread.h:

-----------
//discard
   extern ULONG _hb_gettid( void );

#  if defined( __GNUC__ )
#     define HB_THREAD_SELF()    ( ( TID ) _gettid() )

#  else

// case for OpenWatcom
//   Use something like
  #include <stddef.h>       <---- David was here !
   tid = *_threadid;         <---- David was here !

int vs ULONG ?
In the 32-bit libraries, _threadid is a function that returns a pointer to an int

#  else

//discard
#     define HB_THREAD_SELF()    ( ( TID ) _hb_gettid() )
#  endif
-----------


And in this case ( thread ID ) what is happening/using in Windows OpenWatcom ? It can be used in OS/2 Watcom ?

David Macias


_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to