Leviathan  0.8.0.0
Leviathan game engine
Leviathan::TaskThread Class Reference

Object used by ThreadingManager to easily create properly initialized threads. More...

#include <TaskThread.h>

+ Inheritance diagram for Leviathan::TaskThread:

Public Member Functions

DLLEXPORT TaskThread ()
 
DLLEXPORT ~TaskThread ()
 
DLLEXPORT void SetTaskAndNotify (std::shared_ptr< QueuedTask > task)
 
DLLEXPORT void NotifyKill (Lock &guard)
 
DLLEXPORT void NotifyKill ()
 
DLLEXPORT void NotifyThread ()
 
DLLEXPORT bool HasStarted ()
 Returns true if the thread has performed initialization. More...
 
DLLEXPORT bool HasRunningTask ()
 Returns true if the thread has a task to run. More...
 
DLLEXPORT bool IsRunningTask (std::shared_ptr< QueuedTask > task) const
 Returns true if the current task pointer matches the argument. More...
 
DLLEXPORT std::thread & GetInternalThreadObject ()
 Returns the internal ThisThread variable. More...
 
- Public Member Functions inherited from Leviathan::ThreadSafeGeneric< MutexType >
DLLEXPORT ThreadSafeGeneric ()
 
DLLEXPORT ~ThreadSafeGeneric ()
 
FORCE_INLINE void VerifyLock (RecursiveLock &guard) const
 
FORCE_INLINE void VerifyLock (Lock &lockit) const
 

Static Public Member Functions

static DLLEXPORT ThreadSpecificDataGetThreadSpecificThreadObject ()
 Returns thread specific data about QueuedTask and TaskThread object. More...
 

Friends

void RunNewThread (TaskThread *thisthread)
 

Additional Inherited Members

- Protected Attributes inherited from Leviathan::ThreadSafeGeneric< MutexType >
MutexType ObjectsLock
 

Detailed Description

Object used by ThreadingManager to easily create properly initialized threads.

Definition at line 22 of file TaskThread.h.

Constructor & Destructor Documentation

◆ TaskThread()

DLLEXPORT Leviathan::TaskThread::TaskThread ( )
Warning
this may only be called by the main thread and while no tasks are running, since this will register the thread in various places

Definition at line 91 of file TaskThread.cpp.

91  : StartUpDone(false), KillSelf(false){
92  // Start the thread //
93  ThisThread = std::thread(std::bind(RunNewThread, this));
94 }
friend void RunNewThread(TaskThread *thisthread)

◆ ~TaskThread()

DLLEXPORT Leviathan::TaskThread::~TaskThread ( )

Definition at line 96 of file TaskThread.cpp.

96  {
97  // We want the thread to actually end sometime soon //
98  NotifyKill();
99  ThisThread.join();
100 }
DLLEXPORT void NotifyKill()
Definition: TaskThread.cpp:113

Member Function Documentation

◆ GetInternalThreadObject()

DLLEXPORT std::thread & Leviathan::TaskThread::GetInternalThreadObject ( )

Returns the internal ThisThread variable.

Definition at line 167 of file TaskThread.cpp.

167  {
168  return ThisThread;
169 }

◆ GetThreadSpecificThreadObject()

DLLEXPORT ThreadSpecificData * Leviathan::TaskThread::GetThreadSpecificThreadObject ( )
static

Returns thread specific data about QueuedTask and TaskThread object.

Definition at line 171 of file TaskThread.cpp.

171  {
172  return ThreadThreadPtr.get();
173 }

◆ HasRunningTask()

DLLEXPORT bool Leviathan::TaskThread::HasRunningTask ( )

Returns true if the thread has a task to run.

Definition at line 154 of file TaskThread.cpp.

154  {
155  // Get lock to wait for any possible action to finish //
156  GUARD_LOCK();
157 
158  return SetTask.get() != NULL;
159 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ HasStarted()

DLLEXPORT bool Leviathan::TaskThread::HasStarted ( )

Returns true if the thread has performed initialization.

Definition at line 147 of file TaskThread.cpp.

147  {
148  // Get lock to wait for any possible action to finish //
149  GUARD_LOCK();
150 
151  return StartUpDone;
152 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ IsRunningTask()

DLLEXPORT bool Leviathan::TaskThread::IsRunningTask ( std::shared_ptr< QueuedTask task) const

Returns true if the current task pointer matches the argument.

Definition at line 161 of file TaskThread.cpp.

161  {
162 
163  GUARD_LOCK();
164  return SetTask.get() == task.get();
165 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ NotifyKill() [1/2]

DLLEXPORT void Leviathan::TaskThread::NotifyKill ( Lock guard)

Definition at line 102 of file TaskThread.cpp.

102  {
103  // Verify lock //
104  VerifyLock(guard);
105 
106  // Set as quitting //
107  KillSelf = true;
108 
109  // Notify the thread //
110  NotifyThread();
111 }
FORCE_INLINE void VerifyLock(RecursiveLock &guard) const
Definition: ThreadSafe.h:128
DLLEXPORT void NotifyThread()
Definition: TaskThread.cpp:119

◆ NotifyKill() [2/2]

DLLEXPORT void Leviathan::TaskThread::NotifyKill ( )

Definition at line 113 of file TaskThread.cpp.

113  {
114  // Lock and call the other //
115  GUARD_LOCK();
116  NotifyKill(guard);
117 }
DLLEXPORT void NotifyKill()
Definition: TaskThread.cpp:113
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ NotifyThread()

DLLEXPORT void Leviathan::TaskThread::NotifyThread ( )

Definition at line 119 of file TaskThread.cpp.

119  {
120  ThreadNotify.notify_all();
121 }

◆ SetTaskAndNotify()

DLLEXPORT void Leviathan::TaskThread::SetTaskAndNotify ( std::shared_ptr< QueuedTask task)

Definition at line 137 of file TaskThread.cpp.

137  {
138  GUARD_LOCK();
139 
140  // Set task //
141  SetTask = task;
142 
143  // Notify //
144  NotifyThread();
145 }
DLLEXPORT void NotifyThread()
Definition: TaskThread.cpp:119
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

Friends And Related Function Documentation

◆ RunNewThread

void RunNewThread ( TaskThread thisthread)
friend

The documentation for this class was generated from the following files: