This is Unofficial EPICS BASE Doxygen Site
osdThread.c File Reference
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <vxWorks.h>
#include <taskLib.h>
#include <taskVarLib.h>
#include <sysLib.h>
#include "errlog.h"
#include "ellLib.h"
#include "epicsThread.h"
#include "cantProceed.h"
#include "epicsAssert.h"
#include "vxLib.h"
#include "epicsExit.h"
+ Include dependency graph for osdThread.c:

Go to the source code of this file.

Classes

struct  epicsThreadOSD
 

Macros

#define _VSB_CONFIG_FILE   <../lib/h/config/vsbConfig.h>
 
#define ALLOT_JOIN(tid)
 
#define ARCH_STACK_FACTOR   1
 
#define ID_LIST_CHUNK   512
 
#define THREAD_SEM_FLAGS   (SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY)
 
#define EPICS_THREAD_ONCE_DONE   &threadOnceComplete
 
#define PREPARE_JOIN(tid, joinable)
 
#define AWAIT_JOIN(tid)
 
#define TASK_FLAGS   (VX_FP_TASK)
 

Functions

LIBCOM_API void osdThreadHooksRun (epicsThreadId id)
 
void atRebootRegister (void)
 
void epicsThreadRealtimeLock (void)
 
unsigned int epicsThreadGetStackSize (epicsThreadStackSizeClass stackSizeClass)
 
void epicsThreadOnce (epicsThreadOnceId *id, void(*func)(void *), void *arg)
 
void epicsThreadEntry (EPICSTHREADFUNC func, void *parm)
 
epicsThreadId epicsThreadCreateOpt (const char *name, EPICSTHREADFUNC funptr, void *parm, const epicsThreadOpts *opts)
 Allocate and start a new OS thread. More...
 
void epicsThreadMustJoin (epicsThreadId id)
 
void epicsThreadSuspendSelf ()
 
void epicsThreadResume (epicsThreadId id)
 
void epicsThreadExitMain (void)
 
unsigned int epicsThreadGetPriority (epicsThreadId id)
 
unsigned int epicsThreadGetPrioritySelf (void)
 
void epicsThreadSetPriority (epicsThreadId id, unsigned int osip)
 
epicsThreadBooleanStatus epicsThreadHighestPriorityLevelBelow (unsigned int priority, unsigned *pPriorityJustBelow)
 
epicsThreadBooleanStatus epicsThreadLowestPriorityLevelAbove (unsigned int priority, unsigned *pPriorityJustAbove)
 
int epicsThreadIsEqual (epicsThreadId id1, epicsThreadId id2)
 
int epicsThreadIsSuspended (epicsThreadId id)
 
void epicsThreadSleep (double seconds)
 Block the calling thread for at least the specified time. More...
 
epicsThreadId epicsThreadGetIdSelf (void)
 
epicsThreadId epicsThreadGetId (const char *name)
 
const char * epicsThreadGetNameSelf (void)
 
void epicsThreadGetName (epicsThreadId id, char *name, size_t size)
 
LIBCOM_API void epicsThreadMap (EPICS_THREAD_HOOK_ROUTINE func)
 
void epicsThreadShowAll (unsigned int level)
 
void epicsThreadShow (epicsThreadId id, unsigned int level)
 
epicsThreadPrivateId epicsThreadPrivateCreate ()
 
void epicsThreadPrivateDelete (epicsThreadPrivateId id)
 
void epicsThreadPrivateSet (epicsThreadPrivateId id, void *pvt)
 
void * epicsThreadPrivateGet (epicsThreadPrivateId id)
 
double epicsThreadSleepQuantum ()
 Query a value approximating the OS timer/scheduler resolution. More...
 
LIBCOM_API int epicsThreadGetCPUs (void)
 

Variables

int taskIdListSize = 0
 

Macro Definition Documentation

#define _VSB_CONFIG_FILE   <../lib/h/config/vsbConfig.h>

Definition at line 15 of file osdThread.c.

#define ALLOT_JOIN (   tid)

Definition at line 49 of file osdThread.c.

#define ARCH_STACK_FACTOR   1

Definition at line 56 of file osdThread.c.

#define AWAIT_JOIN (   tid)

Definition at line 226 of file osdThread.c.

#define EPICS_THREAD_ONCE_DONE   &threadOnceComplete
#define ID_LIST_CHUNK   512

Definition at line 66 of file osdThread.c.

#define PREPARE_JOIN (   tid,
  joinable 
)

Definition at line 225 of file osdThread.c.

#define TASK_FLAGS   (VX_FP_TASK)

Definition at line 251 of file osdThread.c.

#define THREAD_SEM_FLAGS   (SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY)

Definition at line 108 of file osdThread.c.

Function Documentation

void atRebootRegister ( void  )

Definition at line 22 of file atReboot.cpp.

23 {
24  sysAtReboot_t sysAtReboot = (sysAtReboot_t) epicsFindSymbol("_sysAtReboot");
25 
26  if (sysAtReboot) {
27  STATUS status = sysAtReboot(epicsExitCallAtExits);
28 
29  if (status) {
30  printf("atReboot: sysAtReboot returned error %d\n", status);
31  }
32  } else {
33  printf("BSP routine sysAtReboot() not found, epicsExit() will not be\n"
34  "called by reboot. For reduced functionality, call\n"
35  " rebootHookAdd(epicsExitCallAtExits)\n");
36  }
37 }
pvd::Status status
#define printf
Definition: epicsStdio.h:41
int(* sysAtReboot_t)(void(func)(void))
Definition: atReboot.cpp:20
LIBCOM_API void *epicsStdCall epicsFindSymbol(const char *name)
Definition: osdFindSymbol.c:23
LIBCOM_API void epicsExitCallAtExits(void)
Internal routine that runs the registered exit routines.
Definition: epicsExit.c:102
epicsThreadId epicsThreadCreateOpt ( const char *  name,
EPICSTHREADFUNC  funptr,
void *  parm,
const epicsThreadOpts opts 
)

Allocate and start a new OS thread.

Parameters
nameA name describing this thread. Appears in various log and error message.
funptrThe thread main function.
parmPassed to thread main function.
optsModifiers for the new thread, or NULL to use target specific defaults.
Returns
NULL on error

Definition at line 253 of file osdThread.c.

255 {
256  unsigned int stackSize;
257  int tid;
258 
259  epicsThreadInit();
260 
261  if (!opts) {
262  static const epicsThreadOpts opts_default = EPICS_THREAD_OPTS_INIT;
263  opts = &opts_default;
264  }
265  stackSize = opts->stackSize;
266  if (stackSize <= epicsThreadStackBig)
267  stackSize = epicsThreadGetStackSize(stackSize);
268 
269  if (stackSize < 100) {
270  errlogPrintf("epicsThreadCreate %s illegal stackSize %d\n",
271  name, stackSize);
272  return 0;
273  }
274 
275  tid = taskCreate((char *)name,getOssPriorityValue(opts->priority),
276  TASK_FLAGS, stackSize,
277  (FUNCPTR)epicsThreadEntry, (int)funptr, (int)parm,
278  0,0,0,0,0,0,0,0);
279  if (tid == ERROR) {
280  errlogPrintf("epicsThreadCreate %s failure %s\n",
281  name, strerror(errno));
282  return 0;
283  }
284 
285  PREPARE_JOIN(tid, opts->joinable);
286  taskActivate(tid);
287 
288  return (epicsThreadId)tid;
289 }
LIBCOM_API unsigned int epicsStdCall epicsThreadGetStackSize(epicsThreadStackSizeClass stackSizeClass)
Definition: osdThread.c:466
#define PREPARE_JOIN(tid, joinable)
Definition: osdThread.c:225
unsigned int joinable
Definition: epicsThread.h:158
#define TASK_FLAGS
Definition: osdThread.c:251
EPICSTHREADFUNC funptr
Definition: osdThread.c:55
void epicsThreadEntry(EPICSTHREADFUNC func, void *parm)
Definition: osdThread.c:230
unsigned int stackSize
Definition: epicsThread.h:154
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
unsigned int priority
Definition: epicsThread.h:150
#define EPICS_THREAD_OPTS_INIT
Definition: epicsThread.h:167
char * name
Definition: osdThread.c:50
void * parm
Definition: osdThread.c:56
void epicsThreadEntry ( EPICSTHREADFUNC  func,
void *  parm 
)

Definition at line 230 of file osdThread.c.

231 {
232  int tid = taskIdSelf();
233 
234  taskVarAdd(tid,(int *)(char *)&papTSD);
235  papTSD = NULL; /* Initialize for this thread */
236 
238 
239  (*func)(parm);
240 
242  free(papTSD);
243  taskVarDelete(tid,(int *)(char *)&papTSD);
244 
245  AWAIT_JOIN(tid);
246 }
LIBCOM_API void epicsExitCallAtThreadExits(void)
Internal routine that runs the registered thread exit routines.
Definition: epicsExit.c:121
#define NULL
Definition: catime.c:38
LIBCOM_API void osdThreadHooksRun(epicsThreadId id)
void * parm
Definition: osdThread.c:56
#define AWAIT_JOIN(tid)
Definition: osdThread.c:226
void epicsThreadExitMain ( void  )

If the main routine is done but wants to let other threads run it can call this routine. This should be the last call in main, except the final return. On most systems epicsThreadExitMain never returns.This must only be called by the main thread.

Definition at line 353 of file osdThread.c.

354 {
355  errlogPrintf("epicsThreadExitMain was called for vxWorks. Why?\n");
356 }
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API int epicsThreadGetCPUs ( void  )

Return a value approximating the number of threads which this target can run in parallel. This value is advisory.

Returns
>=1

Definition at line 574 of file osdThread.c.

575 {
576  return 1;
577 }
epicsThreadId epicsThreadGetId ( const char *  name)

Attempt to find the first instance of a thread by name.

Returns
An epicsThreadId, or NULL if no such thread is currently running. Note that a non-NULL ID may still be invalid if this call races with thread exit.
Warning
Safe use of this function requires external knowledge that this thread will not return.

Definition at line 442 of file osdThread.c.

443 {
444  int tid = taskNameToId((char *)name);
445  return((epicsThreadId)(tid==ERROR?0:tid));
446 }
char * name
Definition: osdThread.c:50
epicsThreadId epicsThreadGetIdSelf ( void  )

Find an epicsThreadId associated with the current thread. For non-EPICS threads, a new epicsThreadId may be allocated.

Definition at line 437 of file osdThread.c.

438 {
439  return((epicsThreadId)taskIdSelf());
440 }
void epicsThreadGetName ( epicsThreadId  id,
char *  name,
size_t  size 
)

Copy out the thread name into the provided buffer.

Guaranteed to be null terminated. size is number of bytes in buffer to hold name (including terminator). Failure results in an empty string stored in name.

Definition at line 453 of file osdThread.c.

454 {
455  int tid = (int)id;
456  strncpy(name,taskName(tid),size-1);
457  name[size-1] = '\0';
458 }
char * name
Definition: osdThread.c:50
const char* epicsThreadGetNameSelf ( void  )

Return the name of the current thread.

Returns
Never NULL. Storage lifetime tied to epicsThreadId.

This is either a copy of the string passed to epicsThread*Create*(), or an arbitrary unique string for non-EPICS threads.

Definition at line 448 of file osdThread.c.

449 {
450  return taskName(taskIdSelf());
451 }
unsigned int epicsThreadGetPriority ( epicsThreadId  id)

Return thread OSI priority

Definition at line 358 of file osdThread.c.

359 {
360  int tid = (int)id;
361  STATUS status;
362  int priority = 0;
363 
364  status = taskPriorityGet(tid,&priority);
365  if(status) errlogPrintf("epicsThreadGetPriority failed\n");
366  return(getOsiPriorityValue(priority));
367 }
pvd::Status status
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
unsigned int epicsThreadGetPrioritySelf ( void  )

Return thread OSI priority

Definition at line 369 of file osdThread.c.

370 {
372 }
LIBCOM_API unsigned int epicsStdCall epicsThreadGetPriority(epicsThreadId pthreadInfo)
Definition: osdThread.c:701
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810
unsigned int epicsThreadGetStackSize ( epicsThreadStackSizeClass  size)

Get a stack size value that can be given to epicsThreadCreate().

Parameters
sizeone of the values epicsThreadStackSmall, epicsThreadStackMedium or epicsThreadStackBig.

Definition at line 137 of file osdThread.c.

138 {
139 
140  if (stackSizeClass<epicsThreadStackSmall) {
141  errlogPrintf("epicsThreadGetStackSize illegal argument (too small)");
142  return stackSizeTable[epicsThreadStackBig];
143  }
144 
145  if (stackSizeClass>epicsThreadStackBig) {
146  errlogPrintf("epicsThreadGetStackSize illegal argument (too large)");
147  return stackSizeTable[epicsThreadStackBig];
148  }
149 
150  return stackSizeTable[stackSizeClass];
151 }
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
epicsThreadBooleanStatus epicsThreadHighestPriorityLevelBelow ( unsigned int  priority,
unsigned *  pPriorityJustBelow 
)

Lookup the next usage OSI priority such that priority > *pPriorityJustBelow if this is possible with the current target configuration and privlages.

Definition at line 385 of file osdThread.c.

387 {
388  unsigned newPriority = priority - 1;
389  if (newPriority <= 99) {
390  *pPriorityJustBelow = newPriority;
392  }
394 }
int epicsThreadIsEqual ( epicsThreadId  id1,
epicsThreadId  id2 
)

Test if two thread IDs actually refer to the same OS thread

Definition at line 409 of file osdThread.c.

410 {
411  return((id1==id2) ? 1 : 0);
412 }
int epicsThreadIsSuspended ( epicsThreadId  id)

How and why a thread can be suspended is implementation dependent. A thread calling epicsThreadSuspendSelf() should result in this routine returning true for that thread, but a thread may also be suspended for other reasons.

Definition at line 414 of file osdThread.c.

415 {
416  int tid = (int)id;
417  return((int)taskIsSuspended(tid));
418 }
epicsThreadBooleanStatus epicsThreadLowestPriorityLevelAbove ( unsigned int  priority,
unsigned *  pPriorityJustAbove 
)

Lookup the next usage OSI priority such that priority < *pPriorityJustBelow if this is possible with the current target configuration and privlages.

Definition at line 396 of file osdThread.c.

398 {
399  unsigned newPriority = priority + 1;
400 
401  newPriority = priority + 1;
402  if (newPriority <= 99) {
403  *pPriorityJustAbove = newPriority;
405  }
407 }
LIBCOM_API void epicsThreadMap ( EPICS_THREAD_HOOK_ROUTINE  func)

Call func once for every known thread.

Definition at line 460 of file osdThread.c.

461 {
462  int noTasks = 0;
463  int i;
464  int result;
465 
466  result = semTake(epicsThreadListMutex, WAIT_FOREVER);
467  assert(result == OK);
468  while (noTasks == 0) {
469  noTasks = taskIdListGet(taskIdList, taskIdListSize);
470  if (noTasks == taskIdListSize) {
471  taskIdList = realloc(taskIdList, (taskIdListSize+ID_LIST_CHUNK)*sizeof(int));
472  assert(taskIdList);
474  noTasks = 0;
475  }
476  }
477  for (i = 0; i < noTasks; i++) {
478  func ((epicsThreadId)taskIdList[i]);
479  }
480  semGive(epicsThreadListMutex);
481 }
pvac::PutEvent result
Definition: clientSync.cpp:117
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
int i
Definition: scan.c:967
#define ID_LIST_CHUNK
Definition: osdThread.c:66
int taskIdListSize
Definition: osdThread.c:68
void epicsThreadMustJoin ( epicsThreadId  id)

Wait for a joinable thread to exit (return from its main function)

Definition at line 291 of file osdThread.c.

292 {
293 #ifdef EPICS_THREAD_CAN_JOIN
294  const char *fn = "epicsThreadMustJoin";
295  int tid = (int) id;
296  SEM_ID joinSem;
297  STATUS status;
298 
299  if (!tid)
300  return;
301 
302  joinSem = (SEM_ID) taskSpareFieldGet(tid, joinField);
303  if ((int) joinSem == ERROR) {
304  errlogPrintf("%s: Thread %#x no longer exists.\n", fn, tid);
305  return;
306  }
307 
308  if (tid == taskIdSelf()) {
309  if (joinSem) {
310  taskSpareFieldSet(tid, joinField, 0);
311  semDelete(joinSem);
312  }
313  else {
314  errlogPrintf("%s: Thread '%s' (%#x) can't self-join.\n",
315  fn, epicsThreadGetNameSelf(), tid);
316  }
317  return;
318  }
319 
320  if (!joinSem) {
321  cantProceed("%s: Thread '%s' (%#x) is not joinable.\n",
322  fn, taskName(tid), tid);
323  return;
324  }
325 
326  semGive(joinSem); /* Rendezvous with thread */
327 
328  status = taskWait(tid, WAIT_FOREVER);
329  if (status && errno != S_objLib_OBJ_ID_ERROR) {
330  perror(fn);
331  cantProceed("%s: ", fn);
332  }
333 #endif
334 }
pvd::Status status
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
const ChannelProviderRegistry::factoryfn_t fn
LIBCOM_API void cantProceed(const char *msg,...)
Definition: cantProceed.c:54
LIBCOM_API const char epicsStdCall * epicsThreadGetNameSelf()
Definition: osdThread.c:846
void epicsThreadOnce ( epicsThreadOnceId id,
void(*)(void *)  func,
void *  arg 
)

Definition at line 159 of file osdThread.c.

160 {
161  static struct epicsThreadOSD threadOnceComplete;
162  #define EPICS_THREAD_ONCE_DONE &threadOnceComplete
163  int result;
164 
165  epicsThreadInit();
166  result = semTake(epicsThreadOnceMutex, WAIT_FOREVER);
167  assert(result == OK);
168  if (*id != EPICS_THREAD_ONCE_DONE) {
169  if (*id == EPICS_THREAD_ONCE_INIT) { /* first call */
170  *id = epicsThreadGetIdSelf(); /* mark active */
171  semGive(epicsThreadOnceMutex);
172  func(arg);
173  result = semTake(epicsThreadOnceMutex, WAIT_FOREVER);
174  assert(result == OK);
175  *id = EPICS_THREAD_ONCE_DONE; /* mark done */
176  } else if (*id == epicsThreadGetIdSelf()) {
177  semGive(epicsThreadOnceMutex);
178  cantProceed("Recursive epicsThreadOnce() initialization\n");
179  } else
180  while (*id != EPICS_THREAD_ONCE_DONE) {
181  /* Another thread is in the above func(arg) call. */
182  semGive(epicsThreadOnceMutex);
184  result = semTake(epicsThreadOnceMutex, WAIT_FOREVER);
185  assert(result == OK);
186  }
187  }
188  semGive(epicsThreadOnceMutex);
189 }
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
pvac::PutEvent result
Definition: clientSync.cpp:117
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
#define EPICS_THREAD_ONCE_DONE
LIBCOM_API double epicsStdCall epicsThreadSleepQuantum()
Query a value approximating the OS timer/scheduler resolution.
Definition: osdThread.c:981
#define EPICS_THREAD_ONCE_INIT
Definition: epicsThread.h:109
LIBCOM_API void cantProceed(const char *msg,...)
Definition: cantProceed.c:54
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810
epicsThreadPrivateId epicsThreadPrivateCreate ( void  )

Allocate a new thread local variable. This variable will initially hold NULL for each thread.

Definition at line 509 of file osdThread.c.

510 {
511  static int lock = 0;
513 
514  epicsThreadInit();
515  /*lock is necessary because ++nepicsThreadPrivate may not be indivisible*/
516  while(!vxTas(&lock)) taskDelay(1);
517  id = (epicsThreadPrivateId)++nepicsThreadPrivate;
518  lock = 0;
519  return(id);
520 }
epicsMutexId lock
Definition: osiClockTime.c:37
struct epicsThreadPrivateOSD * epicsThreadPrivateId
Definition: epicsThread.h:328
void epicsThreadPrivateDelete ( epicsThreadPrivateId  id)

Free a thread local variable

Definition at line 522 of file osdThread.c.

523 {
524  /*nothing to delete */
525  return;
526 }
void* epicsThreadPrivateGet ( epicsThreadPrivateId  )

Fetch the current value of a thread local variable

Definition at line 554 of file osdThread.c.

555 {
556  int int_id = (int)id;
557 
558  /*
559  * If epicsThreadPrivateGet() is called before epicsThreadPrivateSet()
560  * for any particular thread, the value returned is always NULL.
561  */
562  if ( papTSD && int_id <= (int) papTSD[0] ) {
563  return papTSD[int_id];
564  }
565  return NULL;
566 }
#define NULL
Definition: catime.c:38
void epicsThreadPrivateSet ( epicsThreadPrivateId  ,
void *   
)

Update thread local variable

Definition at line 532 of file osdThread.c.

533 {
534  int int_id = (int)id;
535  int nepicsThreadPrivateOld = 0;
536 
537  if (papTSD) nepicsThreadPrivateOld = (int)papTSD[0];
538 
539  if (!papTSD || nepicsThreadPrivateOld < int_id) {
540  void **papTSDold = papTSD;
541  int i;
542 
543  papTSD = callocMustSucceed(int_id + 1,sizeof(void *),
544  "epicsThreadPrivateSet");
545  papTSD[0] = (void *)(int_id);
546  for (i = 1; i <= nepicsThreadPrivateOld; i++) {
547  papTSD[i] = papTSDold[i];
548  }
549  free (papTSDold);
550  }
551  papTSD[int_id] = pvt;
552 }
int i
Definition: scan.c:967
LIBCOM_API void * callocMustSucceed(size_t count, size_t size, const char *msg)
A calloc() that never returns NULL.
Definition: cantProceed.c:22
void epicsThreadRealtimeLock ( void  )

When real-time scheduling is active, attempt any post-init operations that preserve real-time performance. For POSIX targets this locks the process into RAM, preventing swap-related VM faults.

Definition at line 134 of file osdThread.c.

135 {}
void epicsThreadResume ( epicsThreadId  id)

Resume a thread suspended with epicsThreadSuspendSelf()

Definition at line 344 of file osdThread.c.

345 {
346  int tid = (int)id;
347  STATUS status;
348 
349  status = taskResume(tid);
350  if(status) errlogPrintf("epicsThreadResume failed\n");
351 }
pthread_t tid
Definition: osdThread.h:26
pvd::Status status
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
void epicsThreadSetPriority ( epicsThreadId  id,
unsigned int  priority 
)

Change OSI priority of target thread.

Definition at line 374 of file osdThread.c.

375 {
376  int tid = (int)id;
377  STATUS status;
378  int priority = 0;
379 
380  priority = getOssPriorityValue(osip);
381  status = taskPrioritySet(tid,priority);
382  if(status) errlogPrintf("epicsThreadSetPriority failed\n");
383 }
pthread_t tid
Definition: osdThread.h:26
pvd::Status status
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
void epicsThreadShow ( epicsThreadId  id,
unsigned int  level 
)

Print info about a single EPICS thread.

Definition at line 488 of file osdThread.c.

489 {
490  int tid = (int)id;
491 
492  if (level > 1) level = 1;
493  if (tid)
494  taskShow(tid, level);
495 }
pthread_t tid
Definition: osdThread.h:26
void epicsThreadShowAll ( unsigned int  level)

Print to stdout information about all running EPICS threads.

Parameters
level0 prints minimal output. Higher values print more details.

Definition at line 483 of file osdThread.c.

484 {
485  taskShow(0,2);
486 }
void epicsThreadSleep ( double  seconds)

Block the calling thread for at least the specified time.

Parameters
secondsTime to wait in seconds. Values <=0 blocks for the shortest possible time.

Definition at line 420 of file osdThread.c.

421 {
422  STATUS status;
423  int ticks;
424 
425  if (seconds > 0.0) {
426  seconds *= sysClkRateGet();
427  seconds += 0.99999999; /* 8 9s here is optimal */
428  ticks = (seconds >= INT_MAX) ? INT_MAX : (int) seconds;
429  }
430  else { /* seconds <= 0 or NAN */
431  ticks = 0;
432  }
433  status = taskDelay(ticks);
434  if(status) errlogPrintf("epicsThreadSleep\n");
435 }
int sysClkRateGet(void)
pvd::Status status
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
double epicsThreadSleepQuantum ( void  )

Query a value approximating the OS timer/scheduler resolution.

Returns
A value in seconds >=0
Warning
On targets other than vxWorks and RTEMS, the quantum value often isn't meaningful. Use of this function is discouraged in portable code.

Definition at line 568 of file osdThread.c.

569 {
570  double HZ = sysClkRateGet ();
571  return 1.0 / HZ;
572 }
int sysClkRateGet(void)
void epicsThreadSuspendSelf ( void  )

Block the current thread until epicsThreadResume().

Definition at line 336 of file osdThread.c.

337 {
338  STATUS status;
339 
340  status = taskSuspend(taskIdSelf());
341  if(status) errlogPrintf("epicsThreadSuspendSelf failed\n");
342 }
pvd::Status status
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API void osdThreadHooksRun ( epicsThreadId  id)

Definition at line 105 of file osdThreadHooks.c.

106 {
107  threadHookInit();
108 
109  if (epicsMutexLock(hookLock) == epicsMutexLockOK) {
110  epicsThreadHook *pHook = (epicsThreadHook *) ellFirst(&hookList);
111 
112  while (pHook) {
113  pHook->func(id);
114  pHook = (epicsThreadHook *) ellNext(&pHook->node);
115  }
116  epicsMutexUnlock(hookLock);
117  }
118  else {
119  fprintf(stderr, "osdThreadHooksRun: Locking problem\n");
120  }
121 }
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
Definition: epicsMutex.cpp:140
#define ellNext(PNODE)
Find the next node in list.
Definition: ellLib.h:99
epicsMutexLockStatus epicsStdCall epicsMutexLock(epicsMutexId pmutexNode)
Claim the semaphore, waiting until it&#39;s free if currently owned owned by a different thread...
Definition: epicsMutex.cpp:145
#define stderr
Definition: epicsStdio.h:32
EPICS_THREAD_HOOK_ROUTINE func
#define ellFirst(PLIST)
Find the first node in list.
Definition: ellLib.h:89

Variable Documentation

int taskIdListSize = 0

Definition at line 68 of file osdThread.c.