GM6000 Digital Heater Controller Branch: main
SDX-1330
Thread.h
Go to the documentation of this file.
1#ifndef Cpl_System_Win32_Thread_h_
2#define Cpl_System_Win32_Thread_h_
3/*-----------------------------------------------------------------------------
4* This file is part of the Colony.Core Project. The Colony.Core Project is an
5* open source project with a BSD type of licensing agreement. See the license
6* agreement (license.txt) in the top/ directory or on the Internet at
7* http://integerfox.com/colony.core/license.txt
8*
9* Copyright (c) 2014-2022 John T. Taylor
10*
11* Redistributions of the source code must retain the above copyright notice.
12*----------------------------------------------------------------------------*/
13/** @file */
14
15#include "Cpl/System/Thread.h"
17#include "Cpl/Text/FString.h"
18
19
20///
21namespace Cpl {
22///
23namespace System {
24///
25namespace Win32 {
26
27/** This concrete class implements a Thread object using Win32 threads
28 NOTE: The class/implementation uses _beginthread() instead of
29 CreateThread() ->this is per Microsoft's documentation
30 that says the _beginthread() properly initializes/cleans-up
31 the C-Runtime library as where CreateThread() does NOT.
32 */
34{
35protected:
36 /// Reference to the runnable object for the thread
38
39 /// ASCII name of the task
41
42 /// Thread ID
43 size_t m_threadID;
44
45 /// internal handle
47
48 /// Priority
50
51 /// Option to allow simulate ticks
53
54 /// The thread synchronized message semaphore.
56
57
58public:
59 /** Constructor. Priority is 0=highest, 30=lowest, normal=15.
60 NOTE: Does NOT support the application supplying the stack
61 memory.
62 */
63 Thread( Runnable& runnable,
64 const char* name,
66 unsigned stackSize = 0,
67 bool allowSimTicks = true
68 );
69
70 /// Destructor
72
73public:
74 /// See Cpl::System::Thread
75 const char* getName() noexcept;
76
77 /// See Cpl::System::Thread
78 size_t getId() noexcept;
79
80 /// See Cpl::System::Thread
81 bool isRunning( void ) noexcept;
82
83 /// See Cpl::System::Thread
85
86 /// See Cpl::System::Thread
87 Runnable& getRunnable( void ) noexcept;
88
89
90public:
91 /// See Cpl::System::Signable
92 int signal( void ) noexcept;
93
94 /// See Cpl::System::Signable
95 int su_signal( void ) noexcept;
96
97
98
99private:
100 /// Entry point for all newly created threads
101 static void __cdecl entryPoint( void* data );
102
103
104public:
105 /** COMPONENT Scoped constructor to convert the native Win32 thread to a
106 Cpl Thread. THIS CONSTRUCTOR SHOULD NEVER BE USED BY THE APPLICATION!
107 */
108 Thread( Cpl::System::Runnable& dummyRunnable );
109
110
111public:
112 /// Housekeeping
113 friend class Cpl::System::Thread;
114};
115
116
117}; // end namespaces
118};
119};
120#endif // end header latch
#define Cpl_System_Thread_NativeHdl_T
Defer the definition of the native thread handle to the application's 'platform'.
Definition Thread.h:23
#define CPL_SYSTEM_THREAD_PRIORITY_NORMAL
The recommended/default priority for a thread.
Definition Thread.h:30
This is an abstract class defines the interface for an object that is "executed" when a Thread object...
Definition Runnable.h:29
This semaphore class defines the interface for a Counting Semaphore.
Definition Semaphore.h:37
This abstract class defines the operations that can be performed on a thread.
Definition Thread.h:62
This concrete class implements a Thread object using Win32 threads NOTE: The class/implementation use...
Definition Thread.h:34
Cpl::System::Semaphore m_syncSema
The thread synchronized message semaphore.
Definition Thread.h:55
bool m_allowSimTicks
Option to allow simulate ticks.
Definition Thread.h:52
Cpl::Text::FString< 64 > m_name
ASCII name of the task.
Definition Thread.h:40
int m_priority
Priority.
Definition Thread.h:49
Runnable & getRunnable(void) noexcept
See Cpl::System::Thread.
int signal(void) noexcept
See Cpl::System::Signable.
size_t m_threadID
Thread ID.
Definition Thread.h:43
const char * getName() noexcept
See Cpl::System::Thread.
HANDLE m_threadHandle
internal handle
Definition Thread.h:46
Thread(Runnable &runnable, const char *name, int priority=CPL_SYSTEM_THREAD_PRIORITY_NORMAL, unsigned stackSize=0, bool allowSimTicks=true)
Constructor.
int su_signal(void) noexcept
See Cpl::System::Signable.
Cpl_System_Thread_NativeHdl_T getNativeHandle(void) noexcept
See Cpl::System::Thread.
size_t getId() noexcept
See Cpl::System::Thread.
bool isRunning(void) noexcept
See Cpl::System::Thread.
Cpl::System::Runnable & m_runnable
Reference to the runnable object for the thread.
Definition Thread.h:37
This template class represents a NULL terminated string of a specific length.
Definition FString.h:38
The 'Cpl' namespace is the root name space for the Colony.
Definition Api16.h:20