AJA NTV2 SDK  18.0.0.2122
NTV2 SDK 18.0.0.2122
thread.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 // include the system dependent implementation class
9 #if defined(AJA_WINDOWS)
11 #elif defined(AJA_LINUX)
13 #elif defined(AJA_MAC)
15 #elif defined(AJA_BAREMETAL)
17 #endif
18 #include "ajabase/system/debug.h"
20 
21 
23 {
24  // create the implementation class
25  mpImpl = new AJAThreadImpl(this);
26 }
27 
29 {
30  if(mpImpl)
31  {
32  delete mpImpl;
33  mpImpl = NULL;
34  }
35 }
36 
39 {
41  bool loop = true;
42 
43  // initialize the thread
44  status = ThreadInit();
45 
46  if (AJA_SUCCESS(status))
47  {
48  // call the loop until done
49  while (loop && !Terminate())
50  {
51  loop = ThreadLoop();
52  }
53 
54  // flush the thread when done
55  status = ThreadFlush();
56  }
57 
58  return status;
59 }
60 
61 
64 {
65  // default do nothing
66  return AJA_STATUS_SUCCESS;
67 }
68 
69 
70 bool
72 {
73  // default wait a bit
74  AJA_REPORT(0, AJA_DebugSeverity_Warning, "AJAThread::ThreadLoop looping doing nothing");
75  AJATime::Sleep(1000);
76  return AJA_STATUS_TRUE;
77 }
78 
79 
82 {
83  // default do nothing
84  return AJA_STATUS_SUCCESS;
85 }
86 
87 
88 // interface to the implementation class
89 
92 {
93  if(mpImpl)
94  return mpImpl->Start();
95  return AJA_STATUS_FAIL;
96 }
97 
98 
99 AJAStatus
100 AJAThread::Stop(uint32_t timeout)
101 {
102  if(mpImpl)
103  return mpImpl->Stop(timeout);
104  return AJA_STATUS_SUCCESS;
105 }
106 
107 AJAStatus
108 AJAThread::Kill(uint32_t exitCode)
109 {
110  if(mpImpl)
111  return mpImpl->Kill(exitCode);
112  return AJA_STATUS_SUCCESS;
113 }
114 
115 bool
117 {
118  if(mpImpl)
119  return mpImpl->Active();
120  return false;
121 }
122 
123 bool
125 {
126  if(mpImpl)
127  return mpImpl->IsCurrentThread();
128  return false;
129 }
130 
131 
132 AJAStatus
134 {
135  if(mpImpl)
136  return mpImpl->SetPriority(threadPriority);
137  return AJA_STATUS_FAIL;
138 }
139 
140 
141 AJAStatus
143 {
144  if(mpImpl)
145  return mpImpl->GetPriority(pThreadPriority);
146  return AJA_STATUS_FAIL;
147 }
148 
149 
150 AJAStatus
152 {
153  if(mpImpl)
154  return mpImpl->SetRealTime(policy, priority);
155  return AJA_STATUS_FAIL;
156 }
157 
158 
159 bool
161 {
162  if(mpImpl)
163  return mpImpl->mTerminate;
164  return true;
165 }
166 
167 
168 AJAStatus
169 AJAThread::Attach(AJAThreadFunction* pThreadFunction, void* pUserContext)
170 {
171  if(mpImpl)
172  return mpImpl->Attach(pThreadFunction, pUserContext);
173  return AJA_STATUS_FAIL;
174 }
175 
177  return mpImpl ? mpImpl->SetThreadName(name) : AJA_STATUS_FAIL;
178 }
179 
181 {
183 }
#define AJA_SUCCESS(_status_)
Definition: types.h:372
AJAStatus Start()
Definition: threadimpl.cpp:116
virtual AJAStatus SetThreadName(const char *name)
Definition: thread.cpp:176
virtual bool IsCurrentThread()
Definition: thread.cpp:124
virtual AJAStatus ThreadFlush()
Definition: thread.cpp:81
#define NULL
virtual ~AJAThread()
Definition: thread.cpp:28
AJAThreadPriority
Definition: thread.h:39
AJAStatus
Definition: types.h:380
Declares the AJADebug class.
bool mTerminate
Definition: threadimpl.h:58
static uint64_t GetThreadId()
Definition: threadimpl.cpp:685
AJAThread()
Definition: thread.cpp:22
Declares the AJATime class.
virtual AJAStatus SetPriority(AJAThreadPriority priority)
Definition: thread.cpp:133
virtual AJAStatus Start()
Definition: thread.cpp:91
AJAStatus Attach(AJAThreadFunction *pThreadFunction, void *pUserContext)
Definition: threadimpl.cpp:566
virtual AJAStatus Kill(uint32_t exitCode)
Definition: thread.cpp:108
bool IsCurrentThread()
Definition: threadimpl.cpp:406
virtual AJAStatus SetRealTime(AJAThreadRealTimePolicy policy, int priority)
Definition: thread.cpp:151
virtual bool Active()
Definition: thread.cpp:116
AJAThreadRealTimePolicy
Definition: thread.h:50
void AJAThreadFunction(AJAThread *pThread, void *pContext)
Definition: thread.h:22
Declares the AJAThreadImpl class.
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
Declares the AJAThreadImpl class.
#define AJA_REPORT(_index_, _severity_, _format_,...)
Definition: debug.h:117
AJAStatus GetPriority(AJAThreadPriority *pThreadPriority)
Definition: threadimpl.cpp:504
virtual AJAStatus ThreadInit()
Definition: thread.cpp:63
virtual bool Terminate()
Definition: thread.cpp:160
Declares the AJAThreadImpl class.
virtual AJAStatus Attach(AJAThreadFunction *pThreadFunction, void *pUserContext)
Definition: thread.cpp:169
virtual AJAStatus Stop(uint32_t timeout=0xffffffff)
Definition: thread.cpp:100
virtual AJAStatus GetPriority(AJAThreadPriority *pPriority)
Definition: thread.cpp:142
AJAStatus SetPriority(AJAThreadPriority threadPriority)
Definition: threadimpl.cpp:425
AJAStatus Kill(uint32_t exitCode)
Definition: threadimpl.cpp:332
virtual bool ThreadLoop()
Definition: thread.cpp:71
AJAStatus SetThreadName(const char *name)
Definition: threadimpl.cpp:672
AJAStatus SetRealTime(AJAThreadRealTimePolicy policy, int priority)
Definition: threadimpl.cpp:522
virtual AJAStatus ThreadRun()
Definition: thread.cpp:38
static uint64_t GetThreadId()
Definition: thread.cpp:180
AJAStatus Stop(uint32_t timeout=0xffffffff)
Definition: threadimpl.cpp:208