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;
42 /**----------------------------------------------------------------------------
43 \brief Functions for interfacing with the current thread. If threading is disabled
44 for an application, these functions will still be present.
45 ----------------------------------------------------------------------------*/
47 {
48 public:
49 static void SetCurrentThreadName(const String& name);
50 static bool IsPrimaryThread();
51 static void SetPrimaryThreadID(uint04 primary_thread);
52 static void RequestSleep(const TimeSpan& interval);
55 static void RequestNoSleep(bool request_no_sleep);
57 private:
58 static void RequestSleep(uint08 milliseconds);
59 static uint04 s_primary_thread_id;
60 };
61#if NDEVR_SUPPORTS_THREADING
62 /**----------------------------------------------------------------------------
63 \brief A thread is a single sequence stream within the software
64 This is the default Thread class for the NDEVR API
65 ----------------------------------------------------------------------------*/
67 {
68 public:
70 Thread(const String& name);
71 Thread(const Thread& name) = delete;
72 virtual ~Thread();
73
74 void start();
75 void join();
76 void detach();
77 virtual void stopThread();
78 virtual void requestStopThread();
79 bool isRunning() const;
80 void forceStop() { m_is_running = false; }
81 void setIsPrimaryThread(bool is_primary_thread);
82 virtual bool shouldExitThread() const;
83 bool isPrimaryThread() const;
84 const String& threadName() const { return m_name; }
85 void setThreadName(const String& name);
86 static void StopAllThreads();
87 static void ServiceVirtualThreads();
90 static void SetCurrentThreadName(const String& name);
91 protected:
92 const std::thread& self();
93 virtual void run(){};//Override this to make the thread do something
94 private:
95 void startInThread();
96 private:
97 static uint08 GetThreadCount() { return s_thread_count; }
98 static void _setThreadName(const String& name);
99 private:
100 String m_name;
101 std::thread* m_tid = nullptr;
102 uint04 m_thread_id = Constant<uint04>::Invalid;
103 protected:
104 volatile bool m_is_running = false;
105 volatile bool m_is_single_run = true;
106 private:
107 volatile static uint04 s_thread_count;
108 static Dictionary<uint04, Thread*> s_thread_map;
109
110
111 };
112#endif
113}
#define NDEVR_BASE_API
Definition DLLInfo.h:57
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
The core String class for the NDEVR API.
Definition String.h:69
Functions for interfacing with the current thread. If threading is disabled.
Definition Thread.h:47
static String CurrentThreadName()
static bool IsPrimaryThread()
static void RequestSleep(const TimeSpan &interval)
static void SetCurrentThreadName(const String &name)
static void SetPrimaryThreadID(uint04 primary_thread)
static uint04 PrimaryThreadID()
static void RequestNoSleep(bool request_no_sleep)
static uint04 CurrentThreadID()
A thread is a single sequence stream within the software.
Definition Thread.h:67
const String & threadName() const
Definition Thread.h:84
static void StopAllThreads()
virtual ~Thread()
static Thread & CurrentThread()
virtual void stopThread()
static String CurrentThreadName()
void setThreadName(const String &name)
virtual bool shouldExitThread() const
Thread(const String &name)
virtual void run()
Definition Thread.h:93
void forceStop()
Definition Thread.h:80
virtual void requestStopThread()
static void SetCurrentThreadName(const String &name)
bool isPrimaryThread() const
static void ServiceVirtualThreads()
bool isRunning() const
Thread(const Thread &name)=delete
const std::thread & self()
void setIsPrimaryThread(bool is_primary_thread)
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
Definition ACIColor.h:37
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96