AJA NTV2 SDK  17.1.1.1245
NTV2 SDK 17.1.1.1245
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 }
AJAThreadImpl::IsCurrentThread
bool IsCurrentThread()
Definition: threadimpl.cpp:406
AJAThread::SetRealTime
virtual AJAStatus SetRealTime(AJAThreadRealTimePolicy policy, int priority)
Definition: thread.cpp:151
AJAThread::IsCurrentThread
virtual bool IsCurrentThread()
Definition: thread.cpp:124
AJAThread::ThreadInit
virtual AJAStatus ThreadInit()
Definition: thread.cpp:63
AJA_DebugSeverity_Warning
@ AJA_DebugSeverity_Warning
Definition: debugshare.h:29
NULL
#define NULL
Definition: ntv2caption608types.h:19
AJA_STATUS_SUCCESS
@ AJA_STATUS_SUCCESS
Definition: types.h:381
AJAThreadImpl::GetThreadId
static uint64_t GetThreadId()
Definition: threadimpl.cpp:685
AJAThreadImpl::SetThreadName
AJAStatus SetThreadName(const char *name)
Definition: threadimpl.cpp:672
AJAThread::Attach
virtual AJAStatus Attach(AJAThreadFunction *pThreadFunction, void *pUserContext)
Definition: thread.cpp:169
systemtime.h
Declares the AJATime class.
AJA_STATUS_TRUE
@ AJA_STATUS_TRUE
Definition: types.h:380
AJAThread::~AJAThread
virtual ~AJAThread()
Definition: thread.cpp:28
AJAThread::GetThreadId
static uint64_t GetThreadId()
Definition: thread.cpp:180
AJAThreadPriority
AJAThreadPriority
Definition: thread.h:39
AJAThreadImpl
Definition: threadimpl.h:18
AJAThread::Kill
virtual AJAStatus Kill(uint32_t exitCode)
Definition: thread.cpp:108
AJAThread::Active
virtual bool Active()
Definition: thread.cpp:116
AJAStatus
AJAStatus
Definition: types.h:378
AJAThreadImpl::Kill
AJAStatus Kill(uint32_t exitCode)
Definition: threadimpl.cpp:332
AJATime::Sleep
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
threadimpl.h
Declares the AJAThreadImpl class.
AJA_STATUS_FAIL
@ AJA_STATUS_FAIL
Definition: types.h:382
AJA_SUCCESS
#define AJA_SUCCESS(_status_)
Definition: types.h:370
AJA_REPORT
#define AJA_REPORT(_index_, _severity_, _format_,...)
Definition: debug.h:117
threadimpl.h
Declares the AJAThreadImpl class.
AJAThread::ThreadRun
virtual AJAStatus ThreadRun()
Definition: thread.cpp:38
AJAThreadImpl::Active
bool Active()
Definition: threadimpl.cpp:386
AJAThread::Stop
virtual AJAStatus Stop(uint32_t timeout=0xffffffff)
Definition: thread.cpp:100
AJAThreadImpl::mTerminate
bool mTerminate
Definition: threadimpl.h:58
AJAThreadRealTimePolicy
AJAThreadRealTimePolicy
Definition: thread.h:50
threadimpl.h
Declares the AJAThreadImpl class.
AJAThread::SetThreadName
virtual AJAStatus SetThreadName(const char *name)
Definition: thread.cpp:176
AJAThreadImpl::Stop
AJAStatus Stop(uint32_t timeout=0xffffffff)
Definition: threadimpl.cpp:208
threadimpl.h
AJAThread::AJAThreadFunction
void AJAThreadFunction(AJAThread *pThread, void *pContext)
Definition: thread.h:22
AJAThread::Terminate
virtual bool Terminate()
Definition: thread.cpp:160
AJAThread::ThreadLoop
virtual bool ThreadLoop()
Definition: thread.cpp:71
AJAThread::GetPriority
virtual AJAStatus GetPriority(AJAThreadPriority *pPriority)
Definition: thread.cpp:142
AJAThread::SetPriority
virtual AJAStatus SetPriority(AJAThreadPriority priority)
Definition: thread.cpp:133
AJAThread::AJAThread
AJAThread()
Definition: thread.cpp:22
AJAThreadImpl::Start
AJAStatus Start()
Definition: threadimpl.cpp:116
AJAThreadImpl::SetPriority
AJAStatus SetPriority(AJAThreadPriority threadPriority)
Definition: threadimpl.cpp:425
AJAThread::Start
virtual AJAStatus Start()
Definition: thread.cpp:91
AJAThreadImpl::Attach
AJAStatus Attach(AJAThreadFunction *pThreadFunction, void *pUserContext)
Definition: threadimpl.cpp:566
AJAThread::ThreadFlush
virtual AJAStatus ThreadFlush()
Definition: thread.cpp:81
AJAThreadImpl::GetPriority
AJAStatus GetPriority(AJAThreadPriority *pThreadPriority)
Definition: threadimpl.cpp:504
debug.h
Declares the AJADebug class.
AJAThreadImpl::SetRealTime
AJAStatus SetRealTime(AJAThreadRealTimePolicy policy, int priority)
Definition: threadimpl.cpp:522