34 #ifndef PTLIB_THREAD_H
35 #define PTLIB_THREAD_H
316 virtual void Main() = 0;
348 PINDEX stackSize = 65536
387 { traceBlockIndentLevel = 0; }
391 unsigned traceBlockIndentLevel;
394 #ifndef P_HAS_THREADLOCAL_STORAGE
398 #endif // P_HAS_THREADLOCAL_STORAGE
403 #include "msos/ptlib/thread.h"
405 #include "unix/ptlib/thread.h"
410 #if defined(_WIN32) && !defined(_WIN32_WCE)
411 #define PTHREAD_ID_FMT "%u"
413 #define PTHREAD_ID_FMT "0x%lx"
417 #pragma warning(disable:4355)
469 template<
typename Arg1Type>
488 { (*m_function)(
m_arg1); }
508 template<
typename Arg1Type,
typename Arg2Type>
513 typedef void (*
FnType)(Arg1Type arg1, Arg2Type arg2);
520 PThread2Arg(
const char * file,
int line, Arg1Type arg1, Arg2Type arg2,
FnType function,
bool autoDel =
false)
548 template<
typename Arg1Type,
typename Arg2Type,
typename Arg3Type>
553 typedef void (*
FnType)(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3);
561 PThread3Arg(
const char * file,
int line, Arg1Type arg1, Arg2Type arg2, Arg3Type arg3,
FnType function,
bool autoDel =
false)
595 template <
typename ObjType>
605 bool autoDel =
false,
606 const char * name = NULL,
645 template <
class ObjType,
typename Arg1Type>
656 bool autoDel =
false,
657 const char * name = NULL,
681 template <
class ObjType,
typename Arg1Type,
typename Arg2Type>
693 bool autoDel =
false,
694 const char * name = NULL,
728 #define P_HAS_THREADLOCAL_STORAGE 1
730 template <
class Storage_T>
731 class PThreadLocalStorage
735 typedef Storage_T value_type;
737 PThreadLocalStorage()
738 { key = TlsAlloc(); }
740 ~PThreadLocalStorage()
747 {
return (value_type *) TlsGetValue(key); }
749 void Set(value_type * v)
750 { TlsSetValue(key, (LPVOID)v); }
756 #elif defined(P_PTHREADS)
760 #define P_HAS_THREADLOCAL_STORAGE 1
762 template <
class Storage_T>
763 class PThreadLocalStorage
766 typedef pthread_key_t Key_T;
767 typedef Storage_T value_type;
769 PThreadLocalStorage()
770 { pthread_key_create(&key, NULL); }
772 ~PThreadLocalStorage()
773 { pthread_key_delete(key); }
779 {
return (value_type *)pthread_getspecific(key); }
781 void Set(value_type * v)
782 { pthread_setspecific(key, v); }
790 #undef P_HAS_THREADLOCAL_STORAGE 1
791 #warning("Thread local storage not supported");
797 #pragma warning(default:4355)
800 #endif // PTLIB_THREAD_H