ReplicaNet and RNLobby  1
Thread.h
1 /* START_LICENSE_HEADER
2 
3 Copyright (C) 2000 Martin Piper, original design and program code
4 Copyright (C) 2001 Replica Software
5 
6 This program file is copyright (C) Replica Software and can only be used under license.
7 For more information visit: http://www.replicanet.com/
8 Or email: info@replicanet.com
9 
10 END_LICENSE_HEADER */
11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef __THREAD_H__
13 #define __THREAD_H__
14 
15 #include <stddef.h> // For size_t
16 #if defined(RN_UNIX_LIKE)
17 #include <pthread.h>
18 #endif
19 
20 namespace RNReplicaNet
21 {
22 
23 class ThreadClass;
24 const int kReplicaNetPreferredProcessorOSChoice = -1;
29 class Thread
30 {
31 public:
35  Thread();
36 
40  virtual ~Thread();
41 
47  void Begin(ThreadClass *threaded_class);
48 
52  void Terminate(void);
53 
57  bool GetTerminated(void);
58 
62  bool GetEverTerminated(void);
63 
68  static int CallThreadEntry(ThreadClass *thread_class);
69 
74  bool GetIsRunning(void) const;
75 
80  void SetPreferredProcessor(int processor = kReplicaNetPreferredProcessorOSChoice);
81 
85  static int GetCurrentProcessorNumber(void);
86 
90  int GetPreferredProcessor(void);
91 
92  static size_t GetNumAllocated(void)
93  {
94  return mNumAllocated;
95  }
96  static size_t GetNumActive(void)
97  {
98  return mNumActive;
99  }
100 
101 private:
102  friend class ThreadClass;
103  ThreadClass *mThreadClass;
104 #if defined(_WIN32)
105  void *mThreadHandle;
106 // unsigned long mThreadHandle;
107 #endif
108 #if defined(RN_UNIX_LIKE)
109  pthread_t mThreadHandle;
110 #endif
111 #if defined (_PS2)
112  int mThreadHandle;
113 #endif
114 
115  int mProcessor; // The preferred processor to run this thread on
116 
117  volatile bool mIsRunning;
118  volatile bool mTerminateCalled;
119  volatile bool mTerminateCalledNoReset;
120 
121  static size_t mNumAllocated;
122  static size_t mNumActive;
123 };
124 
125 } // namespace RNReplicaNet
126 
127 #endif
void SetPreferredProcessor(int processor=kReplicaNetPreferredProcessorOSChoice)
static int CallThreadEntry(ThreadClass *thread_class)
void Begin(ThreadClass *threaded_class)
bool GetTerminated(void)
bool GetIsRunning(void) const
bool GetEverTerminated(void)
int GetPreferredProcessor(void)
Definition: ThreadClass.h:96
static int GetCurrentProcessorNumber(void)
Definition: Thread.h:29