This is Unofficial EPICS BASE Doxygen Site
epicsThread.cpp File Reference
#include <exception>
#include <typeinfo>
#include <stdio.h>
#include <stddef.h>
#include <float.h>
#include <string.h>
#include "epicsAlgorithm.h"
#include "epicsTime.h"
#include "epicsThread.h"
#include "epicsAssert.h"
#include "epicsGuard.h"
#include "errlog.h"
+ Include dependency graph for epicsThread.cpp:

Go to the source code of this file.

Classes

class  epicsThread::unableToCreateThread
 

Functions

epicsThreadId epicsStdCall epicsThreadCreate (const char *name, unsigned int priority, unsigned int stackSize, EPICSTHREADFUNC funptr, void *parm)
 
void epicsThreadCallEntryPoint (void *pPvt)
 
int epicsStdCall epicsThreadIsOkToBlock (void)
 
void epicsStdCall epicsThreadSetOkToBlock (int isOkToBlock)
 
epicsThreadId epicsStdCall epicsThreadMustCreate (const char *name, unsigned int priority, unsigned int stackSize, EPICSTHREADFUNC funptr, void *parm)
 

Variables

epicsThreadPrivateId okToBlockPrivate
 
epicsThreadId epicsThreadMainId = initMainThread()
 

Function Documentation

void epicsThreadCallEntryPoint ( void *  pPvt)

Definition at line 86 of file epicsThread.cpp.

87 {
88  epicsThread * pThread =
89  static_cast <epicsThread *> ( pPvt );
90  bool threadDestroyed = false;
91  try {
92  pThread->pThreadDestroyed = & threadDestroyed;
93  if ( pThread->beginWait () ) {
94  pThread->runable.run ();
95  // The run() routine may have destroyed the epicsThread
96  // object by now; pThread can only be used below here
97  // when the threadDestroyed flag is false.
98  }
99  }
100  catch ( const epicsThread::exitException & ) {
101  }
102  catch ( std :: exception & except ) {
103  if ( ! threadDestroyed ) {
104  pThread->printLastChanceExceptionMessage (
105  typeid ( except ).name (), except.what () );
106  }
107  }
108  catch ( ... ) {
109  if ( ! threadDestroyed ) {
110  pThread->printLastChanceExceptionMessage (
111  "catch ( ... )", "Non-standard C++ exception" );
112  }
113  }
114  if ( ! threadDestroyed ) {
115  epicsGuard < epicsMutex > guard ( pThread->mutex );
116  pThread->pThreadDestroyed = NULL;
117  pThread->terminated = true;
118  pThread->exitEvent.signal ();
119  // After the terminated flag is set and guard's destructor
120  // releases the lock, pThread must never be used again.
121  }
122 }
#define NULL
Definition: catime.c:38
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.

36 {
38  opts.priority = priority;
39  opts.stackSize = stackSize;
40  opts.joinable = 0;
41 
42  return epicsThreadCreateOpt(name, funptr, parm, &opts);
43 }
unsigned int joinable
Definition: epicsThread.h:158
unsigned int stackSize
Definition: epicsThread.h:154
unsigned int priority
Definition: epicsThread.h:150
#define EPICS_THREAD_OPTS_INIT
Definition: epicsThread.h:167
LIBCOM_API epicsThreadId epicsThreadCreateOpt(const char *name, EPICSTHREADFUNC funptr, void *parm, const epicsThreadOpts *opts)
Allocate and start a new OS thread.
Definition: osdThread.c:529
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.

359  {
360  const int *pokToBlock;
361  epicsThreadOnce(&okToBlockOnce, epicsThreadOnceIdInit, NULL);
362  pokToBlock = (int *) epicsThreadPrivateGet(okToBlockPrivate);
363  return (pokToBlock ? *pokToBlock : 0);
364  }
epicsThreadPrivateId okToBlockPrivate
LIBCOM_API void *epicsStdCall epicsThreadPrivateGet(epicsThreadPrivateId)
Definition: osdThread.c:973
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
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.

377  {
379  name, priority, stackSize, funptr, parm );
380  assert ( id );
381  return id;
382  }
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
epicsThreadId epicsStdCall epicsThreadCreate(const char *name, unsigned int priority, unsigned int stackSize, EPICSTHREADFUNC funptr, void *parm)
Definition: epicsThread.cpp:33
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.

367  {
368  const int *pokToBlock;
369  epicsThreadOnce(&okToBlockOnce, epicsThreadOnceIdInit, NULL);
370  pokToBlock = (isOkToBlock) ? &okToBlockYes : &okToBlockNo;
371  epicsThreadPrivateSet(okToBlockPrivate, (void *)pokToBlock);
372  }
epicsThreadPrivateId okToBlockPrivate
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
LIBCOM_API void epicsStdCall epicsThreadPrivateSet(epicsThreadPrivateId, void *)
Definition: osdThread.c:961

Variable Documentation

epicsThreadId epicsThreadMainId = initMainThread()

Definition at line 392 of file epicsThread.cpp.

epicsThreadPrivateId okToBlockPrivate

Definition at line 349 of file epicsThread.cpp.