This is Unofficial EPICS BASE Doxygen Site
epicsExit.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "ellLib.h"
#include "errlog.h"
#include "epicsThread.h"
#include "epicsMutex.h"
#include "cantProceed.h"
#include "epicsExit.h"
#include "epicsExport.h"
+ Include dependency graph for epicsExit.c:

Go to the source code of this file.

Classes

struct  exitNode
 
struct  exitPvt
 

Typedefs

typedef struct exitNode exitNode
 
typedef struct exitPvt exitPvt
 

Functions

void epicsMutexCleanup (void)
 
LIBCOM_API void epicsExitCallAtExits (void)
 Internal routine that runs the registered exit routines. More...
 
LIBCOM_API void epicsExitCallAtThreadExits (void)
 Internal routine that runs the registered thread exit routines. More...
 
LIBCOM_API int epicsAtThreadExit (epicsExitFunc func, void *arg)
 Register a function and an context value to be run by this thread when it returns from its entry routine. More...
 
LIBCOM_API int epicsAtExit3 (epicsExitFunc func, void *arg, const char *name)
 Register a function and an associated context parameter. More...
 
LIBCOM_API void epicsExit (int status)
 Calls epicsExitCallAtExits(), then the OS exit() routine. More...
 
LIBCOM_API void epicsExitLater (int status)
 Arrange to call epicsExit() later from a low priority thread. More...
 
 epicsExportAddress (int, atExitDebug)
 

Variables

int atExitDebug = 0
 

Typedef Documentation

typedef struct exitNode exitNode
typedef struct exitPvt exitPvt

Function Documentation

LIBCOM_API int epicsAtExit3 ( epicsExitFunc  func,
void *  arg,
const char *  name 
)

Register a function and an associated context parameter.

Parameters
funcFunction to be called when epicsExitCallAtExits is invoked.
argContext parameter for the function.
nameFunction name

Definition at line 166 of file epicsExit.c.

167 {
168  int status = -1;
169 
170  epicsExitInit ();
171  epicsMutexMustLock ( exitPvtLock );
172  if ( !pExitPvtPerProcess ) {
173  pExitPvtPerProcess = createExitPvt ();
174  }
175  if ( pExitPvtPerProcess ) {
176  status = epicsAtExitPvt ( pExitPvtPerProcess, func, arg, name );
177  }
178  epicsMutexUnlock ( exitPvtLock );
179  return status;
180 }
pvd::Status status
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
Definition: epicsMutex.cpp:140
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
Definition: epicsMutex.h:214
LIBCOM_API int epicsAtThreadExit ( epicsExitFunc  func,
void *  arg 
)

Register a function and an context value to be run by this thread when it returns from its entry routine.

Parameters
funcFunction be called at thread completion.
argContext parameter for the function.

Definition at line 150 of file epicsExit.c.

151 {
152  exitPvt * pep;
153 
154  epicsExitInit ();
155  pep = epicsThreadPrivateGet ( exitPvtPerThread );
156  if ( ! pep ) {
157  pep = createExitPvt ();
158  if ( ! pep ) {
159  return -1;
160  }
161  epicsThreadPrivateSet ( exitPvtPerThread, pep );
162  }
163  return epicsAtExitPvt ( pep, func, arg, NULL );
164 }
LIBCOM_API void *epicsStdCall epicsThreadPrivateGet(epicsThreadPrivateId)
Definition: osdThread.c:973
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsThreadPrivateSet(epicsThreadPrivateId, void *)
Definition: osdThread.c:961
LIBCOM_API void epicsExit ( int  status)

Calls epicsExitCallAtExits(), then the OS exit() routine.

Parameters
statusPassed to exit()

Definition at line 182 of file epicsExit.c.

183 {
185  epicsThreadSleep(0.1);
186  exit(status);
187 }
pvd::Status status
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
LIBCOM_API void epicsExitCallAtExits(void)
Internal routine that runs the registered exit routines.
Definition: epicsExit.c:102
LIBCOM_API void epicsExitCallAtExits ( void  )

Internal routine that runs the registered exit routines.

Calls each of the functions registered by prior calls to epicsAtExit in reverse order of their registration.

Note
Most applications will not call this routine directly.

Definition at line 102 of file epicsExit.c.

103 {
104  exitPvt * pep = 0;
105 
106  epicsExitInit ();
107  epicsMutexMustLock ( exitPvtLock );
108  if ( pExitPvtPerProcess ) {
109  pep = pExitPvtPerProcess;
110  pExitPvtPerProcess = 0;
111  }
112  epicsMutexUnlock ( exitPvtLock );
113  if ( pep ) {
114  epicsExitCallAtExitsPvt ( pep );
115  destroyExitPvt ( pep );
116  }
117  /* Handle specially to avoid circular reference */
119 }
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
Definition: epicsMutex.cpp:140
void epicsMutexCleanup(void)
Definition: epicsMutex.cpp:176
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
Definition: epicsMutex.h:214
LIBCOM_API void epicsExitCallAtThreadExits ( void  )

Internal routine that runs the registered thread exit routines.

Calls each of the functions that were registered in the current thread by calling epicsAtThreadExit(), in reverse order of their registration.

Note
This routine is called automatically when an epicsThread's main entry routine returns. It will not be run if the thread gets stopped by some other method.

Definition at line 121 of file epicsExit.c.

122 {
123  exitPvt * pep;
124 
125  epicsExitInit ();
126  pep = epicsThreadPrivateGet ( exitPvtPerThread );
127  if ( pep ) {
128  epicsExitCallAtExitsPvt ( pep );
129  destroyExitPvt ( pep );
130  epicsThreadPrivateSet ( exitPvtPerThread, 0 );
131  }
132 }
LIBCOM_API void *epicsStdCall epicsThreadPrivateGet(epicsThreadPrivateId)
Definition: osdThread.c:973
LIBCOM_API void epicsStdCall epicsThreadPrivateSet(epicsThreadPrivateId, void *)
Definition: osdThread.c:961
LIBCOM_API void epicsExitLater ( int  status)

Arrange to call epicsExit() later from a low priority thread.

This delays the actual call to exit() so it doesn't run in this thread.

Parameters
statusPassed to exit()

Definition at line 204 of file epicsExit.c.

205 {
206  epicsThreadOnce(&exitLaterOnce, &exitLaterOnceFunc, &status);
207 }
pvd::Status status
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
epicsExportAddress ( int  ,
atExitDebug   
)
void epicsMutexCleanup ( void  )

Definition at line 176 of file epicsMutex.cpp.

177 {
178  ELLNODE *cur;
179  epicsMutexLockStatus lockStat =
180  epicsMutexOsdLock(epicsMutexGlobalLock);
181  assert ( lockStat == epicsMutexLockOK );
182 
183  while((cur=ellGet(&freeList))!=NULL) {
184  VALGRIND_MEMPOOL_FREE(&freeList, cur);
185  free(cur);
186  }
187 
188  epicsMutexOsdUnlock(epicsMutexGlobalLock);
189 }
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
ELLNODE * ellGet(ELLLIST *pList)
Deletes and returns the first node from a list.
Definition: ellLib.c:147
#define NULL
Definition: catime.c:38
List node type.
Definition: ellLib.h:45
epicsMutexLockStatus
Definition: epicsMutex.h:51
#define epicsMutexOsdUnlock(ID)
Definition: osdMutex.h:22
#define epicsMutexOsdLock(ID)
Definition: osdMutex.h:24
#define VALGRIND_MEMPOOL_FREE(pool, addr)
Definition: valgrind.h:6485

Variable Documentation

int atExitDebug = 0

Definition at line 50 of file epicsExit.c.