PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
thread.h
Go to the documentation of this file.
1 /*
2  * thread.h
3  *
4  * Executable thread encapsulation class (pre-emptive if OS allows).
5  *
6  * Portable Tools Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  */
29 
30 #ifndef PTLIB_THREAD_H
31 #define PTLIB_THREAD_H
32 
33 #ifdef P_USE_PRAGMA
34 #pragma interface
35 #endif
36 
37 #ifdef Priority
38 #undef Priority
39 #endif
40 
41 #include <ptlib/mutex.h>
42 #include <ptlib/notifier.h>
43 #include <set>
44 
45 
46 class PSemaphore;
47 class PSyncPoint;
48 
49 
51 // PThread
52 
66 class PThread : public PObject, PProfiling::HighWaterMark<PThread>
67 {
68  PCLASSINFO(PThread, PObject);
69 
70  public:
73  P_DECLARE_TRACED_ENUM(Priority,
75  LowestPriority,
76  LowPriority,
77  NormalPriority,
78  HighPriority,
79  HighestPriority
80  );
81 
86 
89  };
90 
112  PThread(
113  PINDEX stack,
114  AutoDeleteFlag deletion = AutoDeleteThread,
116  Priority priorityLevel = NormalPriority,
117  const PString & threadName = PString::Empty()
118  );
119 
127  ~PThread();
129 
136  void PrintOn(
137  ostream & strm
138  ) const;
140 
148  virtual void Restart();
149 
161  virtual void Terminate();
162 
168  virtual PBoolean IsTerminated() const;
169 
172  void WaitForTermination() const;
173 
180  const PTimeInterval & maxWait
181  ) const;
182 
197  static bool WaitAndDelete(
198  PThread * & thread,
199  const PTimeInterval & maxWait = 10000,
200  PMutex * mutex = NULL,
201  bool lock = true
202  );
203 
216  virtual void Suspend(
217  PBoolean susp = true
218  );
219 
239  virtual void Resume();
240 
248  virtual PBoolean IsSuspended() const;
249 
251  static void Sleep(
252  const PTimeInterval & delay
253  );
254 
258  virtual void SetPriority(
259  Priority priorityLevel
260  );
261 
267  virtual Priority GetPriority() const;
268 
272  virtual void SetAutoDelete(
273  AutoDeleteFlag deletion = AutoDeleteThread
274  );
275 
280 
286  virtual PString GetThreadName() const;
287 
293  static PString GetThreadName(PThreadIdentifier id);
294 
297  static PString GetCurrentThreadName() { return GetThreadName(GetCurrentThreadId()); }
298 
303  static PString GetIdentifiersAsString(PThreadIdentifier tid, PUniqueThreadIdentifier uid);
304 
310  virtual void SetThreadName(
311  const PString & name
312  );
314 
320  PThreadIdentifier GetThreadId() const
321  );
322 
326  static PThreadIdentifier GetCurrentThreadId()
327  );
328 
335  PUniqueThreadIdentifier GetUniqueIdentifier() const
336  );
337 
341  static PUniqueThreadIdentifier GetCurrentUniqueIdentifier()
342  );
343 
347  static PINDEX GetTotalCount()
348  );
349 
351  struct Times
352  {
354  Times()
355  );
357  friend ostream & operator<<(ostream & strm, const Times & times)
358  );
360  float AsPercentage() const
361  );
363  Times operator-(const Times & rhs) const
364  );
366  Times & operator-=(const Times & rhs)
367  );
369  bool operator<(const Times & rhs) const { return m_uniqueId < rhs.m_uniqueId; }
370  );
371 
373  PThreadIdentifier m_threadId;
374  PUniqueThreadIdentifier m_uniqueId;
379  };
380 
384  bool GetTimes(
385  Times & times
386  ));
387 
391  static bool GetTimes(
392  PThreadIdentifier id,
393  Times & times
394  ));
395 
399  static void GetTimes(
400  std::vector<Times> & times
401  ));
402  static void GetTimes(
403  std::list<Times> & times
404  );
405  static void GetTimes(
406  std::set<Times> & times
407  );
408 
422  static int GetPercentageCPU(
423  Times & previousTimes,
424  const PTimeInterval & period = PTimeInterval(0,1),
425  PThreadIdentifier id = PNullThreadIdentifier
426  );
427 
430  static unsigned GetNumProcessors();
431 
439  virtual void Main() = 0;
440 
450  static PThread * Current();
451 
458  static void Yield();
459 
464  static PThread * Create(
465  const PNotifier & notifier,
466  INT parameter = 0,
467  AutoDeleteFlag deletion = AutoDeleteThread,
469  Priority priorityLevel = NormalPriority,
470  const PString & threadName = PString::Empty(),
471  PINDEX stackSize = 0
472  );
473  static PThread * Create(
474  const PNotifier & notifier,
475  const PString & threadName
476  ) { return Create(notifier, 0, NoAutoDeleteThread, NormalPriority, threadName); }
478 
479  bool IsAutoDelete() const { return m_type == e_IsAutoDelete; }
480 
483  {
484  public:
485  virtual ~LocalStorageBase() { }
486  void ThreadDestroyed(PThread & thread);
487  protected:
489  void DestroyStorage();
490  virtual void * Allocate() const = 0;
491  virtual void Deallocate(void * ptr) const = 0;
492  virtual void * GetStorage() const;
493  private:
494  typedef std::map<PUniqueThreadIdentifier, void *> DataMap;
495  mutable DataMap m_data;
496  PCriticalSection m_mutex;
498  };
499 
500  private:
501  PThread(bool isProcess);
502  // Create a new thread instance as part of a <code>PProcess</code> class.
503 
504  void InternalThreadMain();
505  void InternalPreMain();
506  void InternalPostMain();
507  void InternalDestroy();
508 
509  friend class PProcess;
510  friend class PExternalThread;
511  // So a PProcess can get at PThread() constructor but nothing else.
512 
513  PThread(const PThread &)
514  : PObject ()
515  , m_type()
517  , m_threadId()
518  , m_uniqueId()
519 #ifdef _WIN32
520  , m_comInitialised()
521 #endif
522  { }
523  // Empty constructor to prevent copying of thread instances.
524 
525  PThread & operator=(const PThread &) { return *this; }
526  // Empty assignment operator to prevent copying of thread instances.
527 
528  protected:
530 
532 
533  PString m_threadName; // Give the thread a name for debugging purposes.
535 
536  PThreadIdentifier m_threadId;
537  PUniqueThreadIdentifier m_uniqueId;
538 
539 // Include platform dependent part of class
540 #ifdef _WIN32
541 #include "msos/ptlib/thread.h"
542 #else
543 #include "unix/ptlib/thread.h"
544 #endif
545 };
546 
547 
552 /*
553  This class automates calling a global function with no arguments within it's own thread.
554  It is used as follows:
555 
556  void GlobalFunction()
557  {
558  }
559 
560  ...
561  PString arg;
562  new PThreadMain(&GlobalFunction)
563  */
564 class PThreadMain : public PThread
565 {
566  PCLASSINFO(PThreadMain, PThread);
567  public:
568  typedef void (*FnType)();
569  PThreadMain(FnType function, bool autoDel = false)
571  , m_function(function)
572  {
573  PThread::Resume();
574  }
575 
577  {
579  }
580 
581  virtual void Main()
582  {
583  (*m_function)();
584  }
585 
586  protected:
588 };
589 
590 
591 /*
592  This template automates calling a global function using a functor
593  It is used as follows:
594 
595  struct Functor {
596  void operator()(PThread & thread) { ... code in here }
597  }
598 
599  ...
600  Functor arg;
601  new PThreadFunctor<Functor>(arg)
602  */
603 template<typename Functor>
604 class PThreadFunctor : public PThread
605 {
606  PCLASSINFO(PThreadFunctor, PThread);
607  public:
609  Functor & funct,
610  bool autoDel = false,
611  const char * name = NULL,
612  PThread::Priority priority = PThread::NormalPriority
613  )
614  : PThread(10000, autoDel ? PThread::AutoDeleteThread : PThread::NoAutoDeleteThread, priority, name)
615  , m_funct(funct)
616  {
617  PThread::Resume();
618  }
619 
621  {
623  }
624 
625  virtual void Main()
626  {
627  m_funct(*this);
628  }
629 
630  protected:
631  Functor & m_funct;
632 };
633 
634 
635 /*
636  This template automates calling a global function with one argument within it's own thread.
637  It is used as follows:
638 
639  void GlobalFunction(PString arg)
640  {
641  }
642 
643  ...
644  PString arg;
645  new PThread1Arg<PString>(arg, &GlobalFunction)
646  */
647 template<typename Arg1Type>
648 class PThread1Arg : public PThread
649 {
650  PCLASSINFO(PThread1Arg, PThread);
651  public:
652  typedef void (*FnType)(Arg1Type arg1);
653 
655  Arg1Type arg1,
656  FnType function,
657  bool autoDel = false,
658  const char * name = NULL,
659  PThread::Priority priority = PThread::NormalPriority
660  ) : PThread(10000, autoDel ? PThread::AutoDeleteThread : PThread::NoAutoDeleteThread, priority, name)
661  , m_function(function)
662  , m_arg1(arg1)
663  {
664  PThread::Resume();
665  }
666 
668  {
670  }
671 
672  virtual void Main()
673  {
674  (*m_function)(m_arg1);
675  }
676 
677  protected:
679  Arg1Type m_arg1;
680 };
681 
682 
683 /*
684  This template automates calling a global function with two arguments within it's own thread.
685  It is used as follows:
686 
687  void GlobalFunction(PString arg1, int arg2)
688  {
689  }
690 
691  ...
692  PString arg;
693  new PThread2Arg<PString, int>(arg1, arg2, &GlobalFunction)
694  */
695 template<typename Arg1Type, typename Arg2Type>
696 class PThread2Arg : public PThread
697 {
698  PCLASSINFO(PThread2Arg, PThread);
699  public:
700  typedef void (*FnType)(Arg1Type arg1, Arg2Type arg2);
702  Arg1Type arg1,
703  Arg2Type arg2,
704  FnType function,
705  bool autoDel = false,
706  const char * name = NULL,
707  PThread::Priority priority = PThread::NormalPriority
708  ) : PThread(10000, autoDel ? PThread::AutoDeleteThread : PThread::NoAutoDeleteThread, priority, name)
709  , m_function(function)
710  , m_arg1(arg1)
711  , m_arg2(arg2)
712  {
713  PThread::Resume();
714  }
715 
717  {
719  }
720 
721  virtual void Main()
722  {
723  (*m_function)(m_arg1, m_arg2);
724  }
725 
726  protected:
728  Arg1Type m_arg1;
729  Arg2Type m_arg2;
730 };
731 
732 /*
733  This template automates calling a global function with three arguments within it's own thread.
734  It is used as follows:
735 
736  void GlobalFunction(PString arg1, int arg2, int arg3)
737  {
738  }
739 
740  ...
741  PString arg;
742  new PThread3Arg<PString, int, int>(arg1, arg2, arg3, &GlobalFunction)
743  */
744 template<typename Arg1Type, typename Arg2Type, typename Arg3Type>
745 class PThread3Arg : public PThread
746 {
747  PCLASSINFO(PThread3Arg, PThread);
748  public:
749  typedef void (*FnType)(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3);
751  Arg1Type arg1,
752  Arg2Type arg2,
753  Arg3Type arg3,
754  FnType function,
755  bool autoDel = false,
756  const char * name = NULL,
757  PThread::Priority priority = PThread::NormalPriority
758  ) : PThread(10000, autoDel ? PThread::AutoDeleteThread : PThread::NoAutoDeleteThread, priority, name)
759  , m_function(function)
760  , m_arg1(arg1)
761  , m_arg2(arg2)
762  , m_arg3(arg3)
763  {
764  PThread::Resume();
765  }
766 
768  {
770  }
771 
772  virtual void Main()
773  {
774  (*m_function)(m_arg1, m_arg2, m_arg3);
775  }
776 
777  protected:
779  Arg1Type m_arg1;
780  Arg2Type m_arg2;
781  Arg3Type m_arg3;
782 };
783 
784 /*
785  This template automates calling a member function with no arguments within it's own thread.
786  It is used as follows:
787 
788  class Example {
789  public:
790  void Function()
791  {
792  }
793  };
794 
795  ...
796  Example ex;
797  new PThreadObj<Example>(ex, &Example::Function)
798  */
799 
800 template <typename ObjType>
801 class PThreadObj : public PThread
802 {
803  PCLASSINFO_ALIGNED(PThreadObj, PThread, 16);
804  public:
805  typedef void (ObjType::*ObjTypeFn)();
806 
808  ObjType & obj,
809  ObjTypeFn function,
810  bool autoDel = false,
811  const char * name = NULL,
812  PThread::Priority priority = PThread::NormalPriority
813  ) : PThread(10000,
815  priority,
816  name)
817  , m_object(obj)
818  , m_function(function)
819  {
820  PThread::Resume();
821  }
822 
824  {
826  }
827 
828  void Main()
829  {
830  (m_object.*m_function)();
831  }
832 
833  protected:
834  ObjType & m_object;
835  P_ALIGN_FIELD(ObjTypeFn,m_function,16);
836 };
837 
838 
839 /*
840  This template automates calling a member function with one argument within it's own thread.
841  It is used as follows:
842 
843  class Example {
844  public:
845  void Function(PString arg)
846  {
847  }
848  };
849 
850  ...
851  Example ex;
852  PString str;
853  new PThreadObj1Arg<Example>(ex, str, &Example::Function)
854  */
855 template <class ObjType, typename Arg1Type>
856 class PThreadObj1Arg : public PThread
857 {
858  PCLASSINFO_ALIGNED(PThreadObj1Arg, PThread, 16);
859  public:
860  typedef void (ObjType::*ObjTypeFn)(Arg1Type);
861 
863  ObjType & obj,
864  Arg1Type arg1,
865  ObjTypeFn function,
866  bool autoDel = false,
867  const char * name = NULL,
868  PThread::Priority priority = PThread::NormalPriority
869  ) : PThread(10000,
871  priority,
872  name)
873  , m_object(obj)
874  , m_function(function)
875  , m_arg1(arg1)
876  {
877  PThread::Resume();
878  }
879 
881  {
883  }
884 
885  void Main()
886  {
887  (m_object.*m_function)(m_arg1);
888  }
889 
890  protected:
891  ObjType & m_object;
892  P_ALIGN_FIELD(ObjTypeFn,m_function,16);
893  Arg1Type m_arg1;
894 };
895 
896 template <class ObjType, typename Arg1Type, typename Arg2Type>
897 class PThreadObj2Arg : public PThread
898 {
899  PCLASSINFO_ALIGNED(PThreadObj2Arg, PThread, 16);
900  public:
901  typedef void (ObjType::*ObjTypeFn)(Arg1Type, Arg2Type);
902 
904  ObjType & obj,
905  Arg1Type arg1,
906  Arg2Type arg2,
907  ObjTypeFn function,
908  bool autoDel = false,
909  const char * name = NULL,
910  PThread::Priority priority = PThread::NormalPriority
911  ) : PThread(10000,
913  priority,
914  name)
915  , m_object(obj)
916  , m_function(function)
917  , m_arg1(arg1)
918  , m_arg2(arg2)
919  {
920  PThread::Resume();
921  }
922 
924  {
926  }
927 
928  void Main()
929  {
930  (m_object.*m_function)(m_arg1, m_arg2);
931  }
932 
933  protected:
934  ObjType & m_object;
935  P_ALIGN_FIELD(ObjTypeFn,m_function,16);
936  Arg1Type m_arg1;
937  Arg2Type m_arg2;
938 };
939 
940 
942 //
943 // PThreadLocalStorage
944 //
945 
946 template <class Storage_T>
948 {
949  public:
950  typedef Storage_T * Ptr_T;
951 
953  Ptr_T Get() const { return (Ptr_T)this->GetStorage(); }
954  operator Ptr_T() const { return (Ptr_T)this->GetStorage(); }
955  Ptr_T operator->() const { return (Ptr_T)this->GetStorage(); }
956  Storage_T & operator*() const { return *(Ptr_T)this->GetStorage(); }
957 
958  protected:
959  virtual void * Allocate() const { return new Storage_T(); }
960  virtual void Deallocate(void * ptr) const { delete (Ptr_T)ptr; }
961 };
962 
963 
964 #define P_HAS_THREADLOCAL_STORAGE 1 // For backward compatbility
965 
966 
967 #endif // PTLIB_THREAD_H
968 
969 // End Of File ///////////////////////////////////////////////////////////////
Arg2Type m_arg2
Definition: thread.h:937
virtual void Deallocate(void *ptr) const
Definition: thread.h:960
~PThreadObj2Arg()
Definition: thread.h:923
void WaitForTermination() const
Block and wait for the thread to terminate.
Definition: channel.h:737
AutoDeleteFlag
Codes for thread autodelete flag.
Definition: thread.h:83
This class defines a thread synchronisation object.
Definition: semaphor.h:74
virtual PString GetThreadName() const
Get the name of the thread.
~PThreadObj()
Definition: thread.h:823
Arg1Type m_arg1
Definition: thread.h:728
Times for execution of the thread.
Definition: thread.h:351
FnType m_function
Definition: thread.h:778
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
virtual PBoolean IsTerminated() const
Determine if the thread has been terminated or ran to completion.
virtual void Main()
User override function for the main execution routine of the thread.
Definition: thread.h:581
Class specialisation for PNotifierTemplate&lt;P_INT_PTR&gt;
Storage_T * Ptr_T
Definition: thread.h:950
Ptr_T Get() const
Definition: thread.h:953
void(* FnType)()
Definition: thread.h:568
static PThread * Create(const PNotifier &notifier, const PString &threadName)
Definition: thread.h:473
This class defines an absolute time and date.
Definition: ptime.h:49
Arg1Type m_arg1
Definition: thread.h:936
~PThread()
Destroy the thread, this simply calls the Terminate() function with all its restrictions and penaltie...
This class implements critical section mutexes using the most efficient mechanism available on the ho...
Definition: mutex.h:270
static PString GetCurrentThreadName()
Get the current threads name.
Definition: thread.h:297
Arg2Type m_arg2
Definition: thread.h:780
Definition: thread.h:897
PThread1Arg(Arg1Type arg1, FnType function, bool autoDel=false, const char *name=NULL, PThread::Priority priority=PThread::NormalPriority)
Definition: thread.h:654
virtual void Main()=0
User override function for the main execution routine of the thread.
Arg1Type m_arg1
Definition: thread.h:679
Type
Definition: thread.h:529
virtual void Resume()
Resume thread execution, this is identical to Suspend(false).
PUniqueThreadIdentifier m_uniqueId
Unique thread identifier.
Definition: thread.h:374
PThread2Arg(Arg1Type arg1, Arg2Type arg2, FnType function, bool autoDel=false, const char *name=NULL, PThread::Priority priority=PThread::NormalPriority)
Definition: thread.h:701
Definition: thread.h:856
FnType m_function
Definition: thread.h:727
~PThreadFunctor()
Definition: thread.h:620
PCriticalSection m_threadNameMutex
Definition: thread.h:534
PThreadMain(FnType function, bool autoDel=false)
Definition: thread.h:569
P_ALIGN_FIELD(ObjTypeFn, m_function, 16)
Arg3Type m_arg3
Definition: thread.h:781
static bool WaitAndDelete(PThread *&thread, const PTimeInterval &maxWait=10000, PMutex *mutex=NULL, bool lock=true)
Wait for thread termination and delete object.
Ptr_T operator->() const
Definition: thread.h:955
~PThread3Arg()
Definition: thread.h:767
virtual void Suspend(PBoolean susp=true)
Suspend or resume the thread.
Define some templates to simplify the declaration of simple PThread descendants with one or two param...
Definition: thread.h:564
P_ALIGN_FIELD(ObjTypeFn, m_function, 16)
Arg1Type m_arg1
Definition: thread.h:893
void PrintOn(ostream &strm) const
Standard stream print function.
static void Sleep(const PTimeInterval &delay)
Suspend the current thread for the specified amount of time.
static PThread * Create(const PNotifier &notifier, INT parameter=0, AutoDeleteFlag deletion=AutoDeleteThread, Priority priorityLevel=NormalPriority, const PString &threadName=PString::Empty(), PINDEX stackSize=0)
Create a simple thread executing the specified notifier.
virtual void Main()
User override function for the main execution routine of the thread.
Definition: thread.h:672
virtual void Terminate()
Terminate the thread.
void(* FnType)(Arg1Type arg1)
Definition: thread.h:652
P_DECLARE_TRACED_ENUM(Priority, LowestPriority, LowPriority, NormalPriority, HighPriority, HighestPriority)
Codes for thread priorities.
This class represents an operating system process.
Definition: pprocess.h:106
Definition: thread.h:604
PString m_name
Name of thread.
Definition: thread.h:372
PString m_threadName
Definition: thread.h:533
~PThreadObj1Arg()
Definition: thread.h:880
~PThread1Arg()
Definition: thread.h:667
friend class PThreadLocalStorageData
Definition: thread.h:497
static PString GetIdentifiersAsString(PThreadIdentifier tid, PUniqueThreadIdentifier uid)
Convert to thread identifers as a string.
void(* FnType)(Arg1Type arg1, Arg2Type arg2)
Definition: thread.h:700
ObjType & m_object
Definition: thread.h:834
ObjType & m_object
Definition: thread.h:934
virtual void SetAutoDelete(AutoDeleteFlag deletion=AutoDeleteThread)
Set the flag indicating thread object is to be automatically deleted when the thread ends...
void(* FnType)(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3)
Definition: thread.h:749
PThread3Arg(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3, FnType function, bool autoDel=false, const char *name=NULL, PThread::Priority priority=PThread::NormalPriority)
Definition: thread.h:750
bool PBoolean
Definition: object.h:174
~PThreadMain()
Definition: thread.h:576
PThreadObj(ObjType &obj, ObjTypeFn function, bool autoDel=false, const char *name=NULL, PThread::Priority priority=PThread::NormalPriority)
Definition: thread.h:807
static void GetTimes(std::list< Times > &times)
Definition: thread.h:529
Definition: thread.h:529
PThreadIdentifier m_threadId
Operating system thread ID.
Definition: thread.h:373
virtual void Deallocate(void *ptr) const =0
Definition: thread.h:529
The character string class.
Definition: pstring.h:108
static void Yield()
Yield to another thread without blocking.
FnType m_function
Definition: thread.h:587
PTimeInterval m_kernel
Total kernel CPU time in milliseconds.
Definition: thread.h:376
Don&#39;t delete thread as it may not be on heap.
Definition: thread.h:88
virtual void Main()
User override function for the main execution routine of the thread.
Definition: thread.h:772
Definition: thread.h:801
Functor & m_funct
Definition: thread.h:631
void SetNoAutoDelete()
Reet the flag indicating thread object is to be automatically deleted when the thread ends...
Definition: thread.h:279
This class defines a thread mutual exclusion object.
Definition: mutex.h:101
This class defines a thread of execution in the system.
Definition: thread.h:66
Definition: thread.h:696
PTimeInterval m_real
Total real time since thread start in milliseconds.
Definition: thread.h:375
Definition: thread.h:529
P_ALIGN_FIELD(ObjTypeFn, m_function, 16)
virtual void Main()
User override function for the main execution routine of the thread.
Definition: thread.h:721
static int GetPercentageCPU(Times &previousTimes, const PTimeInterval &period=PTimeInterval(0, 1), PThreadIdentifier id=PNullThreadIdentifier)
Calculate the percentage CPU used over a period of time.
PUniqueThreadIdentifier m_uniqueId
Definition: thread.h:537
static const PString & Empty()
Return an empty string.
void(ObjType::* ObjTypeFn)(Arg1Type)
Definition: thread.h:860
Definition: thread.h:745
Arg2Type m_arg2
Definition: thread.h:729
PTime m_sample
Time of sample.
Definition: thread.h:378
~PThreadLocalStorage()
Definition: thread.h:952
PThread(PINDEX stack, AutoDeleteFlag deletion=AutoDeleteThread, Priority priorityLevel=NormalPriority, const PString &threadName=PString::Empty())
Create a new thread instance.
virtual void * Allocate() const
Definition: thread.h:959
static unsigned GetNumProcessors()
Get number of processors, or processor cores, this machine has available.
void Main()
User override function for the main execution routine of the thread.
Definition: thread.h:828
enum PThread::Type m_type
void Main()
User override function for the main execution routine of the thread.
Definition: thread.h:885
Definition: thread.h:648
virtual void * Allocate() const =0
bool IsAutoDelete() const
Definition: thread.h:479
static PThread * Current()
Get the currently running thread object instance.
Definition: thread.h:947
virtual void Restart()
Restart a terminated thread using the same stack priority etc that was current when the thread termin...
void(ObjType::* ObjTypeFn)(Arg1Type, Arg2Type)
Definition: thread.h:901
Automatically delete thread object on termination.
Definition: thread.h:85
void(ObjType::* ObjTypeFn)()
Definition: thread.h:805
virtual PBoolean IsSuspended() const
Determine if the thread is currently suspended.
PINDEX m_originalStackSize
Definition: thread.h:531
virtual void SetThreadName(const PString &name)
Change the name of the thread.
PThreadObj1Arg(ObjType &obj, Arg1Type arg1, ObjTypeFn function, bool autoDel=false, const char *name=NULL, PThread::Priority priority=PThread::NormalPriority)
Definition: thread.h:862
virtual Priority GetPriority() const
Get the current priority of the thread in the current process.
Definition: object.h:1537
Storage_T & operator*() const
Definition: thread.h:956
void Main()
User override function for the main execution routine of the thread.
Definition: thread.h:928
~PThread2Arg()
Definition: thread.h:716
virtual ~LocalStorageBase()
Definition: thread.h:485
PThreadFunctor(Functor &funct, bool autoDel=false, const char *name=NULL, PThread::Priority priority=PThread::NormalPriority)
Definition: thread.h:608
virtual void Main()
User override function for the main execution routine of the thread.
Definition: thread.h:625
ObjType & m_object
Definition: thread.h:891
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
void ThreadDestroyed(PThread &thread)
This class defines a thread synchronisation object.
Definition: syncpoint.h:63
Arg1Type m_arg1
Definition: thread.h:779
friend class PExternalThread
Definition: thread.h:510
PPROFILE_EXCLUDE(PThreadIdentifier GetThreadId() const )
PThreadObj2Arg(ObjType &obj, Arg1Type arg1, Arg2Type arg2, ObjTypeFn function, bool autoDel=false, const char *name=NULL, PThread::Priority priority=PThread::NormalPriority)
Definition: thread.h:903
PTimeInterval m_user
Total user CPU time in milliseconds.
Definition: thread.h:377
PThreadIdentifier m_threadId
Definition: thread.h:536
virtual void SetPriority(Priority priorityLevel)
Set the priority of the thread relative to other threads in the current process.
Thread local storage base class, see PThreadLocalStorage for template.
Definition: thread.h:482
virtual void * GetStorage() const
FnType m_function
Definition: thread.h:678