![]() |
This is Unofficial EPICS BASE Doxygen Site
|
C++ and C descriptions for a thread. More...
#include <stddef.h>
#include "libComAPI.h"
#include "osdThread.h"
Go to the source code of this file.
Classes | |
struct | epicsThreadOpts |
Macros | |
#define | EPICS_THREAD_ONCE_INIT 0 |
#define | EPICS_THREAD_OPTS_INIT |
#define | EPICS_THREAD_CAN_JOIN |
Some Named Thread Priorities | |
#define | epicsThreadPriorityMax 99 |
#define | epicsThreadPriorityMin 0 |
#define | epicsThreadPriorityLow 10 |
#define | epicsThreadPriorityMedium 50 |
#define | epicsThreadPriorityHigh 90 |
#define | epicsThreadPriorityCAServerLow 20 |
#define | epicsThreadPriorityCAServerHigh 40 |
#define | epicsThreadPriorityScanLow 60 |
#define | epicsThreadPriorityScanHigh 70 |
#define | epicsThreadPriorityIocsh 91 |
#define | epicsThreadPriorityBaseMax 91 |
Typedefs | |
typedef void(* | EPICSTHREADFUNC) (void *parm) |
typedef struct epicsThreadOSD * | epicsThreadId |
typedef epicsThreadId | epicsThreadOnceId |
typedef struct epicsThreadOpts | epicsThreadOpts |
typedef void(* | EPICS_THREAD_HOOK_ROUTINE) (epicsThreadId id) |
typedef struct epicsThreadPrivateOSD * | epicsThreadPrivateId |
Functions | |
LIBCOM_API unsigned int epicsStdCall | epicsThreadGetStackSize (epicsThreadStackSizeClass size) |
LIBCOM_API void epicsStdCall | epicsThreadOnce (epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg) |
LIBCOM_API void | epicsThreadRealtimeLock (void) |
LIBCOM_API void epicsStdCall | epicsThreadExitMain (void) |
LIBCOM_API epicsThreadId | epicsThreadCreateOpt (const char *name, EPICSTHREADFUNC funptr, void *parm, const epicsThreadOpts *opts) |
Allocate and start a new OS thread. More... | |
LIBCOM_API epicsThreadId epicsStdCall | epicsThreadCreate (const char *name, unsigned int priority, unsigned int stackSize, EPICSTHREADFUNC funptr, void *parm) |
LIBCOM_API epicsThreadId epicsStdCall | epicsThreadMustCreate (const char *name, unsigned int priority, unsigned int stackSize, EPICSTHREADFUNC funptr, void *parm) |
LIBCOM_API void | epicsThreadMustJoin (epicsThreadId id) |
LIBCOM_API void epicsStdCall | epicsThreadSuspendSelf (void) |
LIBCOM_API void epicsStdCall | epicsThreadResume (epicsThreadId id) |
LIBCOM_API unsigned int epicsStdCall | epicsThreadGetPriority (epicsThreadId id) |
LIBCOM_API unsigned int epicsStdCall | epicsThreadGetPrioritySelf (void) |
LIBCOM_API void epicsStdCall | epicsThreadSetPriority (epicsThreadId id, unsigned int priority) |
LIBCOM_API epicsThreadBooleanStatus epicsStdCall | epicsThreadHighestPriorityLevelBelow (unsigned int priority, unsigned *pPriorityJustBelow) |
LIBCOM_API epicsThreadBooleanStatus epicsStdCall | epicsThreadLowestPriorityLevelAbove (unsigned int priority, unsigned *pPriorityJustAbove) |
LIBCOM_API int epicsStdCall | epicsThreadIsEqual (epicsThreadId id1, epicsThreadId id2) |
LIBCOM_API int epicsStdCall | epicsThreadIsSuspended (epicsThreadId id) |
LIBCOM_API void epicsStdCall | epicsThreadSleep (double seconds) |
Block the calling thread for at least the specified time. More... | |
LIBCOM_API double epicsStdCall | epicsThreadSleepQuantum (void) |
Query a value approximating the OS timer/scheduler resolution. More... | |
LIBCOM_API epicsThreadId epicsStdCall | epicsThreadGetIdSelf (void) |
LIBCOM_API epicsThreadId epicsStdCall | epicsThreadGetId (const char *name) |
LIBCOM_API int | epicsThreadGetCPUs (void) |
LIBCOM_API const char *epicsStdCall | epicsThreadGetNameSelf (void) |
LIBCOM_API void epicsStdCall | epicsThreadGetName (epicsThreadId id, char *name, size_t size) |
LIBCOM_API int epicsStdCall | epicsThreadIsOkToBlock (void) |
LIBCOM_API void epicsStdCall | epicsThreadSetOkToBlock (int isOkToBlock) |
LIBCOM_API void epicsStdCall | epicsThreadShowAll (unsigned int level) |
LIBCOM_API void epicsStdCall | epicsThreadShow (epicsThreadId id, unsigned int level) |
LIBCOM_API int | epicsThreadHookAdd (EPICS_THREAD_HOOK_ROUTINE hook) |
LIBCOM_API int | epicsThreadHookDelete (EPICS_THREAD_HOOK_ROUTINE hook) |
LIBCOM_API void | epicsThreadHooksShow (void) |
LIBCOM_API void | epicsThreadMap (EPICS_THREAD_HOOK_ROUTINE func) |
LIBCOM_API epicsThreadPrivateId epicsStdCall | epicsThreadPrivateCreate (void) |
LIBCOM_API void epicsStdCall | epicsThreadPrivateDelete (epicsThreadPrivateId id) |
LIBCOM_API void epicsStdCall | epicsThreadPrivateSet (epicsThreadPrivateId, void *) |
LIBCOM_API void *epicsStdCall | epicsThreadPrivateGet (epicsThreadPrivateId) |
C++ and C descriptions for a thread.
The epicsThread API is meant as a somewhat minimal interface for multithreaded applications. It can be implementedon a wide variety of systems with the restriction that the system MUST support a multithreaded environment. A POSIX pthreads version is provided.
The interface provides the following thread facilities, with restrictions as noted:
Definition in file epicsThread.h.
#define EPICS_THREAD_CAN_JOIN |
Definition at line 193 of file epicsThread.h.
#define EPICS_THREAD_ONCE_INIT 0 |
Definition at line 109 of file epicsThread.h.
#define EPICS_THREAD_OPTS_INIT |
Default initial values for epicsThreadOpts Applications should always use this macro to initialize an epicsThreadOpts structure. Additional fields may be added in the future, and the order of the fields might also change, thus code that assumes the above definition might break if these rules are not followed.
Definition at line 167 of file epicsThread.h.
#define epicsThreadPriorityBaseMax 91 |
Definition at line 85 of file epicsThread.h.
#define epicsThreadPriorityCAServerHigh 40 |
Definition at line 81 of file epicsThread.h.
#define epicsThreadPriorityCAServerLow 20 |
Definition at line 80 of file epicsThread.h.
#define epicsThreadPriorityHigh 90 |
Definition at line 77 of file epicsThread.h.
#define epicsThreadPriorityIocsh 91 |
Definition at line 84 of file epicsThread.h.
#define epicsThreadPriorityLow 10 |
Definition at line 75 of file epicsThread.h.
#define epicsThreadPriorityMax 99 |
Definition at line 71 of file epicsThread.h.
#define epicsThreadPriorityMedium 50 |
Definition at line 76 of file epicsThread.h.
#define epicsThreadPriorityMin 0 |
Definition at line 72 of file epicsThread.h.
#define epicsThreadPriorityScanHigh 70 |
Definition at line 83 of file epicsThread.h.
#define epicsThreadPriorityScanLow 60 |
Definition at line 82 of file epicsThread.h.
typedef void(* EPICS_THREAD_HOOK_ROUTINE) (epicsThreadId id) |
Hooks called when a thread starts, map function called once for every thread.
Definition at line 302 of file epicsThread.h.
typedef void(* EPICSTHREADFUNC) (void *parm) |
Definition at line 66 of file epicsThread.h.
typedef struct epicsThreadOSD* epicsThreadId |
(epicsThreadId)0 is guaranteed to be an invalid thread id
Definition at line 106 of file epicsThread.h.
typedef epicsThreadId epicsThreadOnceId |
Definition at line 108 of file epicsThread.h.
typedef struct epicsThreadOpts epicsThreadOpts |
For use with epicsThreadCreateOpt()
typedef struct epicsThreadPrivateOSD* epicsThreadPrivateId |
Thread local storage
Definition at line 328 of file epicsThread.h.
Enumerator | |
---|---|
epicsThreadBooleanStatusFail | |
epicsThreadBooleanStatusSuccess |
Definition at line 93 of file epicsThread.h.
Stack sizes for each stackSizeClass are implementation and CPU dependent.
Enumerator | |
---|---|
epicsThreadStackSmall | |
epicsThreadStackMedium | |
epicsThreadStackBig |
Definition at line 89 of file epicsThread.h.
LIBCOM_API epicsThreadId epicsStdCall epicsThreadCreate | ( | const char * | name, |
unsigned int | priority, | ||
unsigned int | stackSize, | ||
EPICSTHREADFUNC | funptr, | ||
void * | parm | ||
) |
Short-hand for epicsThreadCreateOpt() to create an un-joinable thread.
Definition at line 33 of file epicsThread.cpp.
LIBCOM_API epicsThreadId epicsThreadCreateOpt | ( | const char * | name, |
EPICSTHREADFUNC | funptr, | ||
void * | parm, | ||
const epicsThreadOpts * | opts | ||
) |
Allocate and start a new OS thread.
name | A name describing this thread. Appears in various log and error message. |
funptr | The thread main function. |
parm | Passed to thread main function. |
opts | Modifiers for the new thread, or NULL to use target specific defaults. |
Definition at line 529 of file osdThread.c.
LIBCOM_API void epicsStdCall 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 683 of file osdThread.c.
LIBCOM_API int epicsThreadGetCPUs | ( | void | ) |
Return a value approximating the number of threads which this target can run in parallel. This value is advisory.
Definition at line 990 of file osdThread.c.
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetId | ( | const char * | name | ) |
Attempt to find the first instance of a thread by name.
Definition at line 826 of file osdThread.c.
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf | ( | void | ) |
Find an epicsThreadId associated with the current thread. For non-EPICS threads, a new epicsThreadId may be allocated.
Definition at line 810 of file osdThread.c.
LIBCOM_API void epicsStdCall 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 857 of file osdThread.c.
LIBCOM_API const char* epicsStdCall epicsThreadGetNameSelf | ( | void | ) |
Return the name of the current thread.
This is either a copy of the string passed to epicsThread*Create*(), or an arbitrary unique string for non-EPICS threads.
Definition at line 846 of file osdThread.c.
LIBCOM_API unsigned int epicsStdCall epicsThreadGetPriority | ( | epicsThreadId | id | ) |
LIBCOM_API unsigned int epicsStdCall epicsThreadGetPrioritySelf | ( | void | ) |
Return thread OSI priority
Definition at line 707 of file osdThread.c.
LIBCOM_API unsigned int epicsStdCall epicsThreadGetStackSize | ( | epicsThreadStackSizeClass | size | ) |
Get a stack size value that can be given to epicsThreadCreate().
size | one of the values epicsThreadStackSmall, epicsThreadStackMedium or epicsThreadStackBig. |
Definition at line 466 of file osdThread.c.
LIBCOM_API epicsThreadBooleanStatus epicsStdCall 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 740 of file osdThread.c.
LIBCOM_API int epicsThreadHookAdd | ( | EPICS_THREAD_HOOK_ROUTINE | hook | ) |
Register a routine to be called by every new thread before the thread function gets run. Hook routines will often register a thread exit routine with epicsAtThreadExit() to release thread-specific resources they have allocated.
Definition at line 54 of file osdThreadHooks.c.
LIBCOM_API int epicsThreadHookDelete | ( | EPICS_THREAD_HOOK_ROUTINE | hook | ) |
Remove routine from the list of hooks run at thread creation time.
Definition at line 77 of file osdThreadHooks.c.
LIBCOM_API void epicsThreadHooksShow | ( | void | ) |
Print the current list of hook function pointers.
Definition at line 123 of file osdThreadHooks.c.
LIBCOM_API int epicsStdCall epicsThreadIsEqual | ( | epicsThreadId | id1, |
epicsThreadId | id2 | ||
) |
Test if two thread IDs actually refer to the same OS thread
Definition at line 776 of file osdThread.c.
LIBCOM_API int epicsStdCall epicsThreadIsOkToBlock | ( | void | ) |
Is it OK for a thread to block? This can be called by support code that does not know if it is called in a thread that should not block. For example the errlog system calls this to decide when messages should be displayed on the console.
Definition at line 358 of file epicsThread.cpp.
LIBCOM_API int epicsStdCall 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 784 of file osdThread.c.
LIBCOM_API epicsThreadBooleanStatus epicsStdCall 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 757 of file osdThread.c.
LIBCOM_API void epicsThreadMap | ( | EPICS_THREAD_HOOK_ROUTINE | func | ) |
Call func once for every known thread.
Definition at line 864 of file osdThread.c.
LIBCOM_API epicsThreadId epicsStdCall epicsThreadMustCreate | ( | const char * | name, |
unsigned int | priority, | ||
unsigned int | stackSize, | ||
EPICSTHREADFUNC | funptr, | ||
void * | parm | ||
) |
Short-hand for epicsThreadCreateOpt() to create an un-joinable thread. On error calls cantProceed()
Definition at line 374 of file epicsThread.cpp.
LIBCOM_API void epicsThreadMustJoin | ( | epicsThreadId | id | ) |
Wait for a joinable thread to exit (return from its main function)
Definition at line 632 of file osdThread.c.
LIBCOM_API void epicsStdCall epicsThreadOnce | ( | epicsThreadOnceId * | id, |
EPICSTHREADFUNC | , | ||
void * | arg | ||
) |
Perform one-time initialization.
Run the provided function if it has not run, and is not running in some other thread.
For each unique epicsThreadOnceId, epicsThreadOnce guarantees that
LIBCOM_API epicsThreadPrivateId epicsStdCall epicsThreadPrivateCreate | ( | void | ) |
Allocate a new thread local variable. This variable will initially hold NULL for each thread.
Definition at line 934 of file osdThread.c.
LIBCOM_API void epicsStdCall epicsThreadPrivateDelete | ( | epicsThreadPrivateId | id | ) |
LIBCOM_API void* epicsStdCall epicsThreadPrivateGet | ( | epicsThreadPrivateId | ) |
LIBCOM_API void epicsStdCall epicsThreadPrivateSet | ( | epicsThreadPrivateId | , |
void * | |||
) |
LIBCOM_API 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 425 of file osdThread.c.
LIBCOM_API void epicsStdCall epicsThreadResume | ( | epicsThreadId | id | ) |
LIBCOM_API void epicsStdCall epicsThreadSetOkToBlock | ( | int | isOkToBlock | ) |
When a thread is started the default is that it is not allowed to block. This method can be called to change the state. For example iocsh calls this to specify that it is OK to block.
Definition at line 366 of file epicsThread.cpp.
LIBCOM_API void epicsStdCall epicsThreadSetPriority | ( | epicsThreadId | id, |
unsigned int | priority | ||
) |
Change OSI priority of target thread.
Definition at line 713 of file osdThread.c.
LIBCOM_API void epicsStdCall epicsThreadShow | ( | epicsThreadId | id, |
unsigned int | level | ||
) |
Print info about a single EPICS thread.
Definition at line 903 of file osdThread.c.
LIBCOM_API void epicsStdCall epicsThreadShowAll | ( | unsigned int | level | ) |
Print to stdout information about all running EPICS threads.
level | 0 prints minimal output. Higher values print more details. |
Definition at line 883 of file osdThread.c.
LIBCOM_API void epicsStdCall epicsThreadSleep | ( | double | seconds | ) |
Block the calling thread for at least the specified time.
seconds | Time to wait in seconds. Values <=0 blocks for the shortest possible time. |
Definition at line 790 of file osdThread.c.
LIBCOM_API double epicsStdCall epicsThreadSleepQuantum | ( | void | ) |
Query a value approximating the OS timer/scheduler resolution.
Definition at line 981 of file osdThread.c.
LIBCOM_API void epicsStdCall epicsThreadSuspendSelf | ( | void | ) |
Block the current thread until epicsThreadResume().
Definition at line 664 of file osdThread.c.