Plasma Engine  2.0
Loading...
Searching...
No Matches
Thread.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Communication/Event.h>
5#include <Foundation/Strings/String.h>
6#include <Foundation/Threading/ThreadUtils.h>
7
8#include <Foundation/Threading/Implementation/OSThread.h>
9
10// Warning: 'this' used in member initialization list (is fine here since it is just stored and not
11// accessed in the constructor (so no operations on a not completely initialized object happen)
12
13PL_WARNING_PUSH()
14PL_WARNING_DISABLE_MSVC(4355)
15
16#ifndef PL_THREAD_CLASS_ENTRY_POINT
17# error "Definition for plThreadClassEntryPoint is missing on this platform!"
18#endif
19
20PL_THREAD_CLASS_ENTRY_POINT;
21
23{
31
32 Type m_Type;
33 plThread* m_pThread = nullptr;
34};
35
39class PL_FOUNDATION_DLL plThread : public plOSThread
40{
41public:
43 static const plThread* GetCurrentThread();
44
47 {
48 Created = 0,
49 Running,
50 Finished
51 };
52
54 plThread(plStringView sName = "plThread", plUInt32 uiStackSize = 128 * 1024);
55
57 virtual ~plThread();
58
60 inline plThreadStatus GetThreadStatus() const { return m_ThreadStatus; }
61
63 inline bool IsRunning() const { return m_ThreadStatus == Running; }
64
66 inline const char* GetThreadName() const { return m_sName.GetData(); }
67
73
74private:
76 virtual plUInt32 Run() = 0;
77
78
79 volatile plThreadStatus m_ThreadStatus = Created;
80
81 plString m_sName;
82
83 friend plUInt32 RunThread(plThread* pThread);
84};
85
86PL_WARNING_POP()
Definition Event.h:177
Implementation of a thread.
Definition OSThread.h:13
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
This class is the base class for platform independent long running threads.
Definition Thread.h:40
static plEvent< const plThreadEvent &, plMutex > s_ThreadEvents
These events inform about threads starting and finishing.
Definition Thread.h:72
bool IsRunning() const
Helper function to determine if the thread is running.
Definition Thread.h:63
plThreadStatus GetThreadStatus() const
Returns the thread status.
Definition Thread.h:60
plThreadStatus
Describes the thread status.
Definition Thread.h:47
virtual plUInt32 Run()=0
The run function can be used to implement a long running task in a thread in a platform independent w...
const char * GetThreadName() const
Returns the thread name.
Definition Thread.h:66
Definition Thread.h:23
Type
Definition Thread.h:25
@ StartingExecution
Called on the thread that executes the plThread instance.
@ ThreadCreated
Called on the thread that creates the plThread instance.
@ FinishedExecution
Called on the thread that executes the plThread instance.
@ ThreadDestroyed
Called on the thread that destroys the plThread instance.