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

Go to the source code of this file.

Classes

struct  epicsThreadHook
 

Typedefs

typedef struct epicsThreadHook epicsThreadHook
 

Functions

LIBCOM_API int epicsThreadHookAdd (EPICS_THREAD_HOOK_ROUTINE hook)
 
LIBCOM_API int epicsThreadHookDelete (EPICS_THREAD_HOOK_ROUTINE hook)
 
LIBCOM_API void osdThreadHooksRunMain (epicsThreadId id)
 
LIBCOM_API void osdThreadHooksRun (epicsThreadId id)
 
LIBCOM_API void epicsThreadHooksShow (void)
 

Variables

LIBCOM_API EPICS_THREAD_HOOK_ROUTINE epicsThreadHookDefault
 
LIBCOM_API EPICS_THREAD_HOOK_ROUTINE epicsThreadHookMain
 

Typedef Documentation

Function Documentation

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.

55 {
56  epicsThreadHook *pHook;
57 
58  if (!hook) return 0;
59  threadHookInit();
60 
61  pHook = calloc(1, sizeof(epicsThreadHook));
62  if (!pHook) {
63  fprintf(stderr, "epicsThreadHookAdd: calloc failed\n");
64  return -1;
65  }
66  pHook->func = hook;
67 
68  if (epicsMutexLock(hookLock) == epicsMutexLockOK) {
69  ellAdd(&hookList, &pHook->node);
70  epicsMutexUnlock(hookLock);
71  return 0;
72  }
73  fprintf(stderr, "epicsThreadHookAdd: Locking problem\n");
74  return -1;
75 }
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
Definition: epicsMutex.cpp:140
void ellAdd(ELLLIST *pList, ELLNODE *pNode)
Adds a node to the end of a list.
Definition: ellLib.c:24
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
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.

78 {
79  if (!hook) return 0;
80  threadHookInit();
81 
82  if (epicsMutexLock(hookLock) == epicsMutexLockOK) {
83  epicsThreadHook *pHook = (epicsThreadHook *) ellFirst(&hookList);
84 
85  while (pHook) {
86  if (hook == pHook->func) {
87  ellDelete(&hookList, &pHook->node);
88  break;
89  }
90  pHook = (epicsThreadHook *) ellNext(&pHook->node);
91  }
92  epicsMutexUnlock(hookLock);
93  return 0;
94  }
95  fprintf(stderr, "epicsThreadHookAdd: Locking problem\n");
96  return -1;
97 }
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
void ellDelete(ELLLIST *pList, ELLNODE *pNode)
Deletes a node from a list.
Definition: ellLib.c:75
#define ellFirst(PLIST)
Find the first node in list.
Definition: ellLib.h:89
LIBCOM_API void epicsThreadHooksShow ( void  )

Print the current list of hook function pointers.

Definition at line 123 of file osdThreadHooks.c.

124 {
125  threadHookInit();
126 
127  if (epicsMutexLock(hookLock) == epicsMutexLockOK) {
128  epicsThreadHook *pHook = (epicsThreadHook *) ellFirst(&hookList);
129 
130  while (pHook) {
131  printf(" %p\n", pHook->func);
132  pHook = (epicsThreadHook *) ellNext(&pHook->node);
133  }
134  epicsMutexUnlock(hookLock);
135  }
136  else {
137  fprintf(stderr, "epicsThreadHooksShow: Locking problem\n");
138  }
139 }
#define printf
Definition: epicsStdio.h:41
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
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
LIBCOM_API void osdThreadHooksRunMain ( epicsThreadId  id)

Definition at line 99 of file osdThreadHooks.c.

100 {
103 }
LIBCOM_API EPICS_THREAD_HOOK_ROUTINE epicsThreadHookMain

Variable Documentation

LIBCOM_API EPICS_THREAD_HOOK_ROUTINE epicsThreadHookDefault

Definition at line 14 of file osdThreadExtra.c.

LIBCOM_API EPICS_THREAD_HOOK_ROUTINE epicsThreadHookMain

Definition at line 15 of file osdThreadExtra.c.