API Documentation
Loading...
Searching...
No Matches
Thread.h
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: Thread
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/String.h>
35#include <NDEVR/Dictionary.h>
36#if NDEVR_SUPPORTS_THREADING
37 #include <thread>
38#endif
39namespace NDEVR
40{
41 class TimeSpan;
43 {
44 public:
45 static void SetCurrentThreadName(const String& name);
46 static bool IsPrimaryThread();
47 static void SetPrimaryThreadID(uint04 primary_thread);
48 static void RequestSleep(const TimeSpan& interval);
49 static uint04 CurrentThreadID();
50 static uint04 PrimaryThreadID();
51 static void RequestNoSleep(bool request_no_sleep);
52 static String CurrentThreadName();
53 private:
54 static void RequestSleep(uint08 milliseconds);
55 static uint04 s_primary_thread_id;
56 };
57#if NDEVR_SUPPORTS_THREADING
58 class NDEVR_BASE_API Thread
59 {
60 public:
61 Thread();
62 Thread(const String& name);
63 Thread(const Thread& name) = delete;
64 virtual ~Thread();
65
66 void start();
67 void join();
68 void detach();
69 virtual void stopThread();
70 virtual void requestStopThread();
71 bool isRunning() const;
72 void forceStop() { m_is_running = false; }
73 void setIsPrimaryThread(bool is_primary_thread);
74 virtual bool shouldExitThread() const;
75 bool isPrimaryThread() const;
76 const String& threadName() const { return m_name; }
77 void setThreadName(const String& name);
78 static void StopAllThreads();
79 static void ServiceVirtualThreads();
80 static Thread& CurrentThread();
81 static String CurrentThreadName();
82 static void SetCurrentThreadName(const String& name);
83 protected:
84 const std::thread& self();
85 virtual void run(){};//Override this to make the thread do something
86 private:
87 void startInThread();
88 protected:
89 static uint08 GetThreadCount() { return s_thread_count; }
90 static void _setThreadName(const String& name);
91 private:
92 String m_name;
93 std::thread* m_tid = nullptr;
94 uint04 m_thread_id = Constant<uint04>::NaN;
95 protected:
96 volatile bool m_is_running = false;
97 volatile bool m_is_single_run = true;
98 private:
99 volatile static uint04 s_thread_count;
100 static Dictionary<uint04, Thread*> s_thread_map;
101
102
103 };
104#endif
105}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
Definition String.h:40
Definition Thread.h:43
Definition TimeSpan.h:40
Definition ACIColor.h:37
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer -Can represent exact integer values 0 thro...
Definition BaseValues.hpp:132
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120