AJA NTV2 SDK  17.0.1.1246
NTV2 SDK 17.0.1.1246
threadimpl.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #include "ajabase/system/debug.h"
9 #include <errno.h>
10 #include <sched.h>
11 #include <signal.h>
12 #include <sys/time.h>
13 #include <sys/resource.h>
14 #include <sys/syscall.h>
15 #include <sys/prctl.h>
16 #include <unistd.h>
17 #include <string.h>
18 
19 static const size_t STACK_SIZE = 1024 * 1024;
20 
21 bool is_pthread_alive(pthread_t thread)
22 {
23 #if 1
24  // since this is a Linux impl use the non portable, non blocking pthread_tryjoin_np.
25  // If the thread is alive a non zero value is returned
26  // NOTE: if this impl is ever changed to not be PTHREAD_CREATE_JOINABLE this will not work
27  void* exitValue;
28  if (pthread_tryjoin_np(thread, &exitValue) != 0)
29  return true;
30 #else
31  // This way no longer works with modern glibc
32  // seen failures with versions: 2.34 & 2.35
33  // seen success with versions: 2.31 and earlier
34  //
35  // with zero, no signal sent to thread, it's only checked for validity
36  if (!pthread_kill(thread, 0))
37  return true;
38 #endif
39 
40  return false;
41 }
42 
43 AJAThreadImpl::AJAThreadImpl(AJAThread* pThreadContext) :
44  mpThreadContext(pThreadContext),
45  mThread(0),
46  mTid(0),
47  mPriority(AJA_ThreadPriority_Normal),
48  mThreadFunc(0),
49  mpUserContext(0),
50  mThreadStarted(false),
51  mTerminate(false),
52  mExiting(false)
53 {
54  int rc = pthread_mutex_init(&mStartMutex, 0);
55  if (rc)
56  {
57  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThreadImpl(%p) start mutex init reported error %d", mpThreadContext, rc);
58  }
59 
60  rc = pthread_cond_init(&mStartCond, 0);
61  if (rc)
62  {
63  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThreadImpl(%p) start cond init reported error %d", mpThreadContext, rc);
64  }
65 
66  rc = pthread_mutex_init(&mExitMutex, 0);
67  if (rc)
68  {
69  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThreadImpl(%p) exit mutex init reported error %d", mpThreadContext, rc);
70  }
71 
72  rc = pthread_cond_init(&mExitCond, 0);
73  if (rc)
74  {
75  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThreadImpl(%p) exit cond init reported error %d", mpThreadContext, rc);
76  }
77 }
78 
79 
81 {
82  Stop();
83 
84  int rc = pthread_mutex_destroy(&mStartMutex);
85  if (rc)
86  {
87  AJA_REPORT(0, AJA_DebugSeverity_Error, "~AJAThreadImpl(%p) start mutex destroy reported error %d", mpThreadContext, rc);
88  }
89 
90  rc = pthread_cond_destroy(&mStartCond);
91  if (rc)
92  {
93  AJA_REPORT(0, AJA_DebugSeverity_Error, "~AJAThreadImpl(%p) start cond destroy reported error %d", mpThreadContext, rc);
94  }
95 
96  rc = pthread_mutex_destroy(&mExitMutex);
97  if (rc)
98  {
99  AJA_REPORT(0, AJA_DebugSeverity_Error, "~AJAThreadImpl(%p) exit mutex destroy reported error %d", mpThreadContext, rc);
100  }
101 
102  rc = pthread_cond_destroy(&mExitCond);
103  if (rc)
104  {
105  AJA_REPORT(0, AJA_DebugSeverity_Error, "~AJAThreadImpl(%p) exit cond destroy reported error %d", mpThreadContext, rc);
106  }
107 }
108 
109 AJAStatus
111 {
112  AJAAutoLock lock(&mLock);
113 
114  // return success if thread is already running
115  if (Active())
116  {
117  return AJA_STATUS_SUCCESS;
118  }
119 
120  // Windows version currently uses the default stack size
121  // The docs say this is 1MB, so give our threads the same stack size
122  pthread_attr_t attr;
123  int rc = 0;
124  rc |= pthread_attr_init(&attr);
125  rc |= pthread_attr_setstacksize(&attr, STACK_SIZE);
126  rc |= pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
127  if (rc)
128  {
129  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThreadImpl::Start(%p) error setting thread attributes", mpThreadContext);
130  mThread = 0;
131  return AJA_STATUS_FAIL;
132  }
133 
134  mTerminate = false;
135  mExiting = false;
136 
137  // we're going to create the thread, then block until it tells us it's alive
138  rc = pthread_mutex_lock(&mStartMutex);
139  if (rc)
140  {
141  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThreadImpl::Start(%p) error %d locking start mutex", mpThreadContext, rc);
142  return AJA_STATUS_FAIL;
143  }
144 
145  // create the thread
146  mThreadStarted = false;
147 
148  rc = pthread_create(&mThread, &attr, ThreadProcStatic, this);
149  if (rc)
150  {
151  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThreadImpl::Start(%p) error %d creating thread", mpThreadContext, rc);
152  mThread = 0;
153  return AJA_STATUS_FAIL;
154  }
155 
156  // wait until the new thread signals us that it's alive (and has logged its thread ID)
157  // ToDo: add a timeout? how do we respond if the thread DOESN'T come up?
158  AJAStatus status = AJA_STATUS_SUCCESS;
159 
160  while (!mThreadStarted)
161  {
162  rc = pthread_cond_wait(&mStartCond, &mStartMutex);
163 
164  if (rc)
165  {
166  status = AJA_STATUS_FAIL;
168  "AJAThread(%p)::Start pthread_cond_wait returned error %d",
169  mpThreadContext, rc);
170  break;
171  }
172  }
173 
174  rc = pthread_mutex_unlock(&mStartMutex);
175  if (rc)
176  {
177  status = AJA_STATUS_FAIL;
179  "AJAThread(%p)::Start error %d unlocking start mutex",
180  mpThreadContext, rc);
181  }
182 
183 
184 #if 0 // This should be set within the running thread itself if a dynamic change
185  // in priority is desired. This will fail in a daemon invocation.
186 
187  // Now that the new thread is up and running and has reported its
188  // thread ID, set the thread priority
189  if ( AJA_SUCCESS(status) )
190  status = SetPriority(mPriority);
191 #endif
192 
193  return status;
194 }
195 
196 
197 AJAStatus
198 AJAThreadImpl::Stop(uint32_t timeout)
199 {
200  AJAAutoLock lock(&mLock);
201  AJAStatus returnStatus = AJA_STATUS_SUCCESS;
202 
203  // return success if the thread is already stopped
204  if (!Active())
205  {
206  return AJA_STATUS_SUCCESS;
207  }
208 
209  // wait for thread to stop
210  int rc = pthread_mutex_lock(&mExitMutex);
211  if (rc)
212  {
213  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThreadImpl::Stop(%p) error %d locking exit mutex", mpThreadContext, rc);
214  return AJA_STATUS_FAIL;
215  }
216 
217  // calculate how long to wait
218  struct timespec ts;
220 
221  if (timeout == 0xffffffff)
222  {
223  ts.tv_sec += 60 * 60 * 24 * 365; // A year is infinite enough
224  }
225  else
226  {
227  // Calculates the non-second portion of the timeout
228  // to nanoseconds.
229  uint32_t nsec = ((timeout % 1000) * 1000000);
230 
231  // Add the current nanosecond count to the result
232  nsec += ts.tv_nsec;
233 
234  struct timespec ts1;
235  ts1 = ts;
236 
237  // The addition of the two nanosecond values may wrap to
238  // another second, so note that; but our nsec portion will
239  // always be less than a second. Finally, create the
240  // absolute time during which the timeout will lapse.
241  ts.tv_sec += (timeout / 1000) + (nsec / 1000000000);
242  ts.tv_nsec = (nsec % 1000000000);
243  }
244 
245  // signal thread to stop
246  mTerminate = true;
247 
248  // loop until signaled or timed out
249  do
250  {
251  if (mExiting == false)
252  {
253  rc = pthread_cond_timedwait(&mExitCond, &mExitMutex, &ts);
254  if (rc)
255  {
256  returnStatus = AJA_STATUS_FAIL;
257  AJA_REPORT(
258  0,
260  "AJAThread(%p)::Stop pthread_cond_timedwait returned error %d",
261  mpThreadContext, rc);
262 
263  // non-timeout errors release the mutex by themselves
264  if (rc == ETIMEDOUT)
265  {
266  rc = pthread_mutex_unlock(&mExitMutex);
267  if (rc)
268  {
269  AJA_REPORT(
270  0,
272  "AJAThread(%p)::Stop error %d unlocking timeout mutex",
273  mpThreadContext, rc);
274  }
275  }
276  break;
277  }
278  }
279 
280  // deal with spurious wakeups here
281  if (!mExiting)
282  continue; // the thread hasn't left its loop, so wait some more
283  else
284  {
285  rc = pthread_mutex_unlock(&mExitMutex);
286  if (rc)
287  {
288  returnStatus = AJA_STATUS_FAIL;
289  AJA_REPORT(
290  0,
292  "AJAThread(%p)::Stop error %d unlocking exit mutex",
293  mpThreadContext, rc);
294  }
295  break;
296  }
297  } while (rc == 0);
298 
299 
300  // close thread handle
301  void* exitValue;
302  rc = pthread_join(mThread, &exitValue);
303  if( rc )
304  {
305  returnStatus = AJA_STATUS_FAIL;
306  AJA_REPORT(
307  0,
309  "AJAThread(%p)::Stop error %d from pthread_join",
310  mpThreadContext, rc);
311  }
312  mThread = 0;
313 
314  return returnStatus;
315 }
316 
317 AJAStatus
318 AJAThreadImpl::Kill(uint32_t exitCode)
319 {
320  AJA_UNUSED(exitCode);
321 
322  AJAAutoLock lock(&mLock);
323  AJAStatus returnStatus = AJA_STATUS_SUCCESS;
324 
325  // If the thread doesn't exist, consider the Kill successful
327  return returnStatus;
328 
329  // Try to make the thread as killable as possible
330  int rc = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
331  if( rc )
332  {
333  returnStatus = AJA_STATUS_FAIL;
334  AJA_REPORT(
335  0,
337  "AJAThread(%p)::Kill error %d from pthread_setcancelstate",
338  mpThreadContext, rc);
339  }
340  rc = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
341  if( rc )
342  {
343  returnStatus = AJA_STATUS_FAIL;
344  AJA_REPORT(
345  0,
347  "AJAThread(%p)::Kill error %d from pthread_setcanceltype",
348  mpThreadContext, rc);
349  }
350 
351  // This should kill the thread, but there are no guarantees
352  rc = pthread_cancel(mThread);
353  if( rc )
354  {
355  returnStatus = AJA_STATUS_FAIL;
356  AJA_REPORT(
357  0,
359  "AJAThread(%p)::Kill error %d from pthread_cancel",
360  mpThreadContext, rc);
361  }
362 
363  return returnStatus;
364 }
365 
366 
367 bool
369 {
370  // if no handle thread is not active
371  if (mThread == 0)
372  {
373  return false;
374  }
375 
377  return true;
378 
379  // the thread has terminated, so clear the handle
380  mThread = 0;
381 
382  return false;
383 }
384 
385 bool
387 {
388  if(mThread == 0)
389  {
390  return false;
391  }
392 
393  if( pthread_equal(mThread, pthread_self()) )
394  {
395  return true;
396  }
397 
398  return false;
399 }
400 
401 
402 AJAStatus
404 {
405  AJAAutoLock lock(&mLock);
406 
407  // save priority for starts
408  mPriority = threadPriority;
409 
410  // If thread isn't running, we're done (but we've logged the desired priority for later)
411  if (!Active())
412  return AJA_STATUS_SUCCESS;
413 
414  // If we haven't been able to get a thread ID (thread not running yet?), bail
415  if (mTid == 0) // note: we're assuming PID == 0 never happens in nature...?
416  return AJA_STATUS_FAIL;
417 
418 
419  // If thread is already running, tweak its priority
420  // We're going to mix Realtime priorities (policy == SCHED_FIFO/SCHED_RR) and "standard" round-robin priorities
421  // (policy == SCHED_OTHER) in one API...
422  bool bRTPriority = false; //
423  int newPriority = 0; // "nice" priority used by setpriority() when bRTPriority = false, or RT priority used by sched_setscheduler() when bRTPriority = true
424 
425  switch (threadPriority)
426  {
428  bRTPriority = false; // use setpriority()
429  newPriority = 0; // -20 to +19, standard "nice" priority
430  break;
432  bRTPriority = false; // use setpriority()
433  newPriority = 10; // positive "nice" values have LOWER priority
434  break;
436  bRTPriority = false; // use setpriority()
437  newPriority = -10; // negative "nice" values have HIGHER priority
438  break;
440  bRTPriority = false; // use setpriority()
441  newPriority = -5; // negative "nice" values have HIGHER priority
442  break;
444  bRTPriority = true; // use sched_setscheduler()
445  newPriority = 90; // 1 - 99 (higher values = higher priority)
446  break;
448  default:
449  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::SetPriority: bad thread priority %d", mpThreadContext, threadPriority);
450  return AJA_STATUS_RANGE;
451  }
452 
453  // first, set (or unset) the RT priority
454  struct sched_param newParam;
455  newParam.sched_priority = (bRTPriority ? newPriority : 0); // if we're not using RT Priority, reset to SCHED_OTHER and sched_priority = 0
456  int newPolicy = (bRTPriority ? SCHED_RR : SCHED_OTHER);
457  int rc = pthread_setschedparam(mThread, newPolicy, &newParam);
458  if (rc != 0)
459  {
460  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::SetPriority: error %d setting sched param: policy = %d, priority = %d\n", mpThreadContext, rc, newPolicy, newParam.sched_priority);
461  return AJA_STATUS_FAIL;
462  }
463 
464  // now set the standard ("nice") priority
465  int newNice = (bRTPriority ? 0 : newPriority); // if we're using RT Priority (SCHED_RR or SCHED_FF), reset "nice" level to zero
466  rc = setpriority(PRIO_PROCESS, mTid, newNice);
467  if (errno != 0)
468  {
469  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::SetPriority: error %d setting nice level: %d\n", mpThreadContext, rc, newNice);
470  return AJA_STATUS_FAIL;
471  }
472 
473  return AJA_STATUS_SUCCESS;
474 }
475 
476 
477 AJAStatus
479 {
480  if (pThreadPriority == NULL)
481  {
482  return AJA_STATUS_INITIALIZE;
483  }
484 
485  *pThreadPriority = mPriority;
486 
487  return AJA_STATUS_SUCCESS;
488 }
489 
490 
491 AJAStatus
493 {
494  int pval = 0;
495  switch(policy)
496  {
498  pval = SCHED_FIFO;
499  break;
501  pval = SCHED_RR;
502  break;
503  default:
504  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::SetRealTime: bad thread policy %d", mpThreadContext, policy);
505  return AJA_STATUS_RANGE;
506  }
507 
508  for(int i = 0; i < 30; i++)
509  {
510  if(!Active())
511  {
512  usleep(1000);
513  continue;
514  }
515  struct sched_param newParam;
516  memset(&newParam, 0, sizeof(newParam));
517  newParam.sched_priority = priority;
518  int rc = pthread_setschedparam(mThread, pval, &newParam);
519  if (rc != 0)
520  {
521  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::SetRealTime: error %d setting sched param: policy = %d, priority = %d\n", mpThreadContext, rc, pval, newParam.sched_priority);
522  return AJA_STATUS_FAIL;
523  }
524  return AJA_STATUS_SUCCESS;
525  }
526  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::SetRealTime: Failed to set realtime thread is not running\n", mpThreadContext);
527  return AJA_STATUS_FAIL;
528 }
529 
530 
531 AJAStatus
532 AJAThreadImpl::Attach(AJAThreadFunction* pThreadFunction, void* pUserContext)
533 {
534  // remember the users thread function
535  mThreadFunc = pThreadFunction;
536  mpUserContext = pUserContext;
537 
538  return AJA_STATUS_SUCCESS;
539 }
540 
541 
542 void*
543 AJAThreadImpl::ThreadProcStatic(void* pThreadImplContext)
544 {
545  // this function is called when the thread starts
546  AJAThreadImpl* pThreadImpl = static_cast<AJAThreadImpl*>(pThreadImplContext);
547  AJA_ASSERT(pThreadImpl != NULL);
548  if (pThreadImpl == NULL)
549  {
550  return (void*)0;
551  }
552 
553  // Who am I? We need the thread ID (TID) in order to set thread scheduler priorities
554 // pid_t myTid = gettid(); // in theory we could make this call, but Glibc doesn't support it
555  errno = 0; // so instead we do this (ick...)
556  pid_t myTid = syscall( SYS_gettid );
557  if (errno == 0) // theoretically gettid() cannot fail, so by extension syscall(SYS_gettid) can't either...?
558  pThreadImpl->mTid = myTid;
559 
560 
561  // signal parent we've started
562  int rc = pthread_mutex_lock(&pThreadImpl->mStartMutex);
563  if (rc)
564  {
565  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::ThreadProcStatic error %d locking start mutex", pThreadImpl->mpThreadContext, rc);
566  return (void*)0;
567  }
568 
569  pThreadImpl->mThreadStarted = true;
570 
571  rc = pthread_cond_signal(&pThreadImpl->mStartCond);
572  if (rc)
573  {
574  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::ThreadProcStatic error %d signaling start cond variable", pThreadImpl->mpThreadContext, rc);
575  return (void*)0;
576  }
577  rc = pthread_mutex_unlock(&pThreadImpl->mStartMutex);
578  if (rc)
579  {
580  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::ThreadProcStatic error %d unlocking start mutex", pThreadImpl->mpThreadContext, rc);
581  return (void*)0;
582  }
583 
584 
585  // call the thread worker function
586  try
587  {
588  // if user specified function call it
589  if (pThreadImpl->mThreadFunc != NULL)
590  {
591  (*pThreadImpl->mThreadFunc)(pThreadImpl->mpThreadContext, pThreadImpl->mpUserContext);
592  }
593  // otherwise call the virtual function
594  else
595  {
596  pThreadImpl->mpThreadContext->ThreadRun();
597  }
598  }
599  catch(...)
600  {
601  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::ThreadProcStatic exception in thread function", pThreadImpl->mpThreadContext);
602  return (void*)0;
603  }
604 
605  // signal parent we're exiting
606  pThreadImpl->mExiting = true;
607 
608  rc = pthread_mutex_lock(&pThreadImpl->mExitMutex);
609  if (rc)
610  {
611  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::ThreadProcStatic error %d locking exit mutex", pThreadImpl->mpThreadContext, rc);
612  return (void*)0;
613  }
614  rc = pthread_cond_signal(&pThreadImpl->mExitCond);
615  if (rc)
616  {
617  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::ThreadProcStatic error %d signaling cond variable", pThreadImpl->mpThreadContext, rc);
618  return (void*)0;
619  }
620  rc = pthread_mutex_unlock(&pThreadImpl->mExitMutex);
621  if (rc)
622  {
623  AJA_REPORT(0, AJA_DebugSeverity_Error, "AJAThread(%p)::ThreadProcStatic error %d unlocking exit mutex", pThreadImpl->mpThreadContext, rc);
624  return (void*)0;
625  }
626 
627  return (void*)1;
628 }
629 
630 AJAStatus AJAThreadImpl::SetThreadName(const char *name) {
631  int ret = prctl(PR_SET_NAME, (unsigned long)name, 0, 0);
632  if(ret == -1) {
633  AJA_REPORT(0, AJA_DebugSeverity_Error, "Failed to set thread name to %s", name);
634  return AJA_STATUS_FAIL;
635  }
636  return AJA_STATUS_SUCCESS;
637 }
638 
640 {
641  errno = 0;
642  pid_t tid = syscall(SYS_gettid);
643  if (errno == 0)
644  return uint64_t(tid);
645  else
646  return 0;
647 }
AJAThreadImpl::IsCurrentThread
bool IsCurrentThread()
Definition: threadimpl.cpp:406
AJA_ThreadPriority_High
@ AJA_ThreadPriority_High
Definition: thread.h:44
AJAThreadImpl::mPriority
AJAThreadPriority mPriority
Definition: threadimpl.h:49
NULL
#define NULL
Definition: ntv2caption608types.h:19
AJAThreadImpl::mpUserContext
void * mpUserContext
Definition: threadimpl.h:51
AJA_STATUS_SUCCESS
@ AJA_STATUS_SUCCESS
Definition: types.h:368
AJAThreadImpl::GetThreadId
static uint64_t GetThreadId()
Definition: threadimpl.cpp:685
AJAThreadImpl::SetThreadName
AJAStatus SetThreadName(const char *name)
Definition: threadimpl.cpp:672
AJA_DebugSeverity_Error
@ AJA_DebugSeverity_Error
Definition: debugshare.h:28
AJAThreadImpl::mThreadFunc
AJAThreadFunction * mThreadFunc
Definition: threadimpl.h:50
AJAThreadImpl::~AJAThreadImpl
virtual ~AJAThreadImpl()
Definition: threadimpl.cpp:84
AJAThreadImpl::mThread
pthread_t mThread
Definition: threadimpl.h:47
AJAThreadPriority
AJAThreadPriority
Definition: thread.h:39
AJA_UNUSED
#define AJA_UNUSED(_x_)
Definition: types.h:411
AJAThreadImpl
Definition: threadimpl.h:18
AJA_ThreadPriority_TimeCritical
@ AJA_ThreadPriority_TimeCritical
Definition: thread.h:45
AJA_ThreadRealTimePolicyFIFO
@ AJA_ThreadRealTimePolicyFIFO
Definition: thread.h:52
AJAThread
Definition: thread.h:69
AJAThreadImpl::mLock
AJALock mLock
Definition: threadimpl.h:52
AJA_ThreadRealTimePolicyRoundRobin
@ AJA_ThreadRealTimePolicyRoundRobin
Definition: thread.h:53
STACK_SIZE
static const size_t STACK_SIZE
Definition: threadimpl.cpp:19
AJAStatus
AJAStatus
Definition: types.h:365
AJA_ThreadPriority_Unknown
@ AJA_ThreadPriority_Unknown
Definition: thread.h:41
CLOCK_REALTIME
#define CLOCK_REALTIME
Definition: pthreadsextra.h:21
AJAThreadImpl::Kill
AJAStatus Kill(uint32_t exitCode)
Definition: threadimpl.cpp:332
AJAThreadImpl::mExitCond
pthread_cond_t mExitCond
Definition: threadimpl.h:61
threadimpl.h
Declares the AJAThreadImpl class.
AJA_STATUS_FAIL
@ AJA_STATUS_FAIL
Definition: types.h:369
AJA_ThreadPriority_Normal
@ AJA_ThreadPriority_Normal
Definition: thread.h:43
AJA_SUCCESS
#define AJA_SUCCESS(_status_)
Definition: types.h:357
AJA_REPORT
#define AJA_REPORT(_index_, _severity_, _format_,...)
Definition: debug.h:117
AJAThread::ThreadRun
virtual AJAStatus ThreadRun()
Definition: thread.cpp:38
AJAThreadImpl::mTid
pid_t mTid
Definition: threadimpl.h:48
AJAThreadImpl::mStartCond
pthread_cond_t mStartCond
Definition: threadimpl.h:56
AJAThreadImpl::Active
bool Active()
Definition: threadimpl.cpp:386
AJAThreadImpl::mStartMutex
pthread_mutex_t mStartMutex
Definition: threadimpl.h:55
AJA_STATUS_RANGE
@ AJA_STATUS_RANGE
Definition: types.h:372
AJAAutoLock
Definition: lock.h:91
AJA_STATUS_INITIALIZE
@ AJA_STATUS_INITIALIZE
Definition: types.h:373
AJAThreadImpl::mTerminate
bool mTerminate
Definition: threadimpl.h:58
false
#define false
Definition: ntv2devicefeatures.h:25
AJA_ThreadPriority_AboveNormal
@ AJA_ThreadPriority_AboveNormal
Definition: thread.h:46
AJAThreadImpl::mThreadStarted
bool mThreadStarted
Definition: threadimpl.h:54
AJAThreadRealTimePolicy
AJAThreadRealTimePolicy
Definition: thread.h:50
AJAThreadImpl::mExitMutex
pthread_mutex_t mExitMutex
Definition: threadimpl.h:60
AJA_ThreadPriority_Low
@ AJA_ThreadPriority_Low
Definition: thread.h:42
AJAThreadImpl::ThreadProcStatic
static void * ThreadProcStatic(void *pThreadImplContext)
Definition: threadimpl.cpp:581
AJAThreadImpl::AJAThreadImpl
AJAThreadImpl(AJAThread *pThreadContext)
Definition: threadimpl.cpp:45
AJAThreadImpl::Stop
AJAStatus Stop(uint32_t timeout=0xffffffff)
Definition: threadimpl.cpp:208
AJAThread::AJAThreadFunction
void AJAThreadFunction(AJAThread *pThread, void *pContext)
Definition: thread.h:22
AJAThreadImpl::mpThreadContext
AJAThread * mpThreadContext
Definition: threadimpl.h:46
AJA_ASSERT
#define AJA_ASSERT(_expression_)
Definition: debug.h:113
AJAThreadImpl::Start
AJAStatus Start()
Definition: threadimpl.cpp:116
is_pthread_alive
bool is_pthread_alive(pthread_t thread)
Definition: threadimpl.cpp:21
clock_gettime
int clock_gettime(clockid_t clk_id, struct timespec *tp)
Definition: pthreadsextra.cpp:12
AJAThreadImpl::SetPriority
AJAStatus SetPriority(AJAThreadPriority threadPriority)
Definition: threadimpl.cpp:425
AJAThreadImpl::Attach
AJAStatus Attach(AJAThreadFunction *pThreadFunction, void *pUserContext)
Definition: threadimpl.cpp:566
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
AJAThreadImpl::mExiting
bool mExiting
Definition: threadimpl.h:59