// extern "C" void epicsShareAPI ca_signal_formated ( long ca_status, const char *pfilenm, int lineno, const char *pFormat, ... ) { ca_client_context *pcac; if ( caClientContextId ) { pcac = ( ca_client_context * ) epicsThreadPrivateGet ( caClientContextId ); } else { pcac = 0; } va_list theArgs; va_start ( theArgs, pFormat ); if ( pcac ) { pcac->vSignal ( ca_status, pfilenm, lineno, pFormat, theArgs ); } else { fprintf ( stderr, "CA exception in thread w/o CA ctx: status=%s file=%s line=%d: \n", ca_message ( ca_status ), pfilenm, lineno ); if ( pFormat ) { vfprintf ( stderr, pFormat, theArgs ); } } va_end ( theArgs ); }
// extern "C" int epicsShareAPI ca_context_create ( ca_preemptive_callback_select premptiveCallbackSelect ) { ca_client_context *pcac; try { epicsThreadOnce ( & caClientContextIdOnce, ca_init_client_context, 0); if ( caClientContextId == 0 ) { return ECA_ALLOCMEM; } pcac = ( ca_client_context * ) epicsThreadPrivateGet ( caClientContextId ); if ( pcac ) { if ( premptiveCallbackSelect == ca_enable_preemptive_callback && ! pcac->preemptiveCallbakIsEnabled() ) { return ECA_NOTTHREADED; } return ECA_NORMAL; } pcac = new ca_client_context ( premptiveCallbackSelect == ca_enable_preemptive_callback ); if ( ! pcac ) { return ECA_ALLOCMEM; } epicsThreadPrivateSet ( caClientContextId, (void *) pcac ); } catch ( ... ) { return ECA_ALLOCMEM; } return ECA_NORMAL; }
// extern "C" void epicsShareAPI ca_self_test () { ca_client_context *pcac = (ca_client_context *) epicsThreadPrivateGet ( caClientContextId ); if ( ! pcac ) { return; } pcac->selfTest (); }
int epicsShareAPI ca_preemtive_callback_is_enabled () { ca_client_context *pcac = (ca_client_context *) epicsThreadPrivateGet ( caClientContextId ); if ( ! pcac ) { return 0; } return pcac->preemptiveCallbakIsEnabled (); }
epicsShareFunc void epicsExitCallAtThreadExits(void) { exitPvt * pep; epicsThreadOnce ( & exitPvtOnce, exitPvtOnceFunc, 0 ); pep = epicsThreadPrivateGet ( exitPvtPerThread ); if ( pep ) { epicsExitCallAtExitsPvt ( pep ); destroyExitPvt ( pep ); epicsThreadPrivateSet ( exitPvtPerThread, 0 ); } }
FILE * epicsShareAPI epicsGetThreadStderr(void) { /* Deliberately don't do the epicsThreadOnce() here; epicsThreadInit() * is allowed to use stderr inside its once() routine, in which case we * must return the OS's stderr instead. There may be a tiny chance of a * race happening here during initialization for some architectures, so * we only use it for stderr to reduce the chance of that happening. */ if (!stderrThreadPrivateId) return NULL; return epicsThreadPrivateGet(stderrThreadPrivateId); }
// extern "C" int epicsShareAPI ca_attach_context ( struct ca_client_context * pCtx ) { ca_client_context *pcac = (ca_client_context *) epicsThreadPrivateGet ( caClientContextId ); if ( pcac && pCtx != 0 ) { return ECA_ISATTACHED; } if ( ! pCtx->preemptiveCallbakIsEnabled() ) { return ECA_NOTTHREADED; } epicsThreadPrivateSet ( caClientContextId, pCtx ); return ECA_NORMAL; }
// extern "C" struct ca_client_context * epicsShareAPI ca_current_context () { struct ca_client_context *pCtx; if ( caClientContextId ) { pCtx = ( struct ca_client_context * ) epicsThreadPrivateGet ( caClientContextId ); } else { pCtx = 0; } return pCtx; }
// // ca_context_destroy () // // extern "C" void epicsShareAPI ca_context_destroy () { ca_client_context *pcac; if ( caClientContextId != NULL ) { pcac = (ca_client_context *) epicsThreadPrivateGet ( caClientContextId ); if ( pcac ) { delete pcac; epicsThreadPrivateSet ( caClientContextId, 0 ); } } }
epicsShareFunc int epicsAtThreadExit(epicsExitFunc func, void *arg) { exitPvt * pep; epicsThreadOnce ( & exitPvtOnce, exitPvtOnceFunc, 0 ); pep = epicsThreadPrivateGet ( exitPvtPerThread ); if ( ! pep ) { pep = createExitPvt (); if ( ! pep ) { return -1; } epicsThreadPrivateSet ( exitPvtPerThread, pep ); } return epicsAtExitPvt ( pep, func, arg ); }
/* * fetchClientContext (); */ int fetchClientContext ( ca_client_context **ppcac ) { epicsThreadOnce ( &caClientContextIdOnce, ca_init_client_context, 0 ); if ( caClientContextId == 0 ) { return ECA_ALLOCMEM; } int status; *ppcac = ( ca_client_context * ) epicsThreadPrivateGet ( caClientContextId ); if ( *ppcac ) { status = ECA_NORMAL; } else { status = ca_task_initialize (); if ( status == ECA_NORMAL ) { *ppcac = (ca_client_context *) epicsThreadPrivateGet ( caClientContextId ); if ( ! *ppcac ) { status = ECA_INTERNAL; } } } return status; }
FILE * epicsShareAPI epicsGetThreadStdout(void) { epicsThreadOnce(&onceId,once,0); return epicsThreadPrivateGet(stdoutThreadPrivateId); }