ConOpSys V2970  P004.07
ANVILEX control operating system
Thread_Manager.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Description : ConOS-Kernel / Thread manager implementation
3 // Filename : ThreadManager.h
4 //------------------------------------------------------------------------------
5 
6 #pragma once
7 
8 //--- Include headers ----------------------------------------------------------
9 
10 #include "Define.h"
11 #include "Circular_List.h"
12 #include "Thread.h"
13 
14 //--- Define log capability ----------------------------------------------------
15 
16 #ifdef LOGGER
17 //#define THREADMANAGER_CPP_LOGGING
18 #endif
19 
20 //--- Define thread runtime factors --------------------------------------------
21 
22 #define THREADMANAGER_REALTIME_FACTOR 1.00 // 100% of thread time
23 #define THREADMANAGER_HIGH_PRIORITY_FACTOR 0.80 // 80% of thread time
24 #define THREADMANAGER_NORMAL_PRIORITY_FACTOR 0.60 // 60% of thread time
25 #define THREADMANAGER_LOW_PRIORITY_FACTOR 0.40 // 40% of thread time
26 #define THREADMANAGER_IDLE_FACTOR 0.20 // 20% of thread time
27 
28 //--- Define interrupt method --------------------------------------------------
29 
30 #pragma inline ( TThreadManager::GetThreadCount )
31 #pragma inline ( TThreadManager::EnterCriticalSection )
32 #pragma inline ( TThreadManager::ExitCriticalSection )
33 
34 //--- C++ definition -----------------------------------------------------------
35 
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
41 //--- Class TThreadManager -----------------------------------------------------
42 
44 {
45 
46  public:
47  TThreadManager(); // Constructor
48  ~TThreadManager(); // Destructor
49  VOID Initialize( DOUBLE ClockFrequency ); // Initialize
50  BOOL SetSwitchTime( DOUBLE ThreadTime ); // Set switch time
51  VOID Run(); // Run thread manager
52  VOID Stop(); // Stop thread manager
53  VOID Create( TThread *Thread ); // Create new thread
54  VOID Destroy( TThread *Thread ); // Destroy thread
55  I32 GetThreadCount(); // Get thread count
56  VOID EnterCriticalSection(); // Enter critical section
57  VOID ExitCriticalSection(); // Exit critical section
58  TCircularList *Storage; // Storage of threads
59  TThread *ActiveThread; // Active thread
60  VOID SwitchImmediate(); // Switch thread immediate
61 
62  private:
63  DOUBLE Resolution; // Timer resolution
64  DOUBLE NormalizedResolution; // Normalized timer resolution
65  U32 RealtimeThreadTimerPrescaler; // Prescaler value for realtime thread
66  U32 HighPriorityThreadTimerPrescaler; // Prescaler value for high priority thread
67  U32 NormalPriorityThreadTimerPrescaler; // Prescaler value for normal priority thread
68  U32 LowPriorityThreadTimerPrescaler; // Prescaler value for low priority thread
69  U32 IdleThreadTimerPrescaler; // Prescaler value for idle thread
70  U32 CriticalSectionsCounter; // Critical sections counter
71 
72 };
73 
74 //--- Define extern object -----------------------------------------------------
75 
77 
78 //--- End Of Class TThreadManager ----------------------------------------------
79 
80 extern VOID *ThreadManagerStack;
81 extern BOOL ThreadSwitch();
82 extern VOID ThreadActivate();
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 //--- End of C++ definition ----------------------------------------------------
90 
91 //------------------------------------------------------------------------------
92 // End Of File
93 //------------------------------------------------------------------------------
int BOOL
Boolean datatype definition.
Definition: Defines.h:124
long I32
2s Compliment 32-Bit signed integer datatype defenition
Definition: Defines.h:206
void VOID
Datatypesess datatype definition.
Definition: Defines.h:105
unsigned long U32
Binary 32-Bit unsigned integer datatype defenition.
Definition: Defines.h:203
BOOL ThreadSwitch()
Definition: Thread_Manager.cpp:39
VOID ThreadManagerInterrupt()
VOID * ThreadManagerStack
TThreadManager ThreadManager
VOID ThreadActivate()
Definition: Thread_Manager.cpp:136
Definition: Circular_List.h:17
Definition: Thread.h:28
Definition: Thread_Manager.h:44
U32 RealtimeThreadTimerPrescaler
Definition: Thread_Manager.h:65
VOID Run()
Definition: Thread_Manager.cpp:314
~TThreadManager()
Definition: Thread_Manager.cpp:218
VOID Create(TThread *Thread)
Definition: Thread_Manager.cpp:356
VOID EnterCriticalSection()
Definition: Thread_Manager.cpp:480
BOOL SetSwitchTime(DOUBLE ThreadTime)
Definition: Thread_Manager.cpp:261
DOUBLE Resolution
Definition: Thread_Manager.h:63
VOID ExitCriticalSection()
Definition: Thread_Manager.cpp:495
TThread * ActiveThread
Definition: Thread_Manager.h:59
TThreadManager()
Definition: Thread_Manager.cpp:182
VOID Stop()
Definition: Thread_Manager.cpp:331
U32 CriticalSectionsCounter
Definition: Thread_Manager.h:70
I32 GetThreadCount()
Definition: Thread_Manager.cpp:344
U32 LowPriorityThreadTimerPrescaler
Definition: Thread_Manager.h:68
TCircularList * Storage
Definition: Thread_Manager.h:58
DOUBLE NormalizedResolution
Definition: Thread_Manager.h:64
U32 IdleThreadTimerPrescaler
Definition: Thread_Manager.h:69
U32 HighPriorityThreadTimerPrescaler
Definition: Thread_Manager.h:66
VOID Initialize(DOUBLE ClockFrequency)
Definition: Thread_Manager.cpp:238
U32 NormalPriorityThreadTimerPrescaler
Definition: Thread_Manager.h:67
VOID SwitchImmediate()
Definition: Thread_Manager.cpp:510
VOID Destroy(TThread *Thread)
Definition: Thread_Manager.cpp:433