Nebula
Loading...
Searching...
No Matches
osxthread.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
11#include "core/refcounted.h"
12#include "threading/threadid.h"
13#include "system/cpu.h"
14
15//------------------------------------------------------------------------------
16namespace OSX
17{
19{
21public:
24 {
28 };
29
31 OSXThread();
33 virtual ~OSXThread();
35 void SetPriority(Priority p);
37 Priority GetPriority() const;
43 void SetStackSize(SizeT s);
45 SizeT GetStackSize() const;
47 void SetName(const Util::String& n);
49 const Util::String& GetName() const;
51 void Start();
53 void Stop();
55 bool IsRunning() const;
56
58 static void YieldThread();
61
62 #if NEBULA_DEBUG
63 /*
64 struct ThreadDebugInfo
65 {
66 Util::String threadName;
67 PS3Thread::Priority threadPriority;
68 System::Cpu::CoreId threadCoreId;
69 SizeT threadStackSize;
70 };
72 static Util::Array<ThreadDebugInfo> GetRunningThreadDebugInfos();
73 */
74 #endif
75
76protected:
78 virtual void EmitWakeupSignal();
80 virtual void DoWork();
82 bool ThreadStopRequested() const;
83
84private:
92
93 pthread_t thread;
99
100#if NEBULA_DEBUG
101 static Threading::CriticalSection criticalSection;
102 static Util::List<OSXThread*> ThreadList;
103 Util::List<OSXThread*>::Iterator threadListIterator;
104#endif
105};
106
107//------------------------------------------------------------------------------
110inline void
112{
113 this->priority = p;
114}
115
116//------------------------------------------------------------------------------
121{
122 return this->priority;
123}
124
125//------------------------------------------------------------------------------
128inline void
130{
131 this->stackSize = s;
132}
133
134//------------------------------------------------------------------------------
137inline SizeT
139{
140 return this->stackSize;
141}
142
143//------------------------------------------------------------------------------
150inline bool
152{
153n_error("IMPLEMENT ME!");
154return false;
155 //return this->stopRequestEvent.Peek();
156}
157
158//------------------------------------------------------------------------------
162inline void
164{
165 n_assert(n.IsValid());
166 this->name = n;
167}
168
169//------------------------------------------------------------------------------
174inline const Util::String&
176{
177 return this->name;
178}
179
180//------------------------------------------------------------------------------
183inline void
185{
186 this->coreId = id;
187}
188
189//------------------------------------------------------------------------------
194{
195 return this->coreId;
196}
197
198} // namespace OSX
199//------------------------------------------------------------------------------
The common base class of Nebula.
Definition refcounted.h:38
OSX implementation of Threading::Thread.
Definition osxthread.h:19
void SetName(const Util::String &n)
set thread name
Definition osxthread.h:163
Priority GetPriority() const
get the thread priority
Definition osxthread.h:120
ThreadState volatile threadState
Definition osxthread.h:98
void SetCoreId(System::Cpu::CoreId coreId)
set cpu core on which the thread should be running
Definition osxthread.h:184
const Util::String & GetName() const
get thread name
Definition osxthread.h:175
void SetPriority(Priority p)
set the thread priority
Definition osxthread.h:111
void Start()
start executing the thread code, returns when thread has actually started
Definition osxthread.cc:56
pthread_t thread
Definition osxthread.h:93
System::Cpu::CoreId coreId
Definition osxthread.h:97
System::Cpu::CoreId GetCoreId() const
get the cpu core on which the thread should be running
Definition osxthread.h:193
Util::String name
Definition osxthread.h:96
OSXThread()
constructor
Definition osxthread.cc:18
static void YieldThread()
yield the thread (gives up current time slice)
Definition osxthread.cc:128
SizeT GetStackSize() const
get stack size
Definition osxthread.h:138
void SetStackSize(SizeT s)
set stack size in bytes (default is 4 KByte)
Definition osxthread.h:129
virtual ~OSXThread()
destructor
Definition osxthread.cc:35
void Stop()
request threading code to stop, returns when thread has actually finished
Definition osxthread.cc:83
Priority
thread priorities
Definition osxthread.h:24
@ Low
Definition osxthread.h:25
@ Normal
Definition osxthread.h:26
@ High
Definition osxthread.h:27
ThreadState
thread states
Definition osxthread.h:87
@ Stopped
Definition osxthread.h:90
@ Running
Definition osxthread.h:89
@ Initial
Definition osxthread.h:88
bool IsRunning() const
return true if thread has been started
Definition osxthread.cc:93
__DeclareClass(OSXThread)
static Threading::ThreadId GetMyThreadId()
get the thread ID of this thread
Definition osxthread.cc:117
virtual void DoWork()
this method runs in the thread context
Definition osxthread.cc:107
bool ThreadStopRequested() const
check if stop is requested, call from DoWork() to see if the thread proc should quit
Definition osxthread.h:151
Priority priority
Definition osxthread.h:94
SizeT stackSize
Definition osxthread.h:95
virtual void EmitWakeupSignal()
override this method if your thread loop needs a wakeup call before stopping
Definition osxthread.cc:70
CoreId
Definition cpu.h:19
Critical section objects are used to protect a portion of code from parallel execution.
the list iterator
Definition list.h:76
Implements a doubly linked list.
Definition list.h:20
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
#define n_assert(exp)
Definition debug.h:50
Definition osxsysfunc.h:21
pthread_t ThreadId
Definition linuxthreadid.h:15
Nebula's universal string class.
Definition string.h:50
bool IsValid() const
return true if string object is not empty
Definition string.h:684
int SizeT
Definition types.h:49