changes for osiThread=>epicsThread
This commit is contained in:
@@ -26,7 +26,7 @@ of this distribution.
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "ellLib.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "cantProceed.h"
|
||||
@@ -46,7 +46,7 @@ of this distribution.
|
||||
|
||||
epicsShareDef int asCaDebug = 0;
|
||||
LOCAL int firstTime = TRUE;
|
||||
LOCAL threadId threadid=0;
|
||||
LOCAL epicsThreadId threadid=0;
|
||||
LOCAL int caInitializing=FALSE;
|
||||
LOCAL epicsMutexId asCaTaskLock; /*lock access to task */
|
||||
LOCAL epicsEventId asCaTaskWait; /*Wait for task to respond*/
|
||||
@@ -72,6 +72,7 @@ static void exceptionCallback(struct exception_handler_args args)
|
||||
int readAccess;
|
||||
int writeAccess;
|
||||
|
||||
printf("as exceptionCallback\n");
|
||||
channel = (chid ? ca_name(chid) : unknown);
|
||||
context = (args.ctx ? args.ctx : unknown);
|
||||
nativeType = dbr_type_to_text((chid ? ca_field_type(chid) : -1));
|
||||
@@ -99,6 +100,7 @@ LOCAL void connectCallback(struct connection_handler_args arg)
|
||||
ASGINP *pasginp = (ASGINP *)ca_puser(chid);
|
||||
ASG *pasg = pasginp->pasg;
|
||||
|
||||
printf("as connectCallback %s\n",ca_name(chid));
|
||||
if(ca_state(chid)!=cs_conn) {
|
||||
if(!(pasg->inpBad & (1<<pasginp->inpIndex))) {
|
||||
/*was good so lets make it bad*/
|
||||
@@ -119,6 +121,7 @@ LOCAL void eventCallback(struct event_handler_args arg)
|
||||
CAPVT *pcapvt;
|
||||
READONLY struct dbr_sts_double *pdata;
|
||||
|
||||
printf("as eventCallback %s\n",ca_name(chid));
|
||||
if(caStatus!=ECA_NORMAL) {
|
||||
if(chid) {
|
||||
epicsPrintf("asCa: eventCallback error %s channel %s\n",
|
||||
@@ -168,13 +171,15 @@ LOCAL void eventCallback(struct event_handler_args arg)
|
||||
|
||||
LOCAL void asCaTask(void)
|
||||
{
|
||||
static const int enablePreemption = 1u;
|
||||
ASG *pasg;
|
||||
ASGINP *pasginp;
|
||||
CAPVT *pcapvt;
|
||||
int status;
|
||||
|
||||
taskwdInsert(threadGetIdSelf(),NULL,NULL);
|
||||
SEVCHK(ca_task_initialize(),"ca_task_initialize");
|
||||
taskwdInsert(epicsThreadGetIdSelf(),NULL,NULL);
|
||||
SEVCHK(ca_context_create(enablePreemption),
|
||||
"asCaTask calling ca_context_create");
|
||||
SEVCHK(ca_add_exception_event(exceptionCallback,NULL),
|
||||
"ca_add_exception_event");
|
||||
while(TRUE) {
|
||||
@@ -194,6 +199,7 @@ LOCAL void asCaTask(void)
|
||||
ca_message(status));
|
||||
}
|
||||
/*Note calls eventCallback immediately for local Pvs*/
|
||||
printf("as ca_add_event %s\n",pasginp->inp);
|
||||
status = ca_add_event(DBR_STS_DOUBLE,pcapvt->chid,
|
||||
eventCallback,pasginp,0);
|
||||
if(status!=ECA_NORMAL) {
|
||||
@@ -204,14 +210,14 @@ LOCAL void asCaTask(void)
|
||||
}
|
||||
pasg = (ASG *)ellNext((ELLNODE *)pasg);
|
||||
}
|
||||
printf("as calling ca_flush_io\n");
|
||||
SEVCHK(ca_flush_io(),"asCaTask");
|
||||
epicsThreadSleep(2.0);
|
||||
asComputeAllAsg();
|
||||
caInitializing = FALSE;
|
||||
if(asCaDebug) printf("asCaTask initialized\n");
|
||||
epicsEventSignal(asCaTaskWait);
|
||||
while(TRUE) {
|
||||
if(epicsEventTryWait(asCaTaskClearChannels)==epicsEventWaitOK) break;
|
||||
ca_pend_event(2.0);
|
||||
}
|
||||
epicsEventMustWait(asCaTaskClearChannels);
|
||||
pasg = (ASG *)ellFirst(&pasbase->asgList);
|
||||
while(pasg) {
|
||||
pasginp = (ASGINP *)ellFirst(&pasg->inpList);
|
||||
@@ -242,10 +248,10 @@ void epicsShareAPI asCaStart(void)
|
||||
asCaTaskWait=epicsEventMustCreate(epicsEventEmpty);
|
||||
asCaTaskAddChannels=epicsEventMustCreate(epicsEventEmpty);
|
||||
asCaTaskClearChannels=epicsEventMustCreate(epicsEventEmpty);
|
||||
threadid = threadCreate("asCaTask",
|
||||
(threadPriorityScanLow - 3),
|
||||
threadGetStackSize(threadStackBig),
|
||||
(THREADFUNC)asCaTask,0);
|
||||
threadid = epicsThreadCreate("asCaTask",
|
||||
(epicsThreadPriorityScanLow - 3),
|
||||
epicsThreadGetStackSize(epicsThreadStackBig),
|
||||
(EPICSTHREADFUNC)asCaTask,0);
|
||||
if(threadid==0) {
|
||||
errMessage(0,"asCaStart: taskSpawn Failure\n");
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ of this distribution.
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "cantProceed.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "errlog.h"
|
||||
#include "taskwd.h"
|
||||
#include "alarm.h"
|
||||
@@ -46,7 +46,7 @@ of this distribution.
|
||||
|
||||
static char *pacf=NULL;
|
||||
static char *psubstitutions=NULL;
|
||||
static threadId asInitTheadId=0;
|
||||
static epicsThreadId asInitTheadId=0;
|
||||
static int firstTime = TRUE;
|
||||
|
||||
static long asDbAddRecords(void)
|
||||
@@ -123,10 +123,10 @@ static long asInitCommon(void)
|
||||
long status;
|
||||
int asWasActive = asActive;
|
||||
int wasFirstTime = firstTime;
|
||||
static threadOnceId asInitCommonOnceFlag = OSITHREAD_ONCE_INIT;
|
||||
static epicsThreadOnceId asInitCommonOnceFlag = EPICS_THREAD_ONCE_INIT;
|
||||
|
||||
|
||||
threadOnce(&asInitCommonOnceFlag,asInitCommonOnce,(void *)&firstTime);
|
||||
epicsThreadOnce(&asInitCommonOnceFlag,asInitCommonOnce,(void *)&firstTime);
|
||||
if(wasFirstTime) {
|
||||
if(!pacf) return(0); /*access security will NEVER be turned on*/
|
||||
} else {
|
||||
@@ -167,9 +167,9 @@ static void asInitTask(ASDBCALLBACK *pcallback)
|
||||
{
|
||||
long status;
|
||||
|
||||
taskwdInsert(threadGetIdSelf(),(TASKWDFUNCPRR)wdCallback,(void *)pcallback);
|
||||
taskwdInsert(epicsThreadGetIdSelf(),(TASKWDFUNCPRR)wdCallback,(void *)pcallback);
|
||||
status = asInitCommon();
|
||||
taskwdRemove(threadGetIdSelf());
|
||||
taskwdRemove(epicsThreadGetIdSelf());
|
||||
asInitTheadId = 0;
|
||||
if(pcallback) {
|
||||
pcallback->status = status;
|
||||
@@ -188,12 +188,12 @@ int epicsShareAPI asInitAsyn(ASDBCALLBACK *pcallback)
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
asInitTheadId = threadCreate("asInitTask",
|
||||
(threadPriorityChannelAccessServer + 9),
|
||||
threadGetStackSize(threadStackBig),
|
||||
(THREADFUNC)asInitTask,(void *)pcallback);
|
||||
asInitTheadId = epicsThreadCreate("asInitTask",
|
||||
(epicsThreadPriorityChannelAccessServer + 9),
|
||||
epicsThreadGetStackSize(epicsThreadStackBig),
|
||||
(EPICSTHREADFUNC)asInitTask,(void *)pcallback);
|
||||
if(asInitTheadId==0) {
|
||||
errMessage(0,"asInit: threadCreate Error");
|
||||
errMessage(0,"asInit: epicsThreadCreate Error");
|
||||
if(pcallback) {
|
||||
pcallback->status = S_asLib_InitFailed;
|
||||
callbackRequest(&pcallback->callback);
|
||||
|
||||
@@ -25,7 +25,7 @@ of this distribution.
|
||||
#include <string.h>
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "ellLib.h"
|
||||
#include "cantProceed.h"
|
||||
#include "epicsMutex.h"
|
||||
@@ -100,9 +100,9 @@ long epicsShareAPI asInitialize(ASINPUTFUNCPTR inputfunction)
|
||||
UAGNAME *puagname;
|
||||
HAG *phag;
|
||||
HAGNAME *phagname;
|
||||
static threadOnceId asInitializeOnceFlag = OSITHREAD_ONCE_INIT;
|
||||
static epicsThreadOnceId asInitializeOnceFlag = EPICS_THREAD_ONCE_INIT;
|
||||
|
||||
threadOnce(&asInitializeOnceFlag,asInitializeOnce,(void *)0);
|
||||
epicsThreadOnce(&asInitializeOnceFlag,asInitializeOnce,(void *)0);
|
||||
LOCK;
|
||||
pasbasenew = asCalloc(1,sizeof(ASBASE));
|
||||
if(!freeListPvt) freeListInitPvt(&freeListPvt,sizeof(ASGCLIENT),20);
|
||||
|
||||
@@ -85,12 +85,12 @@ int CASG::block ( double timeout )
|
||||
/*
|
||||
* dont allow recursion
|
||||
*/
|
||||
void *p = threadPrivateGet (cacRecursionLock);
|
||||
void *p = epicsThreadPrivateGet (cacRecursionLock);
|
||||
if ( p ) {
|
||||
return ECA_EVDISALLOW;
|
||||
}
|
||||
|
||||
threadPrivateSet (cacRecursionLock, &cacRecursionLock);
|
||||
epicsThreadPrivateSet (cacRecursionLock, &cacRecursionLock);
|
||||
|
||||
cur_time = osiTime::getCurrent ();
|
||||
|
||||
@@ -140,7 +140,7 @@ int CASG::block ( double timeout )
|
||||
|
||||
this->client.disableCallbackPreemption ();
|
||||
|
||||
threadPrivateSet (cacRecursionLock, NULL);
|
||||
epicsThreadPrivateSet (cacRecursionLock, NULL);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -27,16 +27,16 @@
|
||||
#include "oldAccess.h"
|
||||
#include "cac_IL.h"
|
||||
|
||||
threadPrivateId caClientContextId;
|
||||
epicsThreadPrivateId caClientContextId;
|
||||
|
||||
threadPrivateId cacRecursionLock;
|
||||
epicsThreadPrivateId cacRecursionLock;
|
||||
|
||||
static threadOnceId caClientContextIdOnce = OSITHREAD_ONCE_INIT;
|
||||
static epicsThreadOnceId caClientContextIdOnce = EPICS_THREAD_ONCE_INIT;
|
||||
|
||||
extern "C" void ca_client_exit_handler ()
|
||||
{
|
||||
if ( caClientContextId ) {
|
||||
threadPrivateDelete ( caClientContextId );
|
||||
epicsThreadPrivateDelete ( caClientContextId );
|
||||
caClientContextId = 0;
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ extern "C" void ca_client_exit_handler ()
|
||||
// runs once only for each process
|
||||
extern "C" void ca_init_client_context ( void * )
|
||||
{
|
||||
caClientContextId = threadPrivateCreate ();
|
||||
caClientContextId = epicsThreadPrivateCreate ();
|
||||
if ( caClientContextId ) {
|
||||
atexit ( ca_client_exit_handler );
|
||||
}
|
||||
@@ -58,20 +58,20 @@ int fetchClientContext ( cac **ppcac )
|
||||
int status;
|
||||
|
||||
if ( caClientContextId == 0 ) {
|
||||
threadOnce ( &caClientContextIdOnce, ca_init_client_context, 0 );
|
||||
epicsThreadOnce ( &caClientContextIdOnce, ca_init_client_context, 0 );
|
||||
if ( caClientContextId == 0 ) {
|
||||
return ECA_ALLOCMEM;
|
||||
}
|
||||
}
|
||||
|
||||
*ppcac = ( cac * ) threadPrivateGet ( caClientContextId );
|
||||
*ppcac = ( cac * ) epicsThreadPrivateGet ( caClientContextId );
|
||||
if ( *ppcac ) {
|
||||
status = ECA_NORMAL;
|
||||
}
|
||||
else {
|
||||
status = ca_task_initialize ();
|
||||
if ( status == ECA_NORMAL ) {
|
||||
*ppcac = (cac *) threadPrivateGet ( caClientContextId );
|
||||
*ppcac = (cac *) epicsThreadPrivateGet ( caClientContextId );
|
||||
if ( ! *ppcac ) {
|
||||
status = ECA_INTERNAL;
|
||||
}
|
||||
@@ -119,13 +119,13 @@ extern "C" epicsShareFunc int epicsShareAPI ca_context_create ( int preemptiveCa
|
||||
{
|
||||
cac *pcac;
|
||||
|
||||
threadOnce ( &caClientContextIdOnce, ca_init_client_context, 0);
|
||||
epicsThreadOnce ( &caClientContextIdOnce, ca_init_client_context, 0);
|
||||
|
||||
if ( caClientContextId == 0 ) {
|
||||
return ECA_ALLOCMEM;
|
||||
}
|
||||
|
||||
pcac = (cac *) threadPrivateGet ( caClientContextId );
|
||||
pcac = (cac *) epicsThreadPrivateGet ( caClientContextId );
|
||||
if ( pcac ) {
|
||||
return ECA_NORMAL;
|
||||
}
|
||||
@@ -135,7 +135,7 @@ extern "C" epicsShareFunc int epicsShareAPI ca_context_create ( int preemptiveCa
|
||||
return ECA_ALLOCMEM;
|
||||
}
|
||||
|
||||
threadPrivateSet ( caClientContextId, (void *) pcac );
|
||||
epicsThreadPrivateSet ( caClientContextId, (void *) pcac );
|
||||
|
||||
return ECA_NORMAL;
|
||||
}
|
||||
@@ -185,10 +185,10 @@ extern "C" epicsShareFunc int epicsShareAPI ca_context_destroy ()
|
||||
cac *pcac;
|
||||
|
||||
if ( caClientContextId != NULL ) {
|
||||
pcac = (cac *) threadPrivateGet ( caClientContextId );
|
||||
pcac = (cac *) epicsThreadPrivateGet ( caClientContextId );
|
||||
if ( pcac ) {
|
||||
delete pcac;
|
||||
threadPrivateSet ( caClientContextId, 0 );
|
||||
epicsThreadPrivateSet ( caClientContextId, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,7 +553,7 @@ extern "C" void epicsShareAPI ca_signal_formated ( long ca_status, const char *p
|
||||
};
|
||||
|
||||
if ( caClientContextId ) {
|
||||
pcac = (cac *) threadPrivateGet ( caClientContextId );
|
||||
pcac = (cac *) epicsThreadPrivateGet ( caClientContextId );
|
||||
}
|
||||
else {
|
||||
pcac = NULL;
|
||||
@@ -688,7 +688,7 @@ int ca_printf ( const char *pformat, ... )
|
||||
int ca_vPrintf ( const char *pformat, va_list args )
|
||||
{
|
||||
if ( caClientContextId ) {
|
||||
cac *pcac = (cac *) threadPrivateGet ( caClientContextId );
|
||||
cac *pcac = (cac *) epicsThreadPrivateGet ( caClientContextId );
|
||||
if ( pcac ) {
|
||||
return pcac->vPrintf ( pformat, args );
|
||||
}
|
||||
@@ -790,7 +790,7 @@ extern "C" unsigned epicsShareAPI ca_get_ioc_connection_count ()
|
||||
return pcac->connectionCount ();
|
||||
}
|
||||
|
||||
extern "C" epicsShareFunc int epicsShareAPI ca_channel_status ( threadId /* tid */ )
|
||||
extern "C" epicsShareFunc int epicsShareAPI ca_channel_status ( epicsThreadId /* tid */ )
|
||||
{
|
||||
printf ("new OSI API does not allow peeking at thread private storage of another thread\n");
|
||||
printf ("please call \"ca_client_status ( unsigned level )\" from the subsystem specific diagnostic code.\n");
|
||||
@@ -820,7 +820,7 @@ extern "C" epicsShareFunc int epicsShareAPI ca_client_status ( unsigned level )
|
||||
extern "C" epicsShareFunc int epicsShareAPI ca_current_context (caClientCtx *pCurrentContext)
|
||||
{
|
||||
if ( caClientContextId ) {
|
||||
void *pCtx = threadPrivateGet ( caClientContextId );
|
||||
void *pCtx = epicsThreadPrivateGet ( caClientContextId );
|
||||
if (pCtx) {
|
||||
*pCurrentContext = pCtx;
|
||||
return ECA_NORMAL;
|
||||
@@ -844,11 +844,11 @@ extern "C" epicsShareFunc int epicsShareAPI ca_attach_context (caClientCtx conte
|
||||
{
|
||||
cac *pcac;
|
||||
|
||||
pcac = (cac *) threadPrivateGet ( caClientContextId );
|
||||
pcac = (cac *) epicsThreadPrivateGet ( caClientContextId );
|
||||
if ( pcac && context != 0 ) {
|
||||
return ECA_ISATTACHED;
|
||||
}
|
||||
threadPrivateSet ( caClientContextId, context );
|
||||
epicsThreadPrivateSet ( caClientContextId, context );
|
||||
return ECA_NORMAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,14 @@
|
||||
extern "C" void cacRecursionLockExitHandler ()
|
||||
{
|
||||
if ( cacRecursionLock ) {
|
||||
threadPrivateDelete ( cacRecursionLock );
|
||||
epicsThreadPrivateDelete ( cacRecursionLock );
|
||||
cacRecursionLock = 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void cacInitRecursionLock ( void * )
|
||||
{
|
||||
cacRecursionLock = threadPrivateCreate ();
|
||||
cacRecursionLock = epicsThreadPrivateCreate ();
|
||||
if ( cacRecursionLock ) {
|
||||
atexit ( cacRecursionLockExitHandler );
|
||||
}
|
||||
@@ -50,14 +50,14 @@ cac::cac ( bool enablePreemptiveCallbackIn ) :
|
||||
pudpiiu ( 0 ),
|
||||
pSearchTmr ( 0 ),
|
||||
pRepeaterSubscribeTmr ( 0 ),
|
||||
initializingThreadsPriority ( threadGetPrioritySelf () ),
|
||||
initializingThreadsPriority ( epicsThreadGetPrioritySelf () ),
|
||||
enablePreemptiveCallback ( enablePreemptiveCallbackIn )
|
||||
{
|
||||
long status;
|
||||
static threadOnceId once = OSITHREAD_ONCE_INIT;
|
||||
static epicsThreadOnceId once = EPICS_THREAD_ONCE_INIT;
|
||||
unsigned abovePriority;
|
||||
|
||||
threadOnce ( &once, cacInitRecursionLock, 0 );
|
||||
epicsThreadOnce ( &once, cacInitRecursionLock, 0 );
|
||||
|
||||
if ( cacRecursionLock == 0 ) {
|
||||
throwWithLocation ( caErrorCode (ECA_ALLOCMEM) );
|
||||
@@ -68,10 +68,10 @@ cac::cac ( bool enablePreemptiveCallbackIn ) :
|
||||
}
|
||||
|
||||
{
|
||||
threadBoolStatus tbs;
|
||||
epicsThreadBooleanStatus tbs;
|
||||
|
||||
tbs = threadLowestPriorityLevelAbove ( this->initializingThreadsPriority, &abovePriority);
|
||||
if ( tbs != tbsSuccess ) {
|
||||
tbs = epicsThreadLowestPriorityLevelAbove ( this->initializingThreadsPriority, &abovePriority);
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
abovePriority = this->initializingThreadsPriority;
|
||||
}
|
||||
}
|
||||
@@ -518,12 +518,12 @@ int cac::pend ( double timeout, int early )
|
||||
/*
|
||||
* dont allow recursion
|
||||
*/
|
||||
p = threadPrivateGet ( cacRecursionLock );
|
||||
p = epicsThreadPrivateGet ( cacRecursionLock );
|
||||
if (p) {
|
||||
return ECA_EVDISALLOW;
|
||||
}
|
||||
|
||||
threadPrivateSet ( cacRecursionLock, &cacRecursionLock );
|
||||
epicsThreadPrivateSet ( cacRecursionLock, &cacRecursionLock );
|
||||
|
||||
this->enableCallbackPreemption ();
|
||||
|
||||
@@ -531,7 +531,7 @@ int cac::pend ( double timeout, int early )
|
||||
|
||||
this->disableCallbackPreemption ();
|
||||
|
||||
threadPrivateSet ( cacRecursionLock, NULL );
|
||||
epicsThreadPrivateSet ( cacRecursionLock, NULL );
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -1039,7 +1039,7 @@ void cac::destroyNCIU ( nciu & chan )
|
||||
bool cac::flushPermit () const
|
||||
{
|
||||
if ( this->pRecvProcThread ) {
|
||||
if ( this->pRecvProcThread->isCurrentThread () ) {
|
||||
if ( this->pRecvProcThread->thread.isCurrentThread () ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "shareLib.h"
|
||||
#include "caerr.h"
|
||||
#include "db_access.h"
|
||||
@@ -941,14 +941,14 @@ typedef void * caClientCtx;
|
||||
epicsShareFunc int epicsShareAPI ca_current_context (caClientCtx *pCurrentContext);
|
||||
epicsShareFunc int epicsShareAPI ca_attach_context (caClientCtx context);
|
||||
|
||||
epicsShareFunc int epicsShareAPI ca_channel_status (threadId tid);
|
||||
epicsShareFunc int epicsShareAPI ca_channel_status (epicsThreadId tid);
|
||||
epicsShareFunc int epicsShareAPI ca_client_status (unsigned level);
|
||||
|
||||
/*
|
||||
* deprecated
|
||||
*/
|
||||
epicsShareFunc int epicsShareAPI ca_import (threadId tid);
|
||||
epicsShareFunc int epicsShareAPI ca_import_cancel (threadId tid);
|
||||
epicsShareFunc int epicsShareAPI ca_import (epicsThreadId tid);
|
||||
epicsShareFunc int epicsShareAPI ca_import_cancel (epicsThreadId tid);
|
||||
|
||||
|
||||
#else /* CAC_ANSI_FUNC_PROTO */
|
||||
|
||||
@@ -68,7 +68,7 @@ int main ( int argc, char **argv )
|
||||
unsigned attemptNumber = 0u;
|
||||
while ( true ) {
|
||||
caRepeaterRegistrationMessage ( sock, repeaterPort, attemptNumber );
|
||||
threadSleep ( 0.1 );
|
||||
epicsThreadSleep ( 0.1 );
|
||||
addrSize = ( osiSocklen_t ) sizeof ( addr );
|
||||
status = recvfrom ( sock, buf, sizeof ( buf ), 0,
|
||||
&addr.sa, &addrSize );
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#include "tsDLList.h"
|
||||
#include "osiSock.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "osiTimer.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
@@ -486,7 +486,7 @@ static const unsigned contiguousMsgCountWhichTriggersFlowControl = 10u;
|
||||
|
||||
enum iiu_conn_state {iiu_connecting, iiu_connected, iiu_disconnected};
|
||||
|
||||
extern threadPrivateId cacRecursionLock;
|
||||
extern epicsThreadPrivateId cacRecursionLock;
|
||||
|
||||
class netiiu {
|
||||
public:
|
||||
@@ -610,7 +610,7 @@ private:
|
||||
char xmitBuf [MAX_UDP_SEND];
|
||||
char recvBuf [MAX_UDP_RECV];
|
||||
ELLLIST dest;
|
||||
threadId recvThreadId;
|
||||
epicsThreadId recvThreadId;
|
||||
epicsEventId recvThreadExitSignal;
|
||||
unsigned nBytesInXmitBuf;
|
||||
SOCKET sock;
|
||||
@@ -900,16 +900,17 @@ private:
|
||||
int code;
|
||||
};
|
||||
|
||||
class recvProcessThread : public osiThread {
|
||||
class recvProcessThread : public epicsThreadRunable {
|
||||
public:
|
||||
recvProcessThread ( class cac *pcacIn );
|
||||
~recvProcessThread ();
|
||||
void entryPoint ();
|
||||
void run ();
|
||||
void signalShutDown ();
|
||||
void enable ();
|
||||
void disable ();
|
||||
void signalActivity ();
|
||||
void show ( unsigned level ) const;
|
||||
epicsThread thread;
|
||||
private:
|
||||
//
|
||||
// The additional complexity associated with
|
||||
@@ -929,13 +930,14 @@ private:
|
||||
bool shutDown;
|
||||
};
|
||||
|
||||
class sendProcessThread : public osiThread {
|
||||
class sendProcessThread : public epicsThreadRunable {
|
||||
public:
|
||||
sendProcessThread ( class cac &cacIn );
|
||||
~sendProcessThread ();
|
||||
void entryPoint ();
|
||||
void run ();
|
||||
void signalShutDown ();
|
||||
void signalActivity ();
|
||||
epicsThread thread;
|
||||
private:
|
||||
epicsEvent sendActivity;
|
||||
class cac &cacRef;
|
||||
|
||||
@@ -20,24 +20,26 @@
|
||||
#include "cac_IL.h"
|
||||
|
||||
recvProcessThread::recvProcessThread (cac *pcacIn) :
|
||||
osiThread ( "CAC-recv-process", threadGetStackSize (threadStackSmall),
|
||||
pcacIn->getInitializingThreadsPriority () ),
|
||||
thread(*this, "CAC-recv-process",
|
||||
epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||
pcacIn->getInitializingThreadsPriority() ),
|
||||
pcac ( pcacIn ),
|
||||
enableRefCount ( 0u ),
|
||||
blockingForCompletion ( 0u ),
|
||||
processing ( false ),
|
||||
shutDown ( false )
|
||||
{
|
||||
this->start ();
|
||||
this->thread.start ();
|
||||
}
|
||||
|
||||
recvProcessThread::~recvProcessThread ()
|
||||
{
|
||||
this->signalShutDown ();
|
||||
this->exit.wait ();
|
||||
delete &thread;
|
||||
}
|
||||
|
||||
void recvProcessThread::entryPoint ()
|
||||
void recvProcessThread::run ()
|
||||
{
|
||||
int status = ca_attach_context ( this->pcac );
|
||||
SEVCHK ( status, "attaching to client context in recv process thread" );
|
||||
|
||||
@@ -562,7 +562,7 @@ void epicsShareAPI ca_repeater ()
|
||||
*/
|
||||
void caRepeaterThread ( void * /* pDummy */ )
|
||||
{
|
||||
taskwdInsert ( threadGetIdSelf(), NULL, NULL );
|
||||
taskwdInsert ( epicsThreadGetIdSelf(), NULL, NULL );
|
||||
ca_repeater ();
|
||||
}
|
||||
|
||||
|
||||
@@ -303,15 +303,15 @@ extern "C" void cacRecvThreadTCP ( void *pParam )
|
||||
epicsAutoMutex autoMutex ( piiu->mutex );
|
||||
if ( piiu->state == iiu_connected ) {
|
||||
unsigned priorityOfSend;
|
||||
threadBoolStatus tbs;
|
||||
threadId tid;
|
||||
epicsThreadBooleanStatus tbs;
|
||||
epicsThreadId tid;
|
||||
|
||||
tbs = threadLowestPriorityLevelAbove ( piiu->pCAC ()->getInitializingThreadsPriority (), &priorityOfSend );
|
||||
if ( tbs != tbsSuccess ) {
|
||||
tbs = epicsThreadLowestPriorityLevelAbove ( piiu->pCAC ()->getInitializingThreadsPriority (), &priorityOfSend );
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
priorityOfSend = piiu->pCAC ()->getInitializingThreadsPriority ();
|
||||
}
|
||||
tid = threadCreate ( "CAC-TCP-send", priorityOfSend,
|
||||
threadGetStackSize ( threadStackMedium ), cacSendThreadTCP, piiu );
|
||||
tid = epicsThreadCreate ( "CAC-TCP-send", priorityOfSend,
|
||||
epicsThreadGetStackSize ( epicsThreadStackMedium ), cacSendThreadTCP, piiu );
|
||||
if ( ! tid ) {
|
||||
epicsEventSignal ( piiu->recvThreadExitSignal );
|
||||
epicsEventSignal ( piiu->sendThreadExitSignal );
|
||||
@@ -353,7 +353,7 @@ extern "C" void cacRecvThreadTCP ( void *pParam )
|
||||
}
|
||||
else {
|
||||
// no way to be informed when memory is available
|
||||
threadSleep ( 0.5 );
|
||||
epicsThreadSleep ( 0.5 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,8 +429,8 @@ bool tcpiiu::initiateConnect ( const osiSockAddr &addrIn, unsigned minorVersion,
|
||||
class bhe &bhe, ipAddrToAsciiEngine &engineIn )
|
||||
{
|
||||
unsigned priorityOfRecv;
|
||||
threadBoolStatus tbs;
|
||||
threadId tid;
|
||||
epicsThreadBooleanStatus tbs;
|
||||
epicsThreadId tid;
|
||||
int status;
|
||||
int flag;
|
||||
|
||||
@@ -511,13 +511,13 @@ bool tcpiiu::initiateConnect ( const osiSockAddr &addrIn, unsigned minorVersion,
|
||||
|
||||
memset ( (void *) &this->curMsg, '\0', sizeof ( this->curMsg ) );
|
||||
|
||||
tbs = threadHighestPriorityLevelBelow ( this->pCAC ()->getInitializingThreadsPriority (), &priorityOfRecv );
|
||||
if ( tbs != tbsSuccess ) {
|
||||
tbs = epicsThreadHighestPriorityLevelBelow ( this->pCAC ()->getInitializingThreadsPriority (), &priorityOfRecv );
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
priorityOfRecv = this->pCAC ()->getInitializingThreadsPriority ();
|
||||
}
|
||||
|
||||
tid = threadCreate ("CAC-TCP-recv", priorityOfRecv,
|
||||
threadGetStackSize (threadStackMedium), cacRecvThreadTCP, this);
|
||||
tid = epicsThreadCreate ("CAC-TCP-recv", priorityOfRecv,
|
||||
epicsThreadGetStackSize (epicsThreadStackMedium), cacRecvThreadTCP, this);
|
||||
if ( tid == 0 ) {
|
||||
ca_printf ("CA: unable to create CA client receive thread\n");
|
||||
socket_close ( this->sock );
|
||||
|
||||
@@ -314,10 +314,10 @@ epicsShareFunc void epicsShareAPI caStartRepeaterIfNotInstalled ( unsigned repea
|
||||
*/
|
||||
osptr = osiSpawnDetachedProcess ( "CA Repeater", "caRepeater" );
|
||||
if ( osptr == osiSpawnDetachedProcessNoSupport ) {
|
||||
threadId tid;
|
||||
epicsThreadId tid;
|
||||
|
||||
tid = threadCreate ( "CAC-repeater", threadPriorityLow,
|
||||
threadGetStackSize (threadStackMedium), caRepeaterThread, 0);
|
||||
tid = epicsThreadCreate ( "CAC-repeater", epicsThreadPriorityLow,
|
||||
epicsThreadGetStackSize (epicsThreadStackMedium), caRepeaterThread, 0);
|
||||
if ( tid == 0 ) {
|
||||
ca_printf ("caStartRepeaterIfNotInstalled : unable to create CA repeater daemon thread\n");
|
||||
}
|
||||
@@ -413,16 +413,16 @@ udpiiu::udpiiu ( cac &cac ) :
|
||||
|
||||
{
|
||||
unsigned priorityOfRecv;
|
||||
threadBoolStatus tbs;
|
||||
epicsThreadBooleanStatus tbs;
|
||||
|
||||
tbs = threadLowestPriorityLevelAbove (
|
||||
tbs = epicsThreadLowestPriorityLevelAbove (
|
||||
this->pCAC ()->getInitializingThreadsPriority (), &priorityOfRecv );
|
||||
if ( tbs != tbsSuccess ) {
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
priorityOfRecv = this->pCAC ()->getInitializingThreadsPriority ();
|
||||
}
|
||||
|
||||
this->recvThreadId = threadCreate ( "CAC-UDP", priorityOfRecv,
|
||||
threadGetStackSize (threadStackMedium), cacRecvThreadUDP, this );
|
||||
this->recvThreadId = epicsThreadCreate ( "CAC-UDP", priorityOfRecv,
|
||||
epicsThreadGetStackSize (epicsThreadStackMedium), cacRecvThreadUDP, this );
|
||||
if ( this->recvThreadId == 0 ) {
|
||||
ca_printf ("CA: unable to create UDP receive thread\n");
|
||||
epicsEventDestroy (this->recvThreadExitSignal);
|
||||
@@ -852,5 +852,5 @@ void udpiiu::show ( unsigned level ) const
|
||||
|
||||
bool udpiiu::isCurrentThread () const
|
||||
{
|
||||
return ( this->recvThreadId == threadGetIdSelf () );
|
||||
return ( this->recvThreadId == epicsThreadGetIdSelf () );
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ of this distribution.
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "osiInterrupt.h"
|
||||
#include "osiTimer.h"
|
||||
#include "epicsRingPointer.h"
|
||||
@@ -42,7 +42,7 @@ of this distribution.
|
||||
int callbackQueueSize = 2000;
|
||||
static epicsEventId callbackSem[NUM_CALLBACK_PRIORITIES];
|
||||
static epicsRingPointerId callbackQ[NUM_CALLBACK_PRIORITIES];
|
||||
static threadId callbackTaskId[NUM_CALLBACK_PRIORITIES];
|
||||
static epicsThreadId callbackTaskId[NUM_CALLBACK_PRIORITIES];
|
||||
static int ringOverflow[NUM_CALLBACK_PRIORITIES];
|
||||
static void callbackInitPvt(void *);
|
||||
volatile int callbackRestart=FALSE;
|
||||
@@ -74,7 +74,7 @@ static void callbackInitPvt(void *arg)
|
||||
{
|
||||
int i;
|
||||
|
||||
timerQueue = osiTimerQueueCreate(threadPriorityScanHigh);
|
||||
timerQueue = osiTimerQueueCreate(epicsThreadPriorityScanHigh);
|
||||
for(i=0; i<NUM_CALLBACK_PRIORITIES; i++) {
|
||||
start(i);
|
||||
}
|
||||
@@ -82,9 +82,9 @@ static void callbackInitPvt(void *arg)
|
||||
|
||||
void epicsShareAPI callbackInit()
|
||||
{
|
||||
static threadOnceId callbackOnceFlag = OSITHREAD_ONCE_INIT;
|
||||
static epicsThreadOnceId callbackOnceFlag = EPICS_THREAD_ONCE_INIT;
|
||||
void *arg = 0;
|
||||
threadOnce(&callbackOnceFlag,callbackInitPvt,arg);
|
||||
epicsThreadOnce(&callbackOnceFlag,callbackInitPvt,arg);
|
||||
}
|
||||
|
||||
/* Routine which places requests into callback queue*/
|
||||
@@ -137,9 +137,9 @@ static void start(int ind)
|
||||
char taskName[20];
|
||||
|
||||
callbackSem[ind] = epicsEventMustCreate(epicsEventEmpty);
|
||||
if(ind==0) priority = threadPriorityScanLow - 1;
|
||||
else if(ind==1) priority = threadPriorityScanLow +4;
|
||||
else if(ind==2) priority = threadPriorityScanHigh + 1;
|
||||
if(ind==0) priority = epicsThreadPriorityScanLow - 1;
|
||||
else if(ind==1) priority = epicsThreadPriorityScanLow +4;
|
||||
else if(ind==2) priority = epicsThreadPriorityScanHigh + 1;
|
||||
else {
|
||||
errMessage(0,"callback start called with illegal priority\n");
|
||||
return;
|
||||
@@ -147,8 +147,8 @@ static void start(int ind)
|
||||
if((callbackQ[ind]=epicsRingPointerCreate(callbackQueueSize)) == 0)
|
||||
errMessage(0,"epicsRingPointerCreate failed while starting a callback task");
|
||||
sprintf(taskName,"cb%s",priorityName[ind]);
|
||||
callbackTaskId[ind] = threadCreate(taskName,priority,
|
||||
threadGetStackSize(threadStackBig),(THREADFUNC)callbackTask,
|
||||
callbackTaskId[ind] = epicsThreadCreate(taskName,priority,
|
||||
epicsThreadGetStackSize(epicsThreadStackBig),(EPICSTHREADFUNC)callbackTask,
|
||||
&priorityValue[ind]);
|
||||
if(callbackTaskId[ind]==0) {
|
||||
errMessage(0,"Failed to spawn a callback task");
|
||||
|
||||
@@ -46,7 +46,7 @@ of this distribution.
|
||||
#include <string.h>
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "errlog.h"
|
||||
#include "cantProceed.h"
|
||||
#include "cvtFast.h"
|
||||
|
||||
@@ -14,6 +14,9 @@ of this distribution.
|
||||
/* Modification Log:
|
||||
* -----------------
|
||||
* $Log$
|
||||
* Revision 1.25 2001/01/12 00:27:16 jhill
|
||||
* fixed bugs introduced by APS's osi => epics name changes
|
||||
*
|
||||
* Revision 1.24 2001/01/11 16:11:21 mrk
|
||||
* replace osiSem with epicsMutex and/or epicsEvent
|
||||
*
|
||||
@@ -33,7 +36,7 @@ of this distribution.
|
||||
* changes for creating win dlls
|
||||
*
|
||||
* Revision 1.18 2000/02/26 23:45:22 norume
|
||||
* Reflect routine name change from threadSuspend() to threadSuspendSelf().
|
||||
* Reflect routine name change from threadSuspend() to epicsThreadSuspendSelf().
|
||||
*
|
||||
* Revision 1.17 2000/02/25 22:26:38 mrk
|
||||
* more changes for creating dlls
|
||||
@@ -107,7 +110,7 @@ of this distribution.
|
||||
#include <string.h>
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "tsStamp.h"
|
||||
@@ -426,9 +429,9 @@ long epicsShareAPI dbb(const char *record_name)
|
||||
/*
|
||||
* Spawn continuation task
|
||||
*/
|
||||
pnode->taskid = threadCreate("bkptCont",threadPriorityScanLow-1,
|
||||
threadGetStackSize(threadStackBig),
|
||||
(THREADFUNC)dbBkptCont,precord);
|
||||
pnode->taskid = epicsThreadCreate("bkptCont",epicsThreadPriorityScanLow-1,
|
||||
epicsThreadGetStackSize(epicsThreadStackBig),
|
||||
(EPICSTHREADFUNC)dbBkptCont,precord);
|
||||
if (pnode->taskid == 0) {
|
||||
printf(" BKPT> Cannot spawn task to process record\n");
|
||||
pnode->taskid = 0;
|
||||
@@ -567,7 +570,7 @@ long epicsShareAPI dbc(const char *record_name)
|
||||
* for a record with a breakpoint. This occurs
|
||||
* because stepping mode has been switched off.
|
||||
*/
|
||||
threadResume(pnode->taskid);
|
||||
epicsThreadResume(pnode->taskid);
|
||||
epicsMutexUnlock(bkpt_stack_sem);
|
||||
return(0);
|
||||
}
|
||||
@@ -596,7 +599,7 @@ long epicsShareAPI dbs(const char *record_name)
|
||||
|
||||
last_lset = pnode->l_num;
|
||||
|
||||
threadResume(pnode->taskid);
|
||||
epicsThreadResume(pnode->taskid);
|
||||
epicsMutexUnlock(bkpt_stack_sem);
|
||||
return(0);
|
||||
}
|
||||
@@ -758,7 +761,7 @@ int epicsShareAPI dbBkpt(dbCommon *precord)
|
||||
* source, queue its execution, but dump out of dbProcess without
|
||||
* calling record support.
|
||||
*/
|
||||
if (pnode->taskid && (threadGetIdSelf() != pnode->taskid)) {
|
||||
if (pnode->taskid && (epicsThreadGetIdSelf() != pnode->taskid)) {
|
||||
/* CONTINUE TASK CANNOT ENTER HERE */
|
||||
|
||||
/*
|
||||
@@ -855,7 +858,7 @@ int epicsShareAPI dbBkpt(dbCommon *precord)
|
||||
*/
|
||||
epicsMutexUnlock(bkpt_stack_sem);
|
||||
dbScanUnlock(precord);
|
||||
threadSuspendSelf();
|
||||
epicsThreadSuspendSelf();
|
||||
dbScanLock(precord);
|
||||
epicsMutexMustLock(bkpt_stack_sem);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
#ifndef INCdbBkptsh
|
||||
#define INCdbBkptsh 1
|
||||
|
||||
#include "ellLib.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "epicsThread.h"
|
||||
#include "tsStamp.h"
|
||||
#include "shareLib.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -73,7 +77,7 @@ struct LS_LIST {
|
||||
ELLLIST bp_list; /* list of records containing breakpoints in a lockset */
|
||||
ELLLIST ep_queue; /* queue of entrypoints found so far */
|
||||
epicsEventId ex_sem; /* semaphore for execution queue */
|
||||
threadId taskid; /* saved taskid for the task in stepping mode */
|
||||
epicsThreadId taskid; /* saved taskid for the task in stepping mode */
|
||||
int step; /* one if currently "stepping," else zero */
|
||||
unsigned long l_num; /* lockset number */
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ of this distribution.
|
||||
#include "dbDefs.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "tsStamp.h"
|
||||
#include "errlog.h"
|
||||
#include "taskwd.h"
|
||||
@@ -85,8 +85,8 @@ void epicsShareAPI dbCaLinkInit(void)
|
||||
ellInit(&caList);
|
||||
caListSem = epicsMutexMustCreate();
|
||||
caWakeupSem = epicsEventMustCreate(epicsEventEmpty);
|
||||
threadCreate("dbCaLink", threadPriorityMedium,
|
||||
threadGetStackSize(threadStackBig), (THREADFUNC) dbCaTask,0);
|
||||
epicsThreadCreate("dbCaLink", epicsThreadPriorityMedium,
|
||||
epicsThreadGetStackSize(epicsThreadStackBig), (EPICSTHREADFUNC) dbCaTask,0);
|
||||
}
|
||||
|
||||
void epicsShareAPI dbCaAddLink( struct link *plink)
|
||||
@@ -627,13 +627,13 @@ void dbCaTask()
|
||||
short link_action;
|
||||
int status;
|
||||
|
||||
taskwdInsert(threadGetIdSelf(),NULL,NULL);
|
||||
taskwdInsert(epicsThreadGetIdSelf(),NULL,NULL);
|
||||
SEVCHK(ca_context_create(enablePreemption),
|
||||
"dbCaTask calling ca_context_create");
|
||||
SEVCHK(ca_add_exception_event(exceptionCallback,NULL),
|
||||
"ca_add_exception_event");
|
||||
/*Dont do anything until iocInit initializes database*/
|
||||
while(!interruptAccept) threadSleep(.1);
|
||||
while(!interruptAccept) epicsThreadSleep(.1);
|
||||
/* channel access event loop */
|
||||
while (TRUE){
|
||||
epicsEventMustWait(caWakeupSem);
|
||||
|
||||
@@ -29,7 +29,7 @@ of this distribution.
|
||||
#include "dbDefs.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "errlog.h"
|
||||
#include "taskwd.h"
|
||||
#include "freeList.h"
|
||||
@@ -97,13 +97,13 @@ struct event_user {
|
||||
EXTRALABORFUNC *extralabor_sub;/* off load to event task */
|
||||
void *extralabor_arg;/* parameter to above */
|
||||
|
||||
threadId taskid; /* event handler task id */
|
||||
epicsThreadId taskid; /* event handler task id */
|
||||
unsigned queovr; /* event que overflow count */
|
||||
unsigned char pendexit; /* exit pend task */
|
||||
unsigned char extra_labor; /* if set call extra labor func */
|
||||
unsigned char flowCtrlMode; /* replace existing monitor */
|
||||
void (*init_func)();
|
||||
threadId init_func_arg;
|
||||
epicsThreadId init_func_arg;
|
||||
};
|
||||
|
||||
|
||||
@@ -528,7 +528,7 @@ int epicsShareAPI db_flush_extra_labor_event (dbEventCtx ctx)
|
||||
struct event_user *evUser = (struct event_user *) ctx;
|
||||
|
||||
while(evUser->extra_labor){
|
||||
threadSleep(1.0);
|
||||
epicsThreadSleep(1.0);
|
||||
}
|
||||
|
||||
return DB_EVENT_OK;
|
||||
@@ -880,7 +880,7 @@ LOCAL void event_task (void *pParm)
|
||||
(*evUser->init_func)(evUser->init_func_arg);
|
||||
}
|
||||
|
||||
taskwdInsert ( threadGetIdSelf(), NULL, NULL );
|
||||
taskwdInsert ( epicsThreadGetIdSelf(), NULL, NULL );
|
||||
|
||||
do{
|
||||
epicsEventMustWait(evUser->ppendsem);
|
||||
@@ -936,7 +936,7 @@ LOCAL void event_task (void *pParm)
|
||||
|
||||
freeListFree(dbevEventUserFreeList, evUser);
|
||||
|
||||
taskwdRemove(threadGetIdSelf());
|
||||
taskwdRemove(epicsThreadGetIdSelf());
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -945,7 +945,7 @@ LOCAL void event_task (void *pParm)
|
||||
* DB_START_EVENTS()
|
||||
*/
|
||||
int epicsShareAPI db_start_events (
|
||||
dbEventCtx ctx,const char *taskname, void (*init_func)(threadId),
|
||||
dbEventCtx ctx,const char *taskname, void (*init_func)(epicsThreadId),
|
||||
void *init_func_arg, unsigned osiPriority )
|
||||
{
|
||||
struct event_user *evUser = (struct event_user *) ctx;
|
||||
@@ -967,8 +967,8 @@ int epicsShareAPI db_start_events (
|
||||
if (!taskname) {
|
||||
taskname = EVENT_PEND_NAME;
|
||||
}
|
||||
evUser->taskid = threadCreate (
|
||||
taskname, osiPriority, threadGetStackSize(threadStackMedium),
|
||||
evUser->taskid = epicsThreadCreate (
|
||||
taskname, osiPriority, epicsThreadGetStackSize(epicsThreadStackMedium),
|
||||
event_task, (void *)evUser);
|
||||
if (!evUser->taskid) {
|
||||
epicsMutexUnlock (evUser->firstque.writelock);
|
||||
|
||||
@@ -68,7 +68,7 @@ since this will delay all other threads.
|
||||
#include "dbBase.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "tsStamp.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "cantProceed.h"
|
||||
#include "ellLib.h"
|
||||
#include "dbBase.h"
|
||||
@@ -96,7 +96,7 @@ typedef struct lockSet {
|
||||
ELLNODE node;
|
||||
ELLLIST recordList;
|
||||
epicsMutexId lock;
|
||||
threadId thread_id;
|
||||
epicsThreadId thread_id;
|
||||
dbCommon *precord;
|
||||
unsigned long id;
|
||||
} lockSet;
|
||||
@@ -166,11 +166,11 @@ void epicsShareAPI dbLockSetRecordLock(dbCommon *precord)
|
||||
if(!plockRecord) return;
|
||||
plockSet = plockRecord->plockSet;
|
||||
if(!plockSet) return;
|
||||
if(plockSet->thread_id==threadGetIdSelf()) return;
|
||||
if(plockSet->thread_id==epicsThreadGetIdSelf()) return;
|
||||
/*Wait for up to 1 minute*/
|
||||
status = epicsMutexLockWithTimeout(plockRecord->plockSet->lock,60.0);
|
||||
if(status==epicsMutexLockOK) {
|
||||
plockSet->thread_id = threadGetIdSelf();
|
||||
plockSet->thread_id = epicsThreadGetIdSelf();
|
||||
plockSet->precord = (void *)precord;
|
||||
/*give it back in case it will not be changed*/
|
||||
epicsMutexUnlock(plockRecord->plockSet->lock);
|
||||
@@ -178,7 +178,7 @@ void epicsShareAPI dbLockSetRecordLock(dbCommon *precord)
|
||||
}
|
||||
/*Should never reach this point*/
|
||||
errlogPrintf("dbLockSetRecordLock timeout caller 0x%x owner 0x%x",
|
||||
threadGetIdSelf(),plockSet->thread_id);
|
||||
epicsThreadGetIdSelf(),plockSet->thread_id);
|
||||
errlogPrintf(" record %s\n",precord->name);
|
||||
cantProceed("dbLockSetRecordLock");
|
||||
}
|
||||
@@ -192,16 +192,16 @@ void epicsShareAPI dbScanLock(dbCommon *precord)
|
||||
if(!(plockRecord= precord->lset)) {
|
||||
epicsPrintf("dbScanLock plockRecord is NULL record %s\n",
|
||||
precord->name);
|
||||
threadSuspendSelf();
|
||||
epicsThreadSuspendSelf();
|
||||
}
|
||||
while(TRUE) {
|
||||
while(changingLockSets) threadSleep(.05);
|
||||
while(changingLockSets) epicsThreadSleep(.05);
|
||||
status = epicsMutexLock(plockRecord->plockSet->lock);
|
||||
/*epicsMutexLock fails if epicsMutexDestroy was called while active*/
|
||||
if(status==epicsMutexLockOK) break;
|
||||
}
|
||||
plockSet = plockRecord->plockSet;
|
||||
plockSet->thread_id = threadGetIdSelf();
|
||||
plockSet->thread_id = epicsThreadGetIdSelf();
|
||||
plockSet->precord = (void *)precord;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "osiInterrupt.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "tsStamp.h"
|
||||
#include "cantProceed.h"
|
||||
#include "epicsRingPointer.h"
|
||||
@@ -79,7 +79,7 @@
|
||||
int onceQueueSize = 1000;
|
||||
static epicsEventId onceSem;
|
||||
static epicsRingPointerId onceQ;
|
||||
static threadId onceTaskId;
|
||||
static epicsThreadId onceTaskId;
|
||||
|
||||
/*all other scan types */
|
||||
typedef struct scan_list{
|
||||
@@ -117,7 +117,7 @@ static io_scan_list *iosl_head[NUM_CALLBACK_PRIORITIES]={NULL,NULL,NULL};
|
||||
/* PERIODIC SCANNER */
|
||||
static int nPeriodic=0;
|
||||
static scan_list **papPeriodic; /* pointer to array of pointers*/
|
||||
static threadId *periodicTaskId; /*array of thread ids*/
|
||||
static epicsThreadId *periodicTaskId; /*array of thread ids*/
|
||||
|
||||
/* Private routines */
|
||||
static void onceTask(void);
|
||||
@@ -485,9 +485,9 @@ static void initOnce(void)
|
||||
cantProceed("dbScan: initOnce failed");
|
||||
}
|
||||
onceSem=epicsEventMustCreate(epicsEventEmpty);
|
||||
onceTaskId = threadCreate("scanOnce",threadPriorityScanHigh,
|
||||
threadGetStackSize(threadStackBig),
|
||||
(THREADFUNC)onceTask,0);
|
||||
onceTaskId = epicsThreadCreate("scanOnce",epicsThreadPriorityScanHigh,
|
||||
epicsThreadGetStackSize(epicsThreadStackBig),
|
||||
(EPICSTHREADFUNC)onceTask,0);
|
||||
taskwdInsert(onceTaskId,NULL,0L);
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ static void periodicTask(void *arg)
|
||||
diff = tsStampDiffInSeconds(&end_time,&start_time);
|
||||
delay = psl->rate - diff;
|
||||
delay = (delay<=0.0) ? .1 : delay;
|
||||
threadSleep(delay);
|
||||
epicsThreadSleep(delay);
|
||||
tsStampGetCurrent(&start_time);
|
||||
}
|
||||
}
|
||||
@@ -548,11 +548,11 @@ static void spawnPeriodic(int ind)
|
||||
while(taskName[strlen(taskName)-1]=='0') taskName[strlen(taskName)-1] = 0;
|
||||
/*strip trailing . */
|
||||
if(taskName[strlen(taskName)-1]=='.') taskName[strlen(taskName)-1] = 0;
|
||||
periodicTaskId[ind] = threadCreate(
|
||||
periodicTaskId[ind] = epicsThreadCreate(
|
||||
taskName,
|
||||
threadPriorityScanLow + ind,
|
||||
threadGetStackSize(threadStackBig),
|
||||
(THREADFUNC)periodicTask,
|
||||
epicsThreadPriorityScanLow + ind,
|
||||
epicsThreadGetStackSize(epicsThreadStackBig),
|
||||
(EPICSTHREADFUNC)periodicTask,
|
||||
(void *)psl);
|
||||
taskwdInsert(periodicTaskId[ind],NULL,0L);
|
||||
}
|
||||
|
||||
@@ -132,10 +132,10 @@ dbEventSubscription dbServiceIO::subscribe ( struct dbAddr &addr, dbSubscription
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned selfPriority = threadGetPrioritySelf ();
|
||||
unsigned selfPriority = epicsThreadGetPrioritySelf ();
|
||||
unsigned above;
|
||||
threadBoolStatus tbs = threadLowestPriorityLevelAbove (selfPriority, &above);
|
||||
if ( tbs != tbsSuccess ) {
|
||||
epicsThreadBooleanStatus tbs = epicsThreadLowestPriorityLevelAbove (selfPriority, &above);
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
above = selfPriority;
|
||||
}
|
||||
status = db_start_events ( this->ctx, "CAC-event",
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "tsStamp.h"
|
||||
#include "epicsPrint.h"
|
||||
#include "dbBase.h"
|
||||
|
||||
@@ -14,7 +14,7 @@ of this distribution.
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "errlog.h"
|
||||
#include "callback.h"
|
||||
#include "taskwd.h"
|
||||
@@ -68,6 +68,6 @@ void callbackTest(void)
|
||||
wait[i]->requestedDiff = (double)i;
|
||||
callbackRequestDelayed(&wait[i]->callback,wait[i]->requestedDiff);
|
||||
}
|
||||
threadSleep((double)(ncallbacks + 2));
|
||||
epicsThreadSleep((double)(ncallbacks + 2));
|
||||
printf("callbackTest returning\n");
|
||||
}
|
||||
|
||||
@@ -13,14 +13,12 @@ of this distribution.
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
void *pdbbase=NULL;
|
||||
|
||||
void callbackTest(void);
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
threadInit();
|
||||
callbackTest();
|
||||
printf("main terminating\n");
|
||||
return(0);
|
||||
|
||||
@@ -22,7 +22,6 @@ of this distribution.
|
||||
#include <string.h>
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsPrint.h"
|
||||
#include "errMdef.h"
|
||||
#include "dbStaticLib.h"
|
||||
@@ -48,7 +47,6 @@ int main(int argc,char **argv)
|
||||
static char *pathSep = OSI_PATH_LIST_SEPARATOR;
|
||||
static char *subSep = ",";
|
||||
|
||||
threadInit();
|
||||
/*Look for options*/
|
||||
if(argc<2) {
|
||||
fprintf(stderr,
|
||||
|
||||
@@ -19,7 +19,6 @@ of this distribution.
|
||||
#include "dbStaticLib.h"
|
||||
#include "dbStaticPvt.h"
|
||||
#include "osiFileName.h"
|
||||
#include "osiThread.h"
|
||||
|
||||
epicsShareExtern char *makeDbdDepends;
|
||||
|
||||
@@ -40,7 +39,6 @@ int main(int argc,char **argv)
|
||||
static char *pathSep = OSI_PATH_LIST_SEPARATOR;
|
||||
static char *subSep = ",";
|
||||
|
||||
threadInit();
|
||||
/*Look for options*/
|
||||
if(argc<2) {
|
||||
printf("usage: makeDbdDepends -Idir -Smacsub target.dbd input.dbd \n");
|
||||
|
||||
@@ -22,7 +22,6 @@ of this distribution.
|
||||
#include <string.h>
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsPrint.h"
|
||||
#include "errMdef.h"
|
||||
#include "dbStaticLib.h"
|
||||
@@ -48,7 +47,6 @@ int main(int argc,char **argv)
|
||||
static char *pathSep = OSI_PATH_LIST_SEPARATOR;
|
||||
static char *subSep = ",";
|
||||
|
||||
threadInit();
|
||||
/*Look for options*/
|
||||
if(argc<2) {
|
||||
printf("usage: dbReadTest -Idir -Smacsub file.dbd file.db \n");
|
||||
|
||||
@@ -21,7 +21,6 @@ of this distribution.
|
||||
#include <string.h>
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsPrint.h"
|
||||
#include "errMdef.h"
|
||||
#include "dbStaticLib.h"
|
||||
@@ -52,7 +51,6 @@ int main(int argc,char **argv)
|
||||
static char *pathSep = OSI_PATH_LIST_SEPARATOR;
|
||||
static char *subSep = ",";
|
||||
|
||||
threadInit();
|
||||
/*Look for options*/
|
||||
if(argc<2) {
|
||||
fprintf(stderr,"usage: dbToMenu -Idir -Idir file.dbd [outfile]\n");
|
||||
|
||||
@@ -22,7 +22,6 @@ of this distribution.
|
||||
#include <ctype.h>
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsPrint.h"
|
||||
#include "errMdef.h"
|
||||
#include "dbStaticLib.h"
|
||||
@@ -57,7 +56,6 @@ int main(int argc,char **argv)
|
||||
static char *pathSep = OSI_PATH_LIST_SEPARATOR;
|
||||
static char *subSep = ",";
|
||||
|
||||
threadInit();
|
||||
/*Look for options*/
|
||||
if(argc<2) {
|
||||
fprintf(stderr,"usage: dbToRecordtypeH -Idir -Idir file.dbd [outfile]\n");
|
||||
|
||||
@@ -13,8 +13,6 @@ of this distribution.
|
||||
#include <ctype.h>
|
||||
|
||||
#include "ellLib.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "tsStamp.h"
|
||||
#include "errlog.h"
|
||||
#include "alarm.h"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <logClient.h>
|
||||
|
||||
#include "osiUnistd.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "ioccrf.h"
|
||||
@@ -69,7 +69,7 @@ static void showCallFunc(const ioccrfArgBuf *args)
|
||||
int first = 1;
|
||||
int level = 0;
|
||||
char *cp;
|
||||
threadId tid;
|
||||
epicsThreadId tid;
|
||||
unsigned long ltmp;
|
||||
char *endp;
|
||||
|
||||
@@ -79,7 +79,7 @@ static void showCallFunc(const ioccrfArgBuf *args)
|
||||
i++;
|
||||
}
|
||||
if ((cp = args[i].sval) == NULL) {
|
||||
threadShowAll (level);
|
||||
epicsThreadShowAll (level);
|
||||
return;
|
||||
}
|
||||
for ( ; i < 10 ; i++) {
|
||||
@@ -87,29 +87,29 @@ static void showCallFunc(const ioccrfArgBuf *args)
|
||||
return;
|
||||
ltmp = strtoul (cp, &endp, 16);
|
||||
if (*endp) {
|
||||
tid = threadGetId (cp);
|
||||
tid = epicsThreadGetId (cp);
|
||||
if (!tid) {
|
||||
printf ("*** argument %d (%s) is not a valid task name ***\n", i+1, cp);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
tid = (threadId)ltmp;
|
||||
tid = (epicsThreadId)ltmp;
|
||||
}
|
||||
if (first) {
|
||||
threadShow (0, level);
|
||||
epicsThreadShow (0, level);
|
||||
first = 0;
|
||||
}
|
||||
threadShow (tid, level);
|
||||
epicsThreadShow (tid, level);
|
||||
}
|
||||
}
|
||||
|
||||
/* threadInit */
|
||||
static const ioccrfFuncDef threadInitFuncDef =
|
||||
{"threadInit",0};
|
||||
static void threadInitCallFunc(const ioccrfArgBuf *args)
|
||||
/* epicsThreadInit */
|
||||
static const ioccrfFuncDef epicsThreadInitFuncDef =
|
||||
{"epicsThreadInit",0};
|
||||
static void epicsThreadInitCallFunc(const ioccrfArgBuf *args)
|
||||
{
|
||||
threadInit();
|
||||
epicsThreadInit();
|
||||
}
|
||||
|
||||
/* putenv */
|
||||
@@ -149,7 +149,7 @@ void epicsShareAPI iocUtilRegister(void)
|
||||
ioccrfRegister(&chdirFuncDef,chdirCallFunc);
|
||||
ioccrfRegister(&pwdFuncDef,pwdCallFunc);
|
||||
ioccrfRegister(&showFuncDef,showCallFunc);
|
||||
ioccrfRegister(&threadInitFuncDef,threadInitCallFunc);
|
||||
ioccrfRegister(&epicsThreadInitFuncDef,epicsThreadInitCallFunc);
|
||||
ioccrfRegister(&putenvFuncDef,putenvCallFunc);
|
||||
ioccrfRegister(&iocLogInitFuncDef,iocLogInitCallFunc);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ of this distribution.
|
||||
|
||||
#include "errlog.h"
|
||||
#include "dbAccess.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "registry.h"
|
||||
#define epicsExportSharedSymbols
|
||||
@@ -36,7 +36,7 @@ struct ioccrfCommand {
|
||||
static struct ioccrfCommand *ioccrfCommandHead;
|
||||
static char ioccrfID[] = "ioccrf";
|
||||
static epicsMutexId commandTableMutex;
|
||||
static threadOnceId commandTableOnceId = OSITHREAD_ONCE_INIT;
|
||||
static epicsThreadOnceId commandTableOnceId = EPICS_THREAD_ONCE_INIT;
|
||||
|
||||
/*
|
||||
* Set up command table mutex
|
||||
@@ -52,7 +52,7 @@ static void commandTableOnce (void *)
|
||||
static void
|
||||
commandTableLock (void)
|
||||
{
|
||||
threadOnce (&commandTableOnceId, commandTableOnce, NULL);
|
||||
epicsThreadOnce (&commandTableOnceId, commandTableOnce, NULL);
|
||||
epicsMutexMustLock (commandTableMutex);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ commandTableLock (void)
|
||||
static void
|
||||
commandTableUnlock (void)
|
||||
{
|
||||
threadOnce (&commandTableOnceId, commandTableOnce, NULL);
|
||||
epicsThreadOnce (&commandTableOnceId, commandTableOnce, NULL);
|
||||
epicsMutexUnlock (commandTableMutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,34 +12,34 @@ of this distribution.
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "dbEvent.h"
|
||||
#define epicsExportSharedSymbols
|
||||
#include "ioccrf.h"
|
||||
#include "osiRegister.h"
|
||||
|
||||
/* threadShowAll */
|
||||
static const ioccrfArg threadShowAllArg0 = { "level",ioccrfArgInt};
|
||||
static const ioccrfArg * const threadShowAllArgs[1] = {&threadShowAllArg0};
|
||||
static const ioccrfFuncDef threadShowAllFuncDef =
|
||||
{"threadShowAll",1,threadShowAllArgs};
|
||||
static void threadShowAllCallFunc(const ioccrfArgBuf *args)
|
||||
/* epicsThreadShowAll */
|
||||
static const ioccrfArg epicsThreadShowAllArg0 = { "level",ioccrfArgInt};
|
||||
static const ioccrfArg * const epicsThreadShowAllArgs[1] = {&epicsThreadShowAllArg0};
|
||||
static const ioccrfFuncDef epicsThreadShowAllFuncDef =
|
||||
{"epicsThreadShowAll",1,epicsThreadShowAllArgs};
|
||||
static void epicsThreadShowAllCallFunc(const ioccrfArgBuf *args)
|
||||
{
|
||||
threadShowAll(args[0].ival);
|
||||
epicsThreadShowAll(args[0].ival);
|
||||
}
|
||||
|
||||
/* threadSleep */
|
||||
static const ioccrfArg threadSleepArg0 = { "seconds",ioccrfArgDouble};
|
||||
static const ioccrfArg * const threadSleepArgs[1] = {&threadSleepArg0};
|
||||
static const ioccrfFuncDef threadSleepFuncDef =
|
||||
{"threadSleep",1,threadSleepArgs};
|
||||
static void threadSleepCallFunc(const ioccrfArgBuf *args)
|
||||
/* epicsThreadSleep */
|
||||
static const ioccrfArg epicsThreadSleepArg0 = { "seconds",ioccrfArgDouble};
|
||||
static const ioccrfArg * const epicsThreadSleepArgs[1] = {&epicsThreadSleepArg0};
|
||||
static const ioccrfFuncDef epicsThreadSleepFuncDef =
|
||||
{"epicsThreadSleep",1,epicsThreadSleepArgs};
|
||||
static void epicsThreadSleepCallFunc(const ioccrfArgBuf *args)
|
||||
{
|
||||
threadSleep(args[0].dval);
|
||||
epicsThreadSleep(args[0].dval);
|
||||
}
|
||||
|
||||
void epicsShareAPI osiRegister(void)
|
||||
{
|
||||
ioccrfRegister(&threadShowAllFuncDef,threadShowAllCallFunc);
|
||||
ioccrfRegister(&threadSleepFuncDef,threadSleepCallFunc);
|
||||
ioccrfRegister(&epicsThreadShowAllFuncDef,epicsThreadShowAllCallFunc);
|
||||
ioccrfRegister(&epicsThreadSleepFuncDef,epicsThreadSleepCallFunc);
|
||||
}
|
||||
|
||||
@@ -132,8 +132,9 @@ INC += epicsAssert.h
|
||||
INC += epicsFindSymbol.h
|
||||
INC += osiPoolStatus.h
|
||||
INC += osdPoolStatus.h
|
||||
INC += osiThread.h
|
||||
INC += osdThread.h
|
||||
|
||||
INC += epicsThread.h
|
||||
INC += osiTime.h
|
||||
INC += osdTime.h
|
||||
INC += osiSigPipeIgnore.h
|
||||
@@ -143,6 +144,9 @@ INC += osiProcess.h
|
||||
INC += osiUnistd.h
|
||||
INC += osiWireFormat.h
|
||||
|
||||
SRCS += epicsThread.cpp
|
||||
SRCS += osiTime.cpp
|
||||
|
||||
SRCS += osdSock.c
|
||||
SRCS += osiSock.c
|
||||
SRCS += osdAssert.c
|
||||
@@ -150,12 +154,10 @@ SRCS += osdFindSymbol.c
|
||||
SRCS += osdInterrupt.c
|
||||
SRCS += osdPoolStatus.c
|
||||
|
||||
SRCS += osdThread.c
|
||||
SRCS += osdMutex.c
|
||||
SRCS += osdEvent.c
|
||||
SRCS += osdThread.c
|
||||
SRCS += osiThread.cpp
|
||||
SRCS += osdTime.cpp
|
||||
SRCS += osiTime.cpp
|
||||
SRCS += osdSigPipeIgnore.c
|
||||
SRCS += osdProcess.c
|
||||
SRCS += osdNetIntf.c
|
||||
|
||||
@@ -24,7 +24,7 @@ of this distribution.
|
||||
#define epicsExportSharedSymbols
|
||||
#define ERRLOG_INIT
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "osiInterrupt.h"
|
||||
@@ -301,7 +301,7 @@ static void errlogInitPvt(void *arg)
|
||||
{
|
||||
int bufsize = *(int *)arg;
|
||||
void *pbuffer;
|
||||
threadId tid;
|
||||
epicsThreadId tid;
|
||||
|
||||
pvtData.errlogInitFailed = TRUE;
|
||||
if(bufsize<BUFFER_SIZE) bufsize = BUFFER_SIZE;
|
||||
@@ -315,17 +315,17 @@ static void errlogInitPvt(void *arg)
|
||||
/*Allow an extra MAX_MESSAGE_SIZE for extra margain of safety*/
|
||||
pbuffer = pvtCalloc(pvtData.buffersize+MAX_MESSAGE_SIZE,sizeof(char));
|
||||
pvtData.pbuffer = pbuffer;
|
||||
tid = threadCreate("errlog",threadPriorityLow,
|
||||
threadGetStackSize(threadStackSmall),
|
||||
(THREADFUNC)errlogTask,0);
|
||||
tid = epicsThreadCreate("errlog",epicsThreadPriorityLow,
|
||||
epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||
(EPICSTHREADFUNC)errlogTask,0);
|
||||
if(tid) pvtData.errlogInitFailed = FALSE;
|
||||
}
|
||||
|
||||
epicsShareFunc int epicsShareAPI errlogInit(int bufsize)
|
||||
{
|
||||
static threadOnceId errlogOnceFlag=OSITHREAD_ONCE_INIT;
|
||||
static epicsThreadOnceId errlogOnceFlag=EPICS_THREAD_ONCE_INIT;
|
||||
|
||||
threadOnce(&errlogOnceFlag,errlogInitPvt,(void *)&bufsize);
|
||||
epicsThreadOnce(&errlogOnceFlag,errlogInitPvt,(void *)&bufsize);
|
||||
if(pvtData.errlogInitFailed) {
|
||||
fprintf(stderr,"errlogInit failed\n");
|
||||
exit(1);
|
||||
@@ -464,7 +464,7 @@ LOCAL void msgbufFreeSend()
|
||||
pnextSend = (msgNode *)ellFirst(&pvtData.msgQueue);
|
||||
if(!pnextSend) {
|
||||
printf("errlog: msgbufFreeSend logic error\n");
|
||||
threadSuspendSelf();
|
||||
epicsThreadSuspendSelf();
|
||||
}
|
||||
ellDelete(&pvtData.msgQueue,&pnextSend->node);
|
||||
epicsMutexUnlock(pvtData.msgQueueLock);
|
||||
@@ -477,7 +477,7 @@ LOCAL void *pvtCalloc(size_t count,size_t size)
|
||||
pmem = calloc(count,size);
|
||||
if(!pmem) {
|
||||
printf("calloc failed in errlog\n");
|
||||
threadSuspendSelf();
|
||||
epicsThreadSuspendSelf();
|
||||
}
|
||||
return(pmem);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
#define epicsExportSharedSymbols
|
||||
#include "epicsAssert.h"
|
||||
#include "osiTimer.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "tsMinMax.h"
|
||||
#include "fdManager.h"
|
||||
#include "locationException.h"
|
||||
@@ -183,7 +183,7 @@ epicsShareFunc void fdManager::process (double delay)
|
||||
* windows sockets and UNIX sockets implementation
|
||||
* of select()
|
||||
*/
|
||||
if (minDelay>0.0) threadSleep(minDelay);
|
||||
if (minDelay>0.0) epicsThreadSleep(minDelay);
|
||||
status = 0;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#include "ellLib.h"
|
||||
#include "bucketLib.h"
|
||||
#include "osiSock.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "shareLib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include "dbDefs.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "osiSock.h"
|
||||
#include "epicsAssert.h"
|
||||
#include "errlog.h"
|
||||
@@ -81,7 +81,7 @@ typedef struct {
|
||||
LOCAL epicsMutexId logClientGlobalMutex;
|
||||
LOCAL epicsEventId logClientGlobalSignal;
|
||||
LOCAL ELLLIST logClientList;
|
||||
LOCAL threadId logClientThreadId;
|
||||
LOCAL epicsThreadId logClientThreadId;
|
||||
LOCAL logClient *pLogClientDefaultClient;
|
||||
|
||||
LOCAL const double LOG_RESTART_DELAY = 5.0; /* sec */
|
||||
@@ -416,7 +416,7 @@ LOCAL void logClientConnect (logClient *pClient)
|
||||
pClient->file = fdopen (pClient->sock, "a");
|
||||
if (!pClient->file) {
|
||||
logClientReset (pClient);
|
||||
threadSleep (10.0);
|
||||
epicsThreadSleep (10.0);
|
||||
}
|
||||
|
||||
pClient->connectReset = 0u;
|
||||
@@ -513,7 +513,7 @@ LOCAL void logClientGlobalInit ()
|
||||
return;
|
||||
}
|
||||
|
||||
logClientThreadId = threadCreate ("logRestart", threadPriorityLow,
|
||||
logClientThreadId = epicsThreadCreate ("logRestart", epicsThreadPriorityLow,
|
||||
logRestartStackSize, logRestart, 0);
|
||||
if (logClientThreadId==NULL) {
|
||||
epicsMutexDestroy (logClientGlobalMutex);
|
||||
@@ -590,7 +590,7 @@ epicsShareFunc logClientId epicsShareAPI logClientInit ()
|
||||
|
||||
epicsEventSignal (logClientGlobalSignal);
|
||||
|
||||
threadSleep (50e-3);
|
||||
epicsThreadSleep (50e-3);
|
||||
|
||||
connectTries++;
|
||||
if (connectTries>=maxConnectTries) {
|
||||
|
||||
@@ -17,7 +17,7 @@ of this distribution.
|
||||
#define epicsExportSharedSymbols
|
||||
#include "errlog.h"
|
||||
#include "cantProceed.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
|
||||
epicsShareFunc void * epicsShareAPI callocMustSucceed(size_t count, size_t size, const char *errorMessage)
|
||||
{
|
||||
@@ -45,6 +45,6 @@ epicsShareFunc void epicsShareAPI cantProceed(const char *errorMessage)
|
||||
{
|
||||
if(errorMessage) errlogPrintf("fatal error: %s\n",errorMessage);
|
||||
else errlogPrintf("fatal error\n");
|
||||
threadSleep(1.0);
|
||||
threadSuspendSelf();
|
||||
epicsThreadSleep(1.0);
|
||||
epicsThreadSuspendSelf();
|
||||
}
|
||||
|
||||
@@ -15,16 +15,16 @@
|
||||
*/
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "ipAddrToAsciiAsynchronous.h"
|
||||
|
||||
epicsMutex ipAddrToAsciiEngine::mutex;
|
||||
|
||||
ipAddrToAsciiEngine::ipAddrToAsciiEngine ( const char *pName ) :
|
||||
osiThread ( pName, 0x1000, threadPriorityLow ), nextId ( 0u ),
|
||||
exitFlag ( false )
|
||||
thread(*(new epicsThread(*this,pName,0x1000,epicsThreadPriorityLow))),
|
||||
nextId ( 0u ), exitFlag ( false )
|
||||
{
|
||||
this->start (); // start the thread
|
||||
this->thread.start (); // start the thread
|
||||
}
|
||||
|
||||
ipAddrToAsciiEngine::~ipAddrToAsciiEngine ()
|
||||
@@ -44,9 +44,10 @@ ipAddrToAsciiEngine::~ipAddrToAsciiEngine ()
|
||||
pItem->ioCompletionNotify ( this->nameTmp );
|
||||
}
|
||||
ipAddrToAsciiEngine::mutex.unlock ();
|
||||
delete &thread;
|
||||
}
|
||||
|
||||
void ipAddrToAsciiEngine::entryPoint ()
|
||||
void ipAddrToAsciiEngine::run ()
|
||||
{
|
||||
osiSockAddr addr;
|
||||
unsigned tmpId;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#ifndef ipAddrToAsciiAsynchronous_h
|
||||
#define ipAddrToAsciiAsynchronous_h
|
||||
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "tsDLList.h"
|
||||
@@ -27,12 +28,14 @@ class ipAddrToAsciiAsynchronous;
|
||||
|
||||
// - this class executes the synchronous DNS query
|
||||
// - it creates one thread
|
||||
class ipAddrToAsciiEngine : public osiThread {
|
||||
class ipAddrToAsciiEngine : public epicsThreadRunable {
|
||||
public:
|
||||
epicsShareFunc ipAddrToAsciiEngine ( const char *pName );
|
||||
epicsShareFunc ~ipAddrToAsciiEngine ();
|
||||
virtual void run();
|
||||
epicsShareFunc void show ( unsigned level ) const;
|
||||
private:
|
||||
epicsThread &thread;
|
||||
tsDLList < ipAddrToAsciiAsynchronous > labor;
|
||||
epicsEvent event;
|
||||
epicsEvent threadExit;
|
||||
@@ -40,7 +43,6 @@ private:
|
||||
unsigned nextId;
|
||||
bool exitFlag;
|
||||
static epicsMutex mutex;
|
||||
void entryPoint ();
|
||||
friend class ipAddrToAsciiAsynchronous;
|
||||
};
|
||||
|
||||
|
||||
58
src/libCom/osi/epicsThread.cpp
Normal file
58
src/libCom/osi/epicsThread.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Author: Jeff Hill
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
extern "C" {
|
||||
static void epicsThreadCallEntryPoint ( void *pPvt ); // for gnu warning
|
||||
}
|
||||
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "epicsThread.h"
|
||||
|
||||
void epicsThreadRunable::stop() {};
|
||||
|
||||
static void epicsThreadCallEntryPoint ( void *pPvt )
|
||||
{
|
||||
epicsThread *pThread = static_cast <epicsThread *> ( pPvt );
|
||||
pThread->begin.wait ();
|
||||
if ( ! pThread->cancel ) {
|
||||
pThread->runable.run ();
|
||||
}
|
||||
pThread->id = 0;
|
||||
pThread->exit.signal ();
|
||||
}
|
||||
|
||||
epicsThread::epicsThread (epicsThreadRunable &r, const char *name, unsigned stackSize, unsigned priority ) :
|
||||
runable(r), cancel (false)
|
||||
{
|
||||
this->id = epicsThreadCreate ( name, priority, stackSize,
|
||||
epicsThreadCallEntryPoint, static_cast <void *> (this) );
|
||||
}
|
||||
|
||||
epicsThread::~epicsThread ()
|
||||
{
|
||||
if ( this->id ) {
|
||||
this->cancel = true;
|
||||
this->begin.signal ();
|
||||
while ( ! this->exit.wait ( 5.0 ) ) {
|
||||
printf ("epicsThread::~epicsThread ():"
|
||||
" Warning, thread object destroyed before thread exit \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void epicsThread::start ()
|
||||
{
|
||||
this->begin.signal ();
|
||||
}
|
||||
|
||||
bool epicsThread::isCurrentThread () const
|
||||
{
|
||||
return ( epicsThreadGetIdSelf () == this->id );
|
||||
}
|
||||
260
src/libCom/osi/epicsThread.h
Normal file
260
src/libCom/osi/epicsThread.h
Normal file
@@ -0,0 +1,260 @@
|
||||
#ifndef epicsThreadh
|
||||
#define epicsThreadh
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "shareLib.h"
|
||||
|
||||
typedef void (*EPICSTHREADFUNC)(void *parm);
|
||||
|
||||
static const unsigned epicsThreadPriorityMax = 99;
|
||||
static const unsigned epicsThreadPriorityMin = 0;
|
||||
|
||||
/* some generic values */
|
||||
static const unsigned epicsThreadPriorityLow = 10;
|
||||
static const unsigned epicsThreadPriorityMedium = 50;
|
||||
static const unsigned epicsThreadPriorityHigh = 90;
|
||||
|
||||
/* some iocCore specific values */
|
||||
static const unsigned epicsThreadPriorityChannelAccessServer = 30;
|
||||
static const unsigned epicsThreadPriorityScanLow = 60;
|
||||
static const unsigned epicsThreadPriorityScanHigh = 70;
|
||||
|
||||
/* stack sizes for each stackSizeClass are implementation and CPU dependent */
|
||||
typedef enum {
|
||||
epicsThreadStackSmall, epicsThreadStackMedium, epicsThreadStackBig
|
||||
} epicsThreadStackSizeClass;
|
||||
|
||||
typedef enum {
|
||||
epicsThreadBooleanStatusFail, epicsThreadBooleanStatusSuccess
|
||||
} epicsThreadBooleanStatus;
|
||||
|
||||
epicsShareFunc unsigned int epicsShareAPI epicsThreadGetStackSize(
|
||||
epicsThreadStackSizeClass size);
|
||||
|
||||
typedef int epicsThreadOnceId;
|
||||
#define EPICS_THREAD_ONCE_INIT 0
|
||||
|
||||
/* void epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg); */
|
||||
/* epicsThreadOnce is implemented as a macro */
|
||||
/* epicsThreadOnceOsd should not be called by user code */
|
||||
epicsShareFunc void epicsShareAPI epicsThreadOnceOsd(
|
||||
epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg);
|
||||
|
||||
#define epicsThreadOnce(id,func,arg) \
|
||||
if(*(id)<=0) epicsThreadOnceOsd((id),(func),(arg))
|
||||
|
||||
epicsShareFunc void epicsShareAPI epicsThreadInit(void);
|
||||
epicsShareFunc void epicsShareAPI epicsThreadExitMain(void);
|
||||
|
||||
/* (epicsThreadId)0 is guaranteed to be an invalid thread id */
|
||||
typedef void *epicsThreadId;
|
||||
|
||||
epicsShareFunc epicsThreadId epicsShareAPI epicsThreadCreate(const char *name,
|
||||
unsigned int priority, unsigned int stackSize,
|
||||
EPICSTHREADFUNC funptr,void *parm);
|
||||
epicsShareFunc void epicsShareAPI epicsThreadSuspendSelf(void);
|
||||
epicsShareFunc void epicsShareAPI epicsThreadResume(epicsThreadId id);
|
||||
epicsShareFunc unsigned int epicsShareAPI epicsThreadGetPriority(
|
||||
epicsThreadId id);
|
||||
epicsShareFunc unsigned int epicsShareAPI epicsThreadGetPrioritySelf();
|
||||
epicsShareFunc void epicsShareAPI epicsThreadSetPriority(
|
||||
epicsThreadId id,unsigned int priority);
|
||||
epicsShareFunc epicsThreadBooleanStatus epicsShareAPI
|
||||
epicsThreadHighestPriorityLevelBelow (
|
||||
unsigned int priority, unsigned *pPriorityJustBelow);
|
||||
epicsShareFunc epicsThreadBooleanStatus epicsShareAPI
|
||||
epicsThreadLowestPriorityLevelAbove (
|
||||
unsigned int priority, unsigned *pPriorityJustAbove);
|
||||
epicsShareFunc int epicsShareAPI epicsThreadIsEqual(
|
||||
epicsThreadId id1, epicsThreadId id2);
|
||||
epicsShareFunc int epicsShareAPI epicsThreadIsSuspended(epicsThreadId id);
|
||||
epicsShareFunc void epicsShareAPI epicsThreadSleep(double seconds);
|
||||
epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetIdSelf(void);
|
||||
epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetId(const char *name);
|
||||
|
||||
epicsShareFunc const char * epicsShareAPI epicsThreadGetNameSelf(void);
|
||||
|
||||
/* For epicsThreadGetName name is guaranteed to be null terminated */
|
||||
/* size is size of buffer to hold name (including terminator) */
|
||||
/* Failure results in an empty string stored in name */
|
||||
epicsShareFunc void epicsShareAPI epicsThreadGetName(
|
||||
epicsThreadId id, char *name, size_t size);
|
||||
|
||||
epicsShareFunc void epicsShareAPI epicsThreadShowAll(unsigned int level);
|
||||
epicsShareFunc void epicsShareAPI epicsThreadShow(
|
||||
epicsThreadId id,unsigned int level);
|
||||
|
||||
typedef void * epicsThreadPrivateId;
|
||||
epicsShareFunc epicsThreadPrivateId epicsShareAPI epicsThreadPrivateCreate(void);
|
||||
epicsShareFunc void epicsShareAPI epicsThreadPrivateDelete(epicsThreadPrivateId id);
|
||||
epicsShareFunc void epicsShareAPI epicsThreadPrivateSet(epicsThreadPrivateId,void *);
|
||||
epicsShareFunc void * epicsShareAPI epicsThreadPrivateGet(epicsThreadPrivateId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "locationException.h"
|
||||
#include "epicsEvent.h"
|
||||
|
||||
|
||||
class epicsThreadRunable {
|
||||
public:
|
||||
virtual void run() = 0;
|
||||
virtual void stop();
|
||||
};
|
||||
|
||||
class epicsShareClass epicsThread {
|
||||
public:
|
||||
epicsThread (epicsThreadRunable &,const char *name, unsigned int stackSize,
|
||||
unsigned int priority=epicsThreadPriorityLow);
|
||||
virtual ~epicsThread ();
|
||||
void start();
|
||||
void resume ();
|
||||
void getName (char *name, size_t size) const;
|
||||
unsigned int getPriority () const;
|
||||
void setPriority (unsigned int);
|
||||
bool priorityIsEqual (const epicsThread &otherThread) const;
|
||||
bool isSuspended () const;
|
||||
bool isCurrentThread () const;
|
||||
bool operator == (const epicsThread &rhs) const;
|
||||
/* these operate on the current thread */
|
||||
static void suspendSelf ();
|
||||
static void sleep (double seconds);
|
||||
static epicsThread & getSelf ();
|
||||
static const char * getNameSelf ();
|
||||
private:
|
||||
epicsThreadRunable &runable;
|
||||
epicsThreadId id;
|
||||
epicsEvent exit;
|
||||
epicsEvent begin;
|
||||
bool cancel;
|
||||
|
||||
epicsThread ( const epicsThread & );
|
||||
epicsThread & operator = ( const epicsThread & );
|
||||
|
||||
friend void epicsThreadCallEntryPoint (void *pPvt);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class epicsThreadPrivate {
|
||||
public:
|
||||
epicsThreadPrivate ();
|
||||
~epicsThreadPrivate ();
|
||||
T *get () const;
|
||||
void set (T *);
|
||||
class unableToCreateThreadPrivate {}; // exception
|
||||
private:
|
||||
epicsThreadPrivateId id;
|
||||
};
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "osdThread.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "epicsAssert.h"
|
||||
|
||||
inline void epicsThread::resume ()
|
||||
{
|
||||
epicsThreadResume (this->id);
|
||||
}
|
||||
|
||||
inline void epicsThread::getName (char *name, size_t size) const
|
||||
{
|
||||
epicsThreadGetName (this->id, name, size);
|
||||
}
|
||||
|
||||
inline unsigned int epicsThread::getPriority () const
|
||||
{
|
||||
return epicsThreadGetPriority (this->id);
|
||||
}
|
||||
|
||||
inline void epicsThread::setPriority (unsigned int priority)
|
||||
{
|
||||
epicsThreadSetPriority (this->id, priority);
|
||||
}
|
||||
|
||||
inline bool epicsThread::priorityIsEqual (const epicsThread &otherThread) const
|
||||
{
|
||||
if ( epicsThreadIsEqual (this->id, otherThread.id) ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool epicsThread::isSuspended () const
|
||||
{
|
||||
if ( epicsThreadIsSuspended (this->id) ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool epicsThread::operator == (const epicsThread &rhs) const
|
||||
{
|
||||
return (this->id == rhs.id);
|
||||
}
|
||||
|
||||
inline void epicsThread::suspendSelf ()
|
||||
{
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
inline void epicsThread::sleep (double seconds)
|
||||
{
|
||||
epicsThreadSleep (seconds);
|
||||
}
|
||||
|
||||
inline epicsThread & epicsThread::getSelf ()
|
||||
{
|
||||
return * static_cast<epicsThread *> ( epicsThreadGetIdSelf () );
|
||||
}
|
||||
|
||||
inline const char *epicsThread::getNameSelf ()
|
||||
{
|
||||
return epicsThreadGetNameSelf ();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline epicsThreadPrivate<T>::epicsThreadPrivate ()
|
||||
{
|
||||
this->id = epicsThreadPrivateCreate ();
|
||||
if (this->id == 0) {
|
||||
throwWithLocation ( unableToCreateThreadPrivate () );
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline epicsThreadPrivate<T>::~epicsThreadPrivate ()
|
||||
{
|
||||
epicsThreadPrivateDelete ( this->id );
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T *epicsThreadPrivate<T>::get () const
|
||||
{
|
||||
return static_cast<T *> ( epicsThreadPrivateGet (this->id) );
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void epicsThreadPrivate<T>::set (T *pIn)
|
||||
{
|
||||
epicsThreadPrivateSet ( this->id, static_cast<void *> (pIn) );
|
||||
}
|
||||
|
||||
#endif /* ifdef __cplusplus */
|
||||
|
||||
#endif /* epicsThreadh */
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <rtems/error.h>
|
||||
|
||||
#include "epicsEvent.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "errlog.h"
|
||||
|
||||
/*
|
||||
@@ -182,7 +182,7 @@ epicsEventShow(epicsEventId id, unsigned int level)
|
||||
else {
|
||||
if (_CORE_mutex_Is_locked(&semaphore.Core_control.mutex)) {
|
||||
char name[20];
|
||||
threadGetName ((threadId)semaphore.Core_control.mutex.holder_id, name, sizeof name);
|
||||
epicsThreadGetName ((epicsThreadId)semaphore.Core_control.mutex.holder_id, name, sizeof name);
|
||||
printf ("Held by:%8.8x (%s) Nest count:%d",
|
||||
semaphore.Core_control.mutex.holder_id,
|
||||
name,
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <rtems/error.h>
|
||||
#include "errlog.h"
|
||||
#include "osiInterrupt.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
|
||||
#define INTERRUPT_CONTEXT_MESSAGE_QUEUE_COUNT 100
|
||||
|
||||
@@ -69,7 +69,7 @@ InterruptContextMessageDaemon (void *unused)
|
||||
&interruptContextMessageQueue);
|
||||
if (sc != RTEMS_SUCCESSFUL) {
|
||||
errlogPrintf ("Can't create interrupt context message queue: %s\n", rtems_status_text (sc));
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
for (;;) {
|
||||
sc = rtems_message_queue_receive (interruptContextMessageQueue,
|
||||
@@ -79,7 +79,7 @@ InterruptContextMessageDaemon (void *unused)
|
||||
RTEMS_NO_TIMEOUT);
|
||||
if (sc != RTEMS_SUCCESSFUL) {
|
||||
errlogPrintf ("Can't receive message from interrupt context: %s\n", rtems_status_text (sc));
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
if (size == sizeof message)
|
||||
syslog (LOG_ERR, "%s", message);
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "osiThread.h"
|
||||
#include "errlog.h"
|
||||
|
||||
#define RTEMS_FAST_MUTEX
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "errlog.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "osiInterrupt.h"
|
||||
#include "cantProceed.h"
|
||||
|
||||
@@ -37,7 +37,7 @@ struct taskVar {
|
||||
struct taskVar *back;
|
||||
char *name;
|
||||
rtems_id id;
|
||||
THREADFUNC funptr;
|
||||
EPICSTHREADFUNC funptr;
|
||||
void *parm;
|
||||
unsigned int threadVariableCapacity;
|
||||
void **threadVariables;
|
||||
@@ -59,20 +59,20 @@ static epicsMutexId onceMutex;
|
||||
* = 199 - osi
|
||||
* osi = 199 - RTEMS
|
||||
*/
|
||||
int threadGetOsiPriorityValue(int ossPriority)
|
||||
int epicsThreadGetOsiPriorityValue(int ossPriority)
|
||||
{
|
||||
if (ossPriority < 100) {
|
||||
return threadPriorityMax;
|
||||
return epicsThreadPriorityMax;
|
||||
}
|
||||
else if (ossPriority > 199) {
|
||||
return threadPriorityMin;
|
||||
return epicsThreadPriorityMin;
|
||||
}
|
||||
else {
|
||||
return (199u - (unsigned int)ossPriority);
|
||||
}
|
||||
}
|
||||
|
||||
int threadGetOssPriorityValue(unsigned int osiPriority)
|
||||
int epicsThreadGetOssPriorityValue(unsigned int osiPriority)
|
||||
{
|
||||
if (osiPriority > 99) {
|
||||
return 100;
|
||||
@@ -83,9 +83,9 @@ int threadGetOssPriorityValue(unsigned int osiPriority)
|
||||
}
|
||||
|
||||
/*
|
||||
* threadLowestPriorityLevelAbove ()
|
||||
* epicsThreadLowestPriorityLevelAbove ()
|
||||
*/
|
||||
epicsShareFunc threadBoolStatus epicsShareAPI threadLowestPriorityLevelAbove
|
||||
epicsShareFunc epicsThreadBooleanStatus epicsShareAPI epicsThreadLowestPriorityLevelAbove
|
||||
(unsigned int priority, unsigned *pPriorityJustAbove)
|
||||
{
|
||||
unsigned newPriority = priority + 1;
|
||||
@@ -93,37 +93,37 @@ epicsShareFunc threadBoolStatus epicsShareAPI threadLowestPriorityLevelAbove
|
||||
newPriority = priority + 1;
|
||||
if (newPriority <= 99) {
|
||||
*pPriorityJustAbove = newPriority;
|
||||
return tbsSuccess;
|
||||
return threadBoolStatusSuccess;
|
||||
}
|
||||
return tbsFail;
|
||||
return threadBoolStatusFail;
|
||||
}
|
||||
|
||||
/*
|
||||
* threadHighestPriorityLevelBelow ()
|
||||
* epicsThreadHighestPriorityLevelBelow ()
|
||||
*/
|
||||
epicsShareFunc threadBoolStatus epicsShareAPI threadHighestPriorityLevelBelow
|
||||
epicsShareFunc epicsThreadBooleanStatus epicsShareAPI epicsThreadHighestPriorityLevelBelow
|
||||
(unsigned int priority, unsigned *pPriorityJustBelow)
|
||||
{
|
||||
unsigned newPriority = priority - 1;
|
||||
|
||||
if (newPriority <= 99) {
|
||||
*pPriorityJustBelow = newPriority;
|
||||
return tbsSuccess;
|
||||
return threadBoolStatusSuccess;
|
||||
}
|
||||
return tbsFail;
|
||||
return threadBoolStatusFail;
|
||||
}
|
||||
|
||||
#define ARCH_STACK_FACTOR 2
|
||||
|
||||
unsigned int
|
||||
threadGetStackSize (threadStackSizeClass size)
|
||||
epicsThreadGetStackSize (epicsThreadStackSizeClass size)
|
||||
{
|
||||
switch(size) {
|
||||
case threadStackSmall: return( 4000*ARCH_STACK_FACTOR);
|
||||
case threadStackMedium: return( 6000*ARCH_STACK_FACTOR);
|
||||
case threadStackBig: return(11000*ARCH_STACK_FACTOR);
|
||||
case epicsThreadStackSmall: return( 4000*ARCH_STACK_FACTOR);
|
||||
case epicsThreadStackMedium: return( 6000*ARCH_STACK_FACTOR);
|
||||
case epicsThreadStackBig: return(11000*ARCH_STACK_FACTOR);
|
||||
default:
|
||||
errlogPrintf("threadGetStackSize illegal argument");
|
||||
errlogPrintf("epicsThreadGetStackSize illegal argument");
|
||||
}
|
||||
return(11000*ARCH_STACK_FACTOR);
|
||||
}
|
||||
@@ -170,7 +170,7 @@ threadWrapper (rtems_task_argument arg)
|
||||
/*
|
||||
* The task wrapper takes care of cleanup
|
||||
*/
|
||||
void threadExitMain (void)
|
||||
void epicsThreadExitMain (void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ void threadExitMain (void)
|
||||
static void
|
||||
badInit (const char *msg)
|
||||
{
|
||||
const char fmt[] = "%s called before threadInit finished!";
|
||||
const char fmt[] = "%s called before epicsThreadInit finished!";
|
||||
|
||||
syslog (LOG_CRIT, fmt, msg);
|
||||
fprintf (stderr, fmt, msg);
|
||||
@@ -189,13 +189,13 @@ badInit (const char *msg)
|
||||
}
|
||||
|
||||
static void
|
||||
setThreadInfo (rtems_id tid, const char *name, THREADFUNC funptr,void *parm)
|
||||
setThreadInfo (rtems_id tid, const char *name, EPICSTHREADFUNC funptr,void *parm)
|
||||
{
|
||||
struct taskVar *v;
|
||||
rtems_unsigned32 note;
|
||||
|
||||
v = mallocMustSucceed (sizeof *v, "threadCreate_vars");
|
||||
v->name = mallocMustSucceed (strlen (name) + 1, "threadCreate_name");
|
||||
v = mallocMustSucceed (sizeof *v, "epicsThreadCreate_vars");
|
||||
v->name = mallocMustSucceed (strlen (name) + 1, "epicsThreadCreate_name");
|
||||
strcpy (v->name, name);
|
||||
v->id = tid;
|
||||
v->funptr = funptr;
|
||||
@@ -218,11 +218,11 @@ setThreadInfo (rtems_id tid, const char *name, THREADFUNC funptr,void *parm)
|
||||
/*
|
||||
* OS-dependent initialization
|
||||
* No need to worry about making this thread-safe since
|
||||
* it must be called before threadCreate creates
|
||||
* it must be called before epicsThreadCreate creates
|
||||
* any new threads.
|
||||
*/
|
||||
void
|
||||
threadInit (void)
|
||||
epicsThreadInit (void)
|
||||
{
|
||||
if (!initialized) {
|
||||
rtems_id tid;
|
||||
@@ -230,14 +230,14 @@ threadInit (void)
|
||||
extern void clockInit (void);
|
||||
|
||||
clockInit ();
|
||||
rtems_task_set_priority (RTEMS_SELF, threadGetOssPriorityValue(99), &old);
|
||||
rtems_task_set_priority (RTEMS_SELF, epicsThreadGetOssPriorityValue(99), &old);
|
||||
onceMutex = epicsMutexMustCreate();
|
||||
taskVarMutex = epicsMutexMustCreate ();
|
||||
rtems_task_ident (RTEMS_SELF, 0, &tid);
|
||||
setThreadInfo (tid, "_main_", NULL, NULL);
|
||||
initialized = 1;
|
||||
threadCreate ("ImsgDaemon", 99,
|
||||
threadGetStackSize (threadStackSmall),
|
||||
epicsThreadCreate ("ImsgDaemon", 99,
|
||||
epicsThreadGetStackSize (epicsThreadStackSmall),
|
||||
InterruptContextMessageDaemon, NULL);
|
||||
}
|
||||
}
|
||||
@@ -245,68 +245,68 @@ threadInit (void)
|
||||
/*
|
||||
* Create and start a new thread
|
||||
*/
|
||||
threadId
|
||||
threadCreate (const char *name,
|
||||
epicsThreadId
|
||||
epicsThreadCreate (const char *name,
|
||||
unsigned int priority, unsigned int stackSize,
|
||||
THREADFUNC funptr,void *parm)
|
||||
EPICSTHREADFUNC funptr,void *parm)
|
||||
{
|
||||
rtems_id tid;
|
||||
rtems_status_code sc;
|
||||
char c[4];
|
||||
|
||||
if (!initialized) threadInit();
|
||||
if (!initialized) epicsThreadInit();
|
||||
if (stackSize < RTEMS_MINIMUM_STACK_SIZE) {
|
||||
errlogPrintf ("threadCreate %s illegal stackSize %d\n",name,stackSize);
|
||||
errlogPrintf ("epicsThreadCreate %s illegal stackSize %d\n",name,stackSize);
|
||||
return 0;
|
||||
}
|
||||
strncpy (c, name, sizeof c);
|
||||
sc = rtems_task_create (rtems_build_name (c[0], c[1], c[2], c[3]),
|
||||
threadGetOssPriorityValue (priority),
|
||||
epicsThreadGetOssPriorityValue (priority),
|
||||
stackSize,
|
||||
RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
|
||||
RTEMS_FLOATING_POINT|RTEMS_LOCAL,
|
||||
&tid);
|
||||
if (sc != RTEMS_SUCCESSFUL) {
|
||||
errlogPrintf ("threadCreate create failure for %s: %s\n",name, rtems_status_text (sc));
|
||||
errlogPrintf ("epicsThreadCreate create failure for %s: %s\n",name, rtems_status_text (sc));
|
||||
return 0;
|
||||
}
|
||||
setThreadInfo (tid, name, funptr,parm);
|
||||
return (threadId)tid;
|
||||
return (epicsThreadId)tid;
|
||||
}
|
||||
|
||||
threadId
|
||||
epicsThreadId
|
||||
threadMustCreate (const char *name,
|
||||
unsigned int priority, unsigned int stackSize,
|
||||
THREADFUNC funptr,void *parm)
|
||||
EPICSTHREADFUNC funptr,void *parm)
|
||||
{
|
||||
threadId tid;
|
||||
epicsThreadId tid;
|
||||
|
||||
if ((tid = threadCreate (name, priority, stackSize, funptr, parm)) == NULL)
|
||||
if ((tid = epicsThreadCreate (name, priority, stackSize, funptr, parm)) == NULL)
|
||||
cantProceed (0);
|
||||
return tid;
|
||||
}
|
||||
|
||||
void
|
||||
threadSuspendSelf (void)
|
||||
epicsThreadSuspendSelf (void)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
|
||||
sc = rtems_task_suspend (RTEMS_SELF);
|
||||
if(sc != RTEMS_SUCCESSFUL)
|
||||
errlogPrintf("threadSuspendSelf failed: %s\n", rtems_status_text (sc));
|
||||
errlogPrintf("epicsThreadSuspendSelf failed: %s\n", rtems_status_text (sc));
|
||||
}
|
||||
|
||||
void threadResume(threadId id)
|
||||
void epicsThreadResume(epicsThreadId id)
|
||||
{
|
||||
rtems_id tid = (rtems_id)id;
|
||||
rtems_status_code sc;
|
||||
|
||||
sc = rtems_task_resume (tid);
|
||||
if(sc != RTEMS_SUCCESSFUL)
|
||||
errlogPrintf("threadResume failed: %s\n", rtems_status_text (sc));
|
||||
errlogPrintf("epicsThreadResume failed: %s\n", rtems_status_text (sc));
|
||||
}
|
||||
|
||||
unsigned int threadGetPriority(threadId id)
|
||||
unsigned int epicsThreadGetPriority(epicsThreadId id)
|
||||
{
|
||||
rtems_id tid = (rtems_id)id;
|
||||
rtems_status_code sc;
|
||||
@@ -314,35 +314,35 @@ unsigned int threadGetPriority(threadId id)
|
||||
|
||||
sc = rtems_task_set_priority (tid, RTEMS_CURRENT_PRIORITY, &pri);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
errlogPrintf("threadGetPriority failed: %s\n", rtems_status_text (sc));
|
||||
return threadGetOsiPriorityValue (pri);
|
||||
errlogPrintf("epicsThreadGetPriority failed: %s\n", rtems_status_text (sc));
|
||||
return epicsThreadGetOsiPriorityValue (pri);
|
||||
}
|
||||
|
||||
unsigned int threadGetPrioritySelf(void)
|
||||
unsigned int epicsThreadGetPrioritySelf(void)
|
||||
{
|
||||
return threadGetPriority((threadId)RTEMS_SELF);
|
||||
return epicsThreadGetPriority((epicsThreadId)RTEMS_SELF);
|
||||
}
|
||||
|
||||
void
|
||||
threadSetPriority (threadId id,unsigned int osip)
|
||||
epicsThreadSetPriority (epicsThreadId id,unsigned int osip)
|
||||
{
|
||||
rtems_id tid = (rtems_id)id;
|
||||
rtems_status_code sc;
|
||||
rtems_task_priority pri = threadGetOssPriorityValue(osip);
|
||||
rtems_task_priority pri = epicsThreadGetOssPriorityValue(osip);
|
||||
|
||||
sc = rtems_task_set_priority (tid, pri, &pri);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
errlogPrintf("threadSetPriority failed\n", rtems_status_text (sc));
|
||||
errlogPrintf("epicsThreadSetPriority failed\n", rtems_status_text (sc));
|
||||
}
|
||||
|
||||
int
|
||||
threadIsEqual (threadId id1, threadId id2)
|
||||
epicsThreadIsEqual (epicsThreadId id1, epicsThreadId id2)
|
||||
{
|
||||
return (id1 == id2);
|
||||
}
|
||||
|
||||
int
|
||||
threadIsSuspended (threadId id)
|
||||
epicsThreadIsSuspended (epicsThreadId id)
|
||||
{
|
||||
rtems_id tid = (rtems_id)id;
|
||||
rtems_status_code sc;
|
||||
@@ -355,13 +355,13 @@ threadIsSuspended (threadId id)
|
||||
return 1;
|
||||
|
||||
default:
|
||||
errlogPrintf("threadIsSuspended: %s\n", rtems_status_text (sc));
|
||||
errlogPrintf("epicsThreadIsSuspended: %s\n", rtems_status_text (sc));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
threadSleep (double seconds)
|
||||
epicsThreadSleep (double seconds)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
rtems_interval delay;
|
||||
@@ -370,19 +370,19 @@ threadSleep (double seconds)
|
||||
delay = seconds * rtemsTicksPerSecond_double;
|
||||
sc = rtems_task_wake_after (delay);
|
||||
if(sc != RTEMS_SUCCESSFUL)
|
||||
errlogPrintf("threadSleep: %s\n", rtems_status_text (sc));
|
||||
errlogPrintf("epicsThreadSleep: %s\n", rtems_status_text (sc));
|
||||
}
|
||||
|
||||
threadId
|
||||
threadGetIdSelf (void)
|
||||
epicsThreadId
|
||||
epicsThreadGetIdSelf (void)
|
||||
{
|
||||
rtems_id tid;
|
||||
|
||||
rtems_task_ident (RTEMS_SELF, 0, &tid);
|
||||
return (threadId)tid;
|
||||
return (epicsThreadId)tid;
|
||||
}
|
||||
|
||||
const char *threadGetNameSelf(void)
|
||||
const char *epicsThreadGetNameSelf(void)
|
||||
{
|
||||
rtems_unsigned32 note;
|
||||
struct taskVar *v;
|
||||
@@ -392,7 +392,7 @@ const char *threadGetNameSelf(void)
|
||||
return v->name;
|
||||
}
|
||||
|
||||
void threadGetName (threadId id, char *name, size_t size)
|
||||
void epicsThreadGetName (epicsThreadId id, char *name, size_t size)
|
||||
{
|
||||
rtems_id tid = (rtems_id)id;
|
||||
rtems_status_code sc;
|
||||
@@ -412,7 +412,7 @@ void threadGetName (threadId id, char *name, size_t size)
|
||||
taskVarUnlock ();
|
||||
}
|
||||
|
||||
threadId threadGetId (const char *name)
|
||||
epicsThreadId epicsThreadGetId (const char *name)
|
||||
{
|
||||
struct taskVar *v;
|
||||
rtems_id tid = 0;
|
||||
@@ -429,15 +429,15 @@ threadId threadGetId (const char *name)
|
||||
}
|
||||
}
|
||||
taskVarUnlock ();
|
||||
return (threadId)tid;
|
||||
return (epicsThreadId)tid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure func() is run only once.
|
||||
*/
|
||||
void threadOnceOsd(threadOnceId *id, void(*func)(void *), void *arg)
|
||||
void epicsThreadOnceOsd(epicsThreadOnceId *id, void(*func)(void *), void *arg)
|
||||
{
|
||||
if (!initialized) threadInit();
|
||||
if (!initialized) epicsThreadInit();
|
||||
epicsMutexMustLock(onceMutex);
|
||||
if (*id == 0) {
|
||||
*id = -1;
|
||||
@@ -451,24 +451,24 @@ void threadOnceOsd(threadOnceId *id, void(*func)(void *), void *arg)
|
||||
* Thread private storage implementation based on the vxWorks
|
||||
* implementation by Andrew Johnson APS/ASD.
|
||||
*/
|
||||
threadPrivateId threadPrivateCreate ()
|
||||
epicsThreadPrivateId epicsThreadPrivateCreate ()
|
||||
{
|
||||
unsigned int taskVarIndex;
|
||||
static volatile unsigned int threadVariableCount = 0;
|
||||
|
||||
if (!initialized) threadInit ();
|
||||
if (!initialized) epicsThreadInit ();
|
||||
taskVarLock ();
|
||||
taskVarIndex = ++threadVariableCount;
|
||||
taskVarUnlock ();
|
||||
return (threadPrivateId)taskVarIndex;
|
||||
return (epicsThreadPrivateId)taskVarIndex;
|
||||
}
|
||||
|
||||
void threadPrivateDelete (threadPrivateId id)
|
||||
void epicsThreadPrivateDelete (epicsThreadPrivateId id)
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
void threadPrivateSet (threadPrivateId id, void *pvt)
|
||||
void epicsThreadPrivateSet (epicsThreadPrivateId id, void *pvt)
|
||||
{
|
||||
unsigned int varIndex = (unsigned int)id;
|
||||
rtems_unsigned32 note;
|
||||
@@ -480,7 +480,7 @@ void threadPrivateSet (threadPrivateId id, void *pvt)
|
||||
if (varIndex >= v->threadVariableCapacity) {
|
||||
v->threadVariables = realloc (v->threadVariables, (varIndex + 1) * sizeof (void *));
|
||||
if (v->threadVariables == NULL)
|
||||
cantProceed("threadPrivateSet realloc failed\n");
|
||||
cantProceed("epicsThreadPrivateSet realloc failed\n");
|
||||
for (i = v->threadVariableCapacity ; i < varIndex ; i++)
|
||||
v->threadVariables[i] = NULL;
|
||||
v->threadVariableCapacity = varIndex + 1;
|
||||
@@ -488,7 +488,7 @@ void threadPrivateSet (threadPrivateId id, void *pvt)
|
||||
v->threadVariables[varIndex] = pvt;
|
||||
}
|
||||
|
||||
void * threadPrivateGet (threadPrivateId id)
|
||||
void * epicsThreadPrivateGet (epicsThreadPrivateId id)
|
||||
{
|
||||
unsigned int varIndex = (unsigned int)id;
|
||||
rtems_unsigned32 note;
|
||||
@@ -556,7 +556,7 @@ showInternalTaskInfo (rtems_id tid)
|
||||
_Thread_Enable_dispatch();
|
||||
/*
|
||||
* Show both real and current priorities if they differ.
|
||||
* Note that the threadGetOsiPriorityValue routine is not used here.
|
||||
* Note that the epicsThreadGetOsiPriorityValue routine is not used here.
|
||||
* If a thread has a priority outside the normal EPICS range then
|
||||
* that priority should be displayed, not the value truncated to
|
||||
* the EPICS range.
|
||||
@@ -575,32 +575,32 @@ showInternalTaskInfo (rtems_id tid)
|
||||
}
|
||||
|
||||
static void
|
||||
threadShowHeader (void)
|
||||
epicsThreadShowHeader (void)
|
||||
{
|
||||
printf (" NAME ID PRIORITY STATE WAIT \n");
|
||||
printf ("+-------------+--------+--------+--------+--------+\n");
|
||||
}
|
||||
|
||||
static void
|
||||
threadShowInfo (struct taskVar *v, unsigned int level)
|
||||
epicsThreadShowInfo (struct taskVar *v, unsigned int level)
|
||||
{
|
||||
printf ("%14.14s %8.8x", v->name, v->id);
|
||||
showInternalTaskInfo (v->id);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
void threadShow (threadId id, unsigned int level)
|
||||
void epicsThreadShow (epicsThreadId id, unsigned int level)
|
||||
{
|
||||
struct taskVar *v;
|
||||
|
||||
if (!id) {
|
||||
threadShowHeader ();
|
||||
epicsThreadShowHeader ();
|
||||
return;
|
||||
}
|
||||
taskVarLock ();
|
||||
for (v = taskVarHead ; v != NULL ; v = v->forw) {
|
||||
if ((rtems_id)id == v->id) {
|
||||
threadShowInfo (v, level);
|
||||
epicsThreadShowInfo (v, level);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -608,11 +608,11 @@ void threadShow (threadId id, unsigned int level)
|
||||
printf ("*** Thread %x does not exist.\n", (unsigned int)id);
|
||||
}
|
||||
|
||||
void threadShowAll (unsigned int level)
|
||||
void epicsThreadShowAll (unsigned int level)
|
||||
{
|
||||
struct taskVar *v;
|
||||
|
||||
threadShowHeader ();
|
||||
epicsThreadShowHeader ();
|
||||
taskVarLock ();
|
||||
/*
|
||||
* Show tasks in the order of creation (backwards through list)
|
||||
@@ -620,7 +620,7 @@ void threadShowAll (unsigned int level)
|
||||
for (v = taskVarHead ; v != NULL && v->forw != NULL ; v = v->forw)
|
||||
continue;
|
||||
while (v) {
|
||||
threadShowInfo (v, level);
|
||||
epicsThreadShowInfo (v, level);
|
||||
v = v->back;
|
||||
}
|
||||
taskVarUnlock ();
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <rtems/rtems_bsdnet.h>
|
||||
#include <rtems/tftp.h>
|
||||
|
||||
#include <osiThread.h>
|
||||
#include <epicsThread.h>
|
||||
#include <logClient.h>
|
||||
#include <ioccrf.h>
|
||||
#include <dbStaticLib.h>
|
||||
@@ -311,7 +311,7 @@ Init (rtems_task_argument ignored)
|
||||
/*
|
||||
* Do EPICS initialization
|
||||
*/
|
||||
threadInit ();
|
||||
epicsThreadInit ();
|
||||
|
||||
/*
|
||||
* Run the EPICS startup script
|
||||
@@ -323,7 +323,7 @@ Init (rtems_task_argument ignored)
|
||||
/*
|
||||
* Everything's running!
|
||||
*/
|
||||
threadSleep (2.0);
|
||||
epicsThreadSleep (2.0);
|
||||
ioccrf (NULL);
|
||||
LogFatal ("Console command interpreter terminated");
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "shareLib.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "cantProceed.h"
|
||||
#include "errlog.h"
|
||||
#include "epicsAssert.h"
|
||||
|
||||
typedef struct win32ThreadParam {
|
||||
HANDLE handle;
|
||||
THREADFUNC funptr;
|
||||
EPICSTHREADFUNC funptr;
|
||||
void *parm;
|
||||
char *pName;
|
||||
DWORD id;
|
||||
@@ -79,16 +79,16 @@ static void threadCleanupWIN32 (void)
|
||||
}
|
||||
|
||||
/*
|
||||
* threadExitMain ()
|
||||
* epicsThreadExitMain ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadExitMain (void)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadExitMain (void)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* threadInit ()
|
||||
* epicsThreadInit ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadInit (void)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadInit (void)
|
||||
{
|
||||
HANDLE win32ThreadGlobalMutexTmp;
|
||||
DWORD status;
|
||||
@@ -155,26 +155,26 @@ static unsigned osdPriorityMagFromPriorityOSI ( unsigned osiPriority )
|
||||
{
|
||||
unsigned magnitude;
|
||||
|
||||
// optimizer will remove this one if threadPriorityMin is zero
|
||||
// optimizer will remove this one if epicsThreadPriorityMin is zero
|
||||
// and osiPriority is unsigned
|
||||
if (osiPriority<threadPriorityMin) {
|
||||
osiPriority = threadPriorityMin;
|
||||
if (osiPriority<epicsThreadPriorityMin) {
|
||||
osiPriority = epicsThreadPriorityMin;
|
||||
}
|
||||
|
||||
if (osiPriority>threadPriorityMax) {
|
||||
osiPriority = threadPriorityMax;
|
||||
if (osiPriority>epicsThreadPriorityMax) {
|
||||
osiPriority = epicsThreadPriorityMax;
|
||||
}
|
||||
|
||||
magnitude = osiPriority * osdPriorityStateCount;
|
||||
magnitude /= (threadPriorityMax - threadPriorityMin)+1;
|
||||
magnitude /= (epicsThreadPriorityMax - epicsThreadPriorityMin)+1;
|
||||
|
||||
return magnitude;
|
||||
}
|
||||
|
||||
/*
|
||||
* threadGetOsdPriorityValue ()
|
||||
* epicsThreadGetOsdPriorityValue ()
|
||||
*/
|
||||
static int threadGetOsdPriorityValue ( unsigned osiPriority )
|
||||
static int epicsThreadGetOsdPriorityValue ( unsigned osiPriority )
|
||||
{
|
||||
unsigned magnitude = osdPriorityMagFromPriorityOSI ( osiPriority );
|
||||
return osdPriorityList[magnitude];
|
||||
@@ -205,76 +205,76 @@ static unsigned osiPriorityMagFromMagnitueOSD ( unsigned magnitude )
|
||||
{
|
||||
unsigned osiPriority;
|
||||
|
||||
osiPriority = magnitude * (threadPriorityMax - threadPriorityMin);
|
||||
osiPriority = magnitude * (epicsThreadPriorityMax - epicsThreadPriorityMin);
|
||||
osiPriority /= osdPriorityStateCount - 1u;
|
||||
osiPriority += threadPriorityMin;
|
||||
osiPriority += epicsThreadPriorityMin;
|
||||
|
||||
return osiPriority;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* threadGetOsiPriorityValue ()
|
||||
* epicsThreadGetOsiPriorityValue ()
|
||||
*/
|
||||
static unsigned threadGetOsiPriorityValue ( int osdPriority )
|
||||
static unsigned epicsThreadGetOsiPriorityValue ( int osdPriority )
|
||||
{
|
||||
unsigned magnitude = osdPriorityMagFromPriorityOSD ( osdPriority );
|
||||
return osiPriorityMagFromMagnitueOSD (magnitude);
|
||||
}
|
||||
|
||||
/*
|
||||
* threadLowestPriorityLevelAbove ()
|
||||
* epicsThreadLowestPriorityLevelAbove ()
|
||||
*/
|
||||
epicsShareFunc threadBoolStatus epicsShareAPI threadLowestPriorityLevelAbove
|
||||
epicsShareFunc epicsThreadBooleanStatus epicsShareAPI epicsThreadLowestPriorityLevelAbove
|
||||
(unsigned int priority, unsigned *pPriorityJustAbove)
|
||||
{
|
||||
unsigned magnitude = osdPriorityMagFromPriorityOSI ( priority );
|
||||
threadBoolStatus status;
|
||||
epicsThreadBooleanStatus status;
|
||||
|
||||
if ( magnitude < (osdPriorityStateCount-1) ) {
|
||||
*pPriorityJustAbove = osiPriorityMagFromMagnitueOSD ( magnitude + 1u );
|
||||
status = tbsSuccess;
|
||||
status = threadBoolStatusSuccess;
|
||||
}
|
||||
else {
|
||||
status = tbsFail;
|
||||
status = threadBoolStatusFail;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* threadHighestPriorityLevelBelow ()
|
||||
* epicsThreadHighestPriorityLevelBelow ()
|
||||
*/
|
||||
epicsShareFunc threadBoolStatus epicsShareAPI threadHighestPriorityLevelBelow
|
||||
epicsShareFunc epicsThreadBooleanStatus epicsShareAPI epicsThreadHighestPriorityLevelBelow
|
||||
(unsigned int priority, unsigned *pPriorityJustBelow)
|
||||
{
|
||||
unsigned magnitude = osdPriorityMagFromPriorityOSI ( priority );
|
||||
threadBoolStatus status;
|
||||
epicsThreadBooleanStatus status;
|
||||
|
||||
if ( magnitude > 1u ) {
|
||||
*pPriorityJustBelow = osiPriorityMagFromMagnitueOSD ( magnitude - 1u );
|
||||
status = tbsSuccess;
|
||||
status = threadBoolStatusSuccess;
|
||||
}
|
||||
else {
|
||||
status = tbsFail;
|
||||
status = threadBoolStatusFail;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* threadGetStackSize ()
|
||||
* epicsThreadGetStackSize ()
|
||||
*/
|
||||
epicsShareFunc unsigned int epicsShareAPI threadGetStackSize (threadStackSizeClass stackSizeClass)
|
||||
epicsShareFunc unsigned int epicsShareAPI epicsThreadGetStackSize (epicsThreadStackSizeClass stackSizeClass)
|
||||
{
|
||||
static const unsigned stackSizeTable[threadStackBig+1] = {4000, 6000, 11000};
|
||||
static const unsigned stackSizeTable[epicsThreadStackBig+1] = {4000, 6000, 11000};
|
||||
|
||||
if (stackSizeClass<threadStackSmall) {
|
||||
errlogPrintf("threadGetStackSize illegal argument (too small)");
|
||||
return stackSizeTable[threadStackBig];
|
||||
if (stackSizeClass<epicsThreadStackSmall) {
|
||||
errlogPrintf("epicsThreadGetStackSize illegal argument (too small)");
|
||||
return stackSizeTable[epicsThreadStackBig];
|
||||
}
|
||||
|
||||
if (stackSizeClass>threadStackBig) {
|
||||
errlogPrintf("threadGetStackSize illegal argument (too large)");
|
||||
return stackSizeTable[threadStackBig];
|
||||
if (stackSizeClass>epicsThreadStackBig) {
|
||||
errlogPrintf("epicsThreadGetStackSize illegal argument (too large)");
|
||||
return stackSizeTable[epicsThreadStackBig];
|
||||
}
|
||||
|
||||
return stackSizeTable[stackSizeClass];
|
||||
@@ -303,10 +303,10 @@ static unsigned WINAPI epicsWin32ThreadEntry (LPVOID lpParameter)
|
||||
}
|
||||
|
||||
/*
|
||||
* threadCreate ()
|
||||
* epicsThreadCreate ()
|
||||
*/
|
||||
epicsShareFunc threadId epicsShareAPI threadCreate (const char *pName,
|
||||
unsigned int priority, unsigned int stackSize, THREADFUNC pFunc,void *pParm)
|
||||
epicsShareFunc epicsThreadId epicsShareAPI epicsThreadCreate (const char *pName,
|
||||
unsigned int priority, unsigned int stackSize, EPICSTHREADFUNC pFunc,void *pParm)
|
||||
{
|
||||
win32ThreadParam *pParmWIN32;
|
||||
int osdPriority;
|
||||
@@ -314,7 +314,7 @@ epicsShareFunc threadId epicsShareAPI threadCreate (const char *pName,
|
||||
BOOL bstat;
|
||||
|
||||
if ( ! win32ThreadInitOK ) {
|
||||
threadInit ();
|
||||
epicsThreadInit ();
|
||||
if ( ! win32ThreadInitOK ) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -338,7 +338,7 @@ epicsShareFunc threadId epicsShareAPI threadCreate (const char *pName,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
osdPriority = threadGetOsdPriorityValue (priority);
|
||||
osdPriority = epicsThreadGetOsdPriorityValue (priority);
|
||||
bstat = SetThreadPriority ( pParmWIN32->handle, osdPriority );
|
||||
if (!bstat) {
|
||||
CloseHandle ( pParmWIN32->handle );
|
||||
@@ -353,13 +353,13 @@ epicsShareFunc threadId epicsShareAPI threadCreate (const char *pName,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ( threadId ) pParmWIN32;
|
||||
return ( epicsThreadId ) pParmWIN32;
|
||||
}
|
||||
|
||||
/*
|
||||
* threadSuspendSelf ()
|
||||
* epicsThreadSuspendSelf ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadSuspendSelf ()
|
||||
epicsShareFunc void epicsShareAPI epicsThreadSuspendSelf ()
|
||||
{
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) TlsGetValue (tlsIndexWIN32);
|
||||
BOOL success;
|
||||
@@ -382,9 +382,9 @@ epicsShareFunc void epicsShareAPI threadSuspendSelf ()
|
||||
}
|
||||
|
||||
/*
|
||||
* threadResume ()
|
||||
* epicsThreadResume ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadResume (threadId id)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadResume (epicsThreadId id)
|
||||
{
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) id;
|
||||
BOOL success;
|
||||
@@ -403,9 +403,9 @@ epicsShareFunc void epicsShareAPI threadResume (threadId id)
|
||||
}
|
||||
|
||||
/*
|
||||
* threadGetPriority ()
|
||||
* epicsThreadGetPriority ()
|
||||
*/
|
||||
epicsShareFunc unsigned epicsShareAPI threadGetPriority (threadId id)
|
||||
epicsShareFunc unsigned epicsShareAPI epicsThreadGetPriority (epicsThreadId id)
|
||||
{
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) id;
|
||||
int win32ThreadPriority;
|
||||
@@ -413,52 +413,52 @@ epicsShareFunc unsigned epicsShareAPI threadGetPriority (threadId id)
|
||||
win32ThreadPriority = GetThreadPriority (pParm->handle);
|
||||
assert (win32ThreadPriority!=THREAD_PRIORITY_ERROR_RETURN);
|
||||
|
||||
return threadGetOsiPriorityValue (win32ThreadPriority);
|
||||
return epicsThreadGetOsiPriorityValue (win32ThreadPriority);
|
||||
}
|
||||
|
||||
/*
|
||||
* threadGetPriority ()
|
||||
* epicsThreadGetPriority ()
|
||||
*/
|
||||
epicsShareFunc unsigned epicsShareAPI threadGetPrioritySelf ()
|
||||
epicsShareFunc unsigned epicsShareAPI epicsThreadGetPrioritySelf ()
|
||||
{
|
||||
int win32ThreadPriority;
|
||||
|
||||
win32ThreadPriority = GetThreadPriority ( GetCurrentThread () );
|
||||
assert (win32ThreadPriority!=THREAD_PRIORITY_ERROR_RETURN);
|
||||
|
||||
return threadGetOsiPriorityValue (win32ThreadPriority);
|
||||
return epicsThreadGetOsiPriorityValue (win32ThreadPriority);
|
||||
}
|
||||
|
||||
/*
|
||||
* threadSetPriority ()
|
||||
* epicsThreadSetPriority ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadSetPriority (threadId id, unsigned priority)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadSetPriority (epicsThreadId id, unsigned priority)
|
||||
{
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) id;
|
||||
BOOL stat;
|
||||
|
||||
stat = SetThreadPriority (pParm->handle, threadGetOsdPriorityValue (priority) );
|
||||
stat = SetThreadPriority (pParm->handle, epicsThreadGetOsdPriorityValue (priority) );
|
||||
assert (stat);
|
||||
}
|
||||
|
||||
/*
|
||||
* threadIsEqual ()
|
||||
* epicsThreadIsEqual ()
|
||||
*/
|
||||
epicsShareFunc int epicsShareAPI threadIsEqual (threadId id1, threadId id2)
|
||||
epicsShareFunc int epicsShareAPI epicsThreadIsEqual (epicsThreadId id1, epicsThreadId id2)
|
||||
{
|
||||
return ( id1 == id2 );
|
||||
}
|
||||
|
||||
/*
|
||||
* threadIsSuspended ()
|
||||
* epicsThreadIsSuspended ()
|
||||
*
|
||||
* This implementation is deficient if the thread is not suspended by
|
||||
* threadSuspendSelf () or resumed by threadResume(). This would happen
|
||||
* if a WIN32 call was used instead of threadSuspendSelf(), or if WIN32
|
||||
* epicsThreadSuspendSelf () or resumed by epicsThreadResume(). This would happen
|
||||
* if a WIN32 call was used instead of epicsThreadSuspendSelf(), or if WIN32
|
||||
* suspended the thread when it receives an unhandled run time exception.
|
||||
*
|
||||
*/
|
||||
epicsShareFunc int epicsShareAPI threadIsSuspended (threadId id)
|
||||
epicsShareFunc int epicsShareAPI epicsThreadIsSuspended (epicsThreadId id)
|
||||
{
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) id;
|
||||
DWORD exitCode;
|
||||
@@ -479,9 +479,9 @@ epicsShareFunc int epicsShareAPI threadIsSuspended (threadId id)
|
||||
}
|
||||
|
||||
/*
|
||||
* threadSleep ()
|
||||
* epicsThreadSleep ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadSleep (double seconds)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadSleep (double seconds)
|
||||
{
|
||||
static const double mSecPerSec = 1000;
|
||||
DWORD milliSecDelay = (DWORD) (seconds * mSecPerSec);
|
||||
@@ -489,24 +489,24 @@ epicsShareFunc void epicsShareAPI threadSleep (double seconds)
|
||||
}
|
||||
|
||||
/*
|
||||
* threadGetIdSelf ()
|
||||
* epicsThreadGetIdSelf ()
|
||||
*/
|
||||
epicsShareFunc threadId epicsShareAPI threadGetIdSelf (void)
|
||||
epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetIdSelf (void)
|
||||
{
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) TlsGetValue (tlsIndexWIN32);
|
||||
return (threadId) pParm;
|
||||
return (epicsThreadId) pParm;
|
||||
}
|
||||
|
||||
epicsShareFunc threadId epicsShareAPI threadGetId (const char *name)
|
||||
epicsShareFunc epicsThreadId epicsShareAPI epicsThreadGetId (const char *name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* threadGetNameSelf ()
|
||||
* epicsThreadGetNameSelf ()
|
||||
*/
|
||||
epicsShareFunc const char * epicsShareAPI threadGetNameSelf (void)
|
||||
epicsShareFunc const char * epicsShareAPI epicsThreadGetNameSelf (void)
|
||||
{
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) TlsGetValue (tlsIndexWIN32);
|
||||
|
||||
@@ -519,9 +519,9 @@ epicsShareFunc const char * epicsShareAPI threadGetNameSelf (void)
|
||||
}
|
||||
|
||||
/*
|
||||
* threadGetName ()
|
||||
* epicsThreadGetName ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadGetName (threadId id, char *pName, size_t size)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadGetName (epicsThreadId id, char *pName, size_t size)
|
||||
{
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) id;
|
||||
|
||||
@@ -533,17 +533,17 @@ epicsShareFunc void epicsShareAPI threadGetName (threadId id, char *pName, size_
|
||||
}
|
||||
|
||||
/*
|
||||
* threadShowAll ()
|
||||
* epicsThreadShowAll ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadShowAll (unsigned level)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadShowAll (unsigned level)
|
||||
{
|
||||
printf ("sorry, threadShowAll() not implemented on WIN32\n");
|
||||
printf ("sorry, epicsThreadShowAll() not implemented on WIN32\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* threadShow ()
|
||||
* epicsThreadShow ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadShow (threadId id, unsigned level)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadShow (epicsThreadId id, unsigned level)
|
||||
{
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) id;
|
||||
|
||||
@@ -553,10 +553,10 @@ epicsShareFunc void epicsShareAPI threadShow (threadId id, unsigned level)
|
||||
}
|
||||
|
||||
/*
|
||||
* threadOnce ()
|
||||
* epicsThreadOnce ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadOnceOsd (
|
||||
threadOnceId *id, void (*func)(void *), void *arg)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadOnceOsd (
|
||||
epicsThreadOnceId *id, void (*func)(void *), void *arg)
|
||||
{
|
||||
|
||||
win32ThreadParam *pParm = (win32ThreadParam *) id;
|
||||
@@ -564,7 +564,7 @@ epicsShareFunc void epicsShareAPI threadOnceOsd (
|
||||
DWORD stat;
|
||||
|
||||
if ( ! win32ThreadInitOK ) {
|
||||
threadInit ();
|
||||
epicsThreadInit ();
|
||||
if ( ! win32ThreadInitOK ) {
|
||||
return;
|
||||
}
|
||||
@@ -583,9 +583,9 @@ epicsShareFunc void epicsShareAPI threadOnceOsd (
|
||||
}
|
||||
|
||||
/*
|
||||
* threadPrivateCreate ()
|
||||
* epicsThreadPrivateCreate ()
|
||||
*/
|
||||
epicsShareFunc threadPrivateId epicsShareAPI threadPrivateCreate ()
|
||||
epicsShareFunc epicsThreadPrivateId epicsShareAPI epicsThreadPrivateCreate ()
|
||||
{
|
||||
osdThreadPrivate *p = (osdThreadPrivate *) malloc (sizeof (*p));
|
||||
if (p) {
|
||||
@@ -595,13 +595,13 @@ epicsShareFunc threadPrivateId epicsShareAPI threadPrivateCreate ()
|
||||
p = 0;
|
||||
}
|
||||
}
|
||||
return (threadPrivateId) p;
|
||||
return (epicsThreadPrivateId) p;
|
||||
}
|
||||
|
||||
/*
|
||||
* threadPrivateDelete ()
|
||||
* epicsThreadPrivateDelete ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadPrivateDelete (threadPrivateId id)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadPrivateDelete (epicsThreadPrivateId id)
|
||||
{
|
||||
osdThreadPrivate *p = (osdThreadPrivate *) id;
|
||||
BOOL stat = TlsFree (p->key);
|
||||
@@ -610,9 +610,9 @@ epicsShareFunc void epicsShareAPI threadPrivateDelete (threadPrivateId id)
|
||||
}
|
||||
|
||||
/*
|
||||
* threadPrivateSet ()
|
||||
* epicsThreadPrivateSet ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI threadPrivateSet (threadPrivateId id, void *pVal)
|
||||
epicsShareFunc void epicsShareAPI epicsThreadPrivateSet (epicsThreadPrivateId id, void *pVal)
|
||||
{
|
||||
struct osdThreadPrivate *pPvt = (struct osdThreadPrivate *) id;
|
||||
BOOL stat = TlsSetValue (pPvt->key, (void *) pVal );
|
||||
@@ -620,9 +620,9 @@ epicsShareFunc void epicsShareAPI threadPrivateSet (threadPrivateId id, void *pV
|
||||
}
|
||||
|
||||
/*
|
||||
* threadPrivateGet ()
|
||||
* epicsThreadPrivateGet ()
|
||||
*/
|
||||
epicsShareFunc void * epicsShareAPI threadPrivateGet (threadPrivateId id)
|
||||
epicsShareFunc void * epicsShareAPI epicsThreadPrivateGet (epicsThreadPrivateId id)
|
||||
{
|
||||
struct osdThreadPrivate *pPvt = (struct osdThreadPrivate *) id;
|
||||
return (void *) TlsGetValue (pPvt->key);
|
||||
@@ -633,12 +633,12 @@ void testPriorityMapping ()
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i=threadPriorityMin; i<threadPriorityMax; i++) {
|
||||
printf ("%u %d\n", i, threadGetOsdPriorityValue (i) );
|
||||
for (i=epicsThreadPriorityMin; i<epicsThreadPriorityMax; i++) {
|
||||
printf ("%u %d\n", i, epicsThreadGetOsdPriorityValue (i) );
|
||||
}
|
||||
|
||||
for (i=0; i<osdPriorityStateCount; i++) {
|
||||
printf ("%d %u\n", osdPriorityList[i], threadGetOsiPriorityValue(osdPriorityList[i]));
|
||||
printf ("%d %u\n", osdPriorityList[i], epicsThreadGetOsiPriorityValue(osdPriorityList[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "epicsPrint.h"
|
||||
#include "epicsVersion.h"
|
||||
#include "epicsAssert.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "cantProceed.h"
|
||||
|
||||
/*
|
||||
@@ -77,7 +77,7 @@ epicsShareFunc void epicsShareAPI
|
||||
|
||||
}
|
||||
errlogPrintf ("This problem occurred in \"%s\"\n", epicsReleaseVersion);
|
||||
errlogPrintf("calling threadSuspendSelf()\n");
|
||||
threadSuspendSelf();
|
||||
errlogPrintf("calling epicsThreadSuspendSelf()\n");
|
||||
epicsThreadSuspendSelf();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "osiSock.h"
|
||||
@@ -53,9 +53,9 @@ static void createInfoMutex (void *unused)
|
||||
}
|
||||
static void lockInfo (void)
|
||||
{
|
||||
static threadOnceId infoMutexOnceFlag = OSITHREAD_ONCE_INIT;
|
||||
static epicsThreadOnceId infoMutexOnceFlag = EPICS_THREAD_ONCE_INIT;
|
||||
|
||||
threadOnce (&infoMutexOnceFlag, createInfoMutex, NULL);
|
||||
epicsThreadOnce (&infoMutexOnceFlag, createInfoMutex, NULL);
|
||||
epicsMutexMustLock (infoMutex);
|
||||
}
|
||||
static void unlockInfo (void)
|
||||
|
||||
@@ -18,7 +18,6 @@ of this distribution.
|
||||
#include <pthread.h>
|
||||
|
||||
#include "epicsEvent.h"
|
||||
#include "osiThread.h"
|
||||
#include "cantProceed.h"
|
||||
#include "tsStamp.h"
|
||||
#include "errlog.h"
|
||||
|
||||
@@ -18,7 +18,6 @@ of this distribution.
|
||||
#include <pthread.h>
|
||||
|
||||
#include "epicsMutex.h"
|
||||
#include "osiThread.h"
|
||||
#include "cantProceed.h"
|
||||
#include "tsStamp.h"
|
||||
#include "errlog.h"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* osiThread.c */
|
||||
/* epicsThread.c */
|
||||
|
||||
/* Author: Marty Kraimer Date: 18JAN2000 */
|
||||
|
||||
@@ -8,7 +8,7 @@ described on the COPYRIGHT_UniversityOfChicago file included as part
|
||||
of this distribution.
|
||||
****************************************************************************/
|
||||
|
||||
/* This is a posix implementation of osiThread */
|
||||
/* This is a posix implementation of epicsThread */
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
@@ -21,7 +21,7 @@ of this distribution.
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ellLib.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "cantProceed.h"
|
||||
@@ -45,7 +45,7 @@ typedef struct threadInfo {
|
||||
pthread_t tid;
|
||||
pthread_attr_t attr;
|
||||
struct sched_param schedParam;
|
||||
THREADFUNC createFunc;
|
||||
EPICSTHREADFUNC createFunc;
|
||||
void *createArg;
|
||||
epicsEventId suspendEvent;
|
||||
int isSuspended;
|
||||
@@ -58,7 +58,7 @@ static epicsMutexId onceLock;
|
||||
static epicsMutexId listLock;
|
||||
static ELLLIST pthreadList;
|
||||
static commonAttr *pcommonAttr = 0;
|
||||
static int threadInitCalled = 0;
|
||||
static int epicsThreadInitCalled = 0;
|
||||
|
||||
#define checkStatus(status,message) \
|
||||
if((status)) {\
|
||||
@@ -71,8 +71,8 @@ if(status) { \
|
||||
cantProceed((method)); \
|
||||
}
|
||||
|
||||
/* The following are for use by once, which is only invoked from threadInit*/
|
||||
/* Until threadInit completes errlogInit will not work */
|
||||
/* The following are for use by once, which is only invoked from epicsThreadInit*/
|
||||
/* Until epicsThreadInit completes errlogInit will not work */
|
||||
/* It must also be used by init_threadInfo otherwise errlogInit could get */
|
||||
/* called recursively */
|
||||
#define checkStatusOnce(status,message) \
|
||||
@@ -83,7 +83,7 @@ if((status)) {\
|
||||
if(status) { \
|
||||
fprintf(stderr,"%s error %s",(message),strerror((status))); \
|
||||
fprintf(stderr," %s\n",method); \
|
||||
fprintf(stderr,"threadInit cant proceed. Program exiting\n"); \
|
||||
fprintf(stderr,"epicsThreadInit cant proceed. Program exiting\n"); \
|
||||
exit(-1);\
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ static int getOssPriorityValue(threadInfo *pthreadInfo)
|
||||
|
||||
static threadInfo * init_threadInfo(const char *name,
|
||||
unsigned int priority, unsigned int stackSize,
|
||||
THREADFUNC funptr,void *parm)
|
||||
EPICSTHREADFUNC funptr,void *parm)
|
||||
{
|
||||
threadInfo *pthreadInfo;
|
||||
int status;
|
||||
@@ -160,7 +160,7 @@ static threadInfo * init_threadInfo(const char *name,
|
||||
status = pthread_attr_setschedparam(
|
||||
&pthreadInfo->attr,&pthreadInfo->schedParam);
|
||||
if(status && errVerbose) {
|
||||
fprintf(stderr,"threadCreate: pthread_attr_setschedparam failed %s",
|
||||
fprintf(stderr,"epicsThreadCreate: pthread_attr_setschedparam failed %s",
|
||||
strerror(status));
|
||||
fprintf(stderr," sched_priority %d\n",
|
||||
pthreadInfo->schedParam.sched_priority);
|
||||
@@ -170,7 +170,7 @@ static threadInfo * init_threadInfo(const char *name,
|
||||
if(errVerbose) checkStatusOnce(status,"pthread_attr_setinheritsched");
|
||||
#endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
|
||||
pthreadInfo->suspendEvent = epicsEventMustCreate(epicsEventEmpty);
|
||||
pthreadInfo->name = mallocMustSucceed(strlen(name)+1,"threadCreate");
|
||||
pthreadInfo->name = mallocMustSucceed(strlen(name)+1,"epicsThreadCreate");
|
||||
strcpy(pthreadInfo->name,name);
|
||||
return(pthreadInfo);
|
||||
}
|
||||
@@ -199,9 +199,9 @@ static void once(void)
|
||||
listLock = epicsMutexMustCreate();
|
||||
ellInit(&pthreadList);
|
||||
pcommonAttr = calloc(1,sizeof(commonAttr));
|
||||
if(!pcommonAttr) checkStatusOnceQuit(errno,"calloc","threadInit");
|
||||
if(!pcommonAttr) checkStatusOnceQuit(errno,"calloc","epicsThreadInit");
|
||||
status = pthread_attr_init(&pcommonAttr->attr);
|
||||
checkStatusOnceQuit(status,"pthread_attr_init","threadInit");
|
||||
checkStatusOnceQuit(status,"pthread_attr_init","epicsThreadInit");
|
||||
status = pthread_attr_setdetachstate(
|
||||
&pcommonAttr->attr, PTHREAD_CREATE_DETACHED);
|
||||
checkStatusOnce(status,"pthread_attr_setdetachstate");
|
||||
@@ -231,9 +231,9 @@ static void once(void)
|
||||
#endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
|
||||
pthreadInfo = init_threadInfo("_main_",0,0,0,0);
|
||||
status = pthread_setspecific(getpthreadInfo,(void *)pthreadInfo);
|
||||
checkStatusOnceQuit(status,"pthread_setspecific","threadInit");
|
||||
checkStatusOnceQuit(status,"pthread_setspecific","epicsThreadInit");
|
||||
status = epicsMutexLock(listLock);
|
||||
checkStatusOnceQuit(status,"epicsMutexLock","threadInit");
|
||||
checkStatusOnceQuit(status,"epicsMutexLock","epicsThreadInit");
|
||||
ellAdd(&pthreadList,&pthreadInfo->node);
|
||||
epicsMutexUnlock(listLock);
|
||||
status = atexit(myAtExit);
|
||||
@@ -267,91 +267,91 @@ static void * start_routine(void *arg)
|
||||
#define ARCH_STACK_FACTOR 2
|
||||
#endif
|
||||
|
||||
unsigned int threadGetStackSize (threadStackSizeClass stackSizeClass)
|
||||
unsigned int epicsThreadGetStackSize (epicsThreadStackSizeClass stackSizeClass)
|
||||
{
|
||||
#if ! defined (_POSIX_THREAD_ATTR_STACKSIZE)
|
||||
return 0;
|
||||
#elif defined (OSITHREAD_USE_DEFAULT_STACK)
|
||||
return 0;
|
||||
#else
|
||||
static const unsigned stackSizeTable[threadStackBig+1] =
|
||||
static const unsigned stackSizeTable[epicsThreadStackBig+1] =
|
||||
{4000*ARCH_STACK_FACTOR, 6000*ARCH_STACK_FACTOR, 11000*ARCH_STACK_FACTOR};
|
||||
if (stackSizeClass<threadStackSmall) {
|
||||
errlogPrintf("threadGetStackSize illegal argument (too small)");
|
||||
return stackSizeTable[threadStackBig];
|
||||
if (stackSizeClass<epicsThreadStackSmall) {
|
||||
errlogPrintf("epicsThreadGetStackSize illegal argument (too small)");
|
||||
return stackSizeTable[epicsThreadStackBig];
|
||||
}
|
||||
|
||||
if (stackSizeClass>threadStackBig) {
|
||||
errlogPrintf("threadGetStackSize illegal argument (too large)");
|
||||
return stackSizeTable[threadStackBig];
|
||||
if (stackSizeClass>epicsThreadStackBig) {
|
||||
errlogPrintf("epicsThreadGetStackSize illegal argument (too large)");
|
||||
return stackSizeTable[epicsThreadStackBig];
|
||||
}
|
||||
|
||||
return stackSizeTable[stackSizeClass];
|
||||
#endif /*_POSIX_THREAD_ATTR_STACKSIZE*/
|
||||
}
|
||||
|
||||
void threadInit(void)
|
||||
void epicsThreadInit(void)
|
||||
{
|
||||
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
||||
int status = pthread_once(&once_control,once);
|
||||
threadInitCalled = 1;
|
||||
checkStatusQuit(status,"pthread_once","threadInit");
|
||||
epicsThreadInitCalled = 1;
|
||||
checkStatusQuit(status,"pthread_once","epicsThreadInit");
|
||||
}
|
||||
|
||||
/* threadOnce is a macro that calls threadOnceOsd */
|
||||
void threadOnceOsd(threadOnceId *id, void (*func)(void *), void *arg)
|
||||
/* epicsThreadOnce is a macro that calls epicsThreadOnceOsd */
|
||||
void epicsThreadOnceOsd(epicsThreadOnceId *id, void (*func)(void *), void *arg)
|
||||
{
|
||||
|
||||
if(!threadInitCalled) threadInit();
|
||||
if(!epicsThreadInitCalled) epicsThreadInit();
|
||||
if(epicsMutexLock(onceLock) != epicsMutexLockOK) {
|
||||
fprintf(stderr,"threadOnceOsd epicsMutexLock failed.\n");
|
||||
fprintf(stderr,"Did you call threadInit? Program exiting\n");
|
||||
fprintf(stderr,"epicsThreadOnceOsd epicsMutexLock failed.\n");
|
||||
fprintf(stderr,"Did you call epicsThreadInit? Program exiting\n");
|
||||
exit(-1);
|
||||
}
|
||||
if (*id == 0) { /* 0 => first call */
|
||||
*id = -1; /* -1 => func() active */
|
||||
func(arg);
|
||||
*id = +1; /* +1 => func() done (see threadOnce() macro defn) */
|
||||
*id = +1; /* +1 => func() done (see epicsThreadOnce() macro defn) */
|
||||
}
|
||||
epicsMutexUnlock(onceLock);
|
||||
}
|
||||
|
||||
threadId threadCreate(const char *name,
|
||||
epicsThreadId epicsThreadCreate(const char *name,
|
||||
unsigned int priority, unsigned int stackSize,
|
||||
THREADFUNC funptr,void *parm)
|
||||
EPICSTHREADFUNC funptr,void *parm)
|
||||
{
|
||||
threadInfo *pthreadInfo;
|
||||
int status;
|
||||
|
||||
if(!threadInitCalled) threadInit();
|
||||
if(!epicsThreadInitCalled) epicsThreadInit();
|
||||
assert(pcommonAttr);
|
||||
pthreadInfo = init_threadInfo(name,priority,stackSize,funptr,parm);
|
||||
status = pthread_create(&pthreadInfo->tid,&pthreadInfo->attr,
|
||||
start_routine,pthreadInfo);
|
||||
checkStatusQuit(status,"pthread_create","threadCreate");
|
||||
return((threadId)pthreadInfo);
|
||||
checkStatusQuit(status,"pthread_create","epicsThreadCreate");
|
||||
return((epicsThreadId)pthreadInfo);
|
||||
}
|
||||
|
||||
void threadSuspendSelf(void)
|
||||
void epicsThreadSuspendSelf(void)
|
||||
{
|
||||
threadInfo *pthreadInfo = (threadInfo *)pthread_getspecific(getpthreadInfo);
|
||||
pthreadInfo->isSuspended = 1;
|
||||
epicsEventMustWait(pthreadInfo->suspendEvent);
|
||||
}
|
||||
|
||||
void threadResume(threadId id)
|
||||
void epicsThreadResume(epicsThreadId id)
|
||||
{
|
||||
threadInfo *pthreadInfo = (threadInfo *)id;
|
||||
pthreadInfo->isSuspended = 0;
|
||||
epicsEventSignal(pthreadInfo->suspendEvent);
|
||||
}
|
||||
|
||||
void threadExitMain(void)
|
||||
void epicsThreadExitMain(void)
|
||||
{
|
||||
threadInfo *pthreadInfo = (threadInfo *)pthread_getspecific(getpthreadInfo);
|
||||
if(pthreadInfo->createFunc) {
|
||||
errlogPrintf("called from non-main thread\n");
|
||||
cantProceed("threadExitMain");
|
||||
cantProceed("epicsThreadExitMain");
|
||||
}
|
||||
else {
|
||||
free_threadInfo(pthreadInfo);
|
||||
@@ -359,18 +359,18 @@ void threadExitMain(void)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int threadGetPriority(threadId id)
|
||||
unsigned int epicsThreadGetPriority(epicsThreadId id)
|
||||
{
|
||||
threadInfo *pthreadInfo = (threadInfo *)id;
|
||||
return(pthreadInfo->osiPriority);
|
||||
}
|
||||
|
||||
unsigned int threadGetPrioritySelf(void)
|
||||
unsigned int epicsThreadGetPrioritySelf(void)
|
||||
{
|
||||
return(threadGetPriority(threadGetIdSelf()));
|
||||
return(epicsThreadGetPriority(epicsThreadGetIdSelf()));
|
||||
}
|
||||
|
||||
void threadSetPriority(threadId id,unsigned int priority)
|
||||
void epicsThreadSetPriority(epicsThreadId id,unsigned int priority)
|
||||
{
|
||||
threadInfo *pthreadInfo = (threadInfo *)id;
|
||||
#if defined (_POSIX_THREAD_PRIORITY_SCHEDULING)
|
||||
@@ -389,54 +389,54 @@ void threadSetPriority(threadId id,unsigned int priority)
|
||||
#endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
|
||||
}
|
||||
|
||||
threadBoolStatus threadHighestPriorityLevelBelow(
|
||||
epicsThreadBooleanStatus epicsThreadHighestPriorityLevelBelow(
|
||||
unsigned int priority, unsigned *pPriorityJustBelow)
|
||||
{
|
||||
unsigned newPriority = priority - 1;
|
||||
#if defined (_POSIX_THREAD_PRIORITY_SCHEDULING)
|
||||
int diff;
|
||||
diff = (double)pcommonAttr->maxPriority - (double)pcommonAttr->minPriority;
|
||||
diff = pcommonAttr->maxPriority - pcommonAttr->minPriority;
|
||||
if(diff<0) diff = -diff;
|
||||
if(diff>1 && diff <100) newPriority -= 100/(diff+1);
|
||||
#endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
|
||||
if (newPriority <= 99) {
|
||||
*pPriorityJustBelow = newPriority;
|
||||
return tbsSuccess;
|
||||
return epicsThreadBooleanStatusSuccess;
|
||||
}
|
||||
return tbsFail;
|
||||
return epicsThreadBooleanStatusFail;
|
||||
}
|
||||
|
||||
threadBoolStatus threadLowestPriorityLevelAbove(
|
||||
epicsThreadBooleanStatus epicsThreadLowestPriorityLevelAbove(
|
||||
unsigned int priority, unsigned *pPriorityJustAbove)
|
||||
{
|
||||
unsigned newPriority = priority + 1;
|
||||
|
||||
#if defined (_POSIX_THREAD_PRIORITY_SCHEDULING)
|
||||
int diff;
|
||||
diff = (double)pcommonAttr->maxPriority - (double)pcommonAttr->minPriority;
|
||||
diff = pcommonAttr->maxPriority - pcommonAttr->minPriority;
|
||||
if(diff<0) diff = -diff;
|
||||
if(diff>1 && diff <100) newPriority += 100/(diff+1);
|
||||
#endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
|
||||
if (newPriority <= 99) {
|
||||
*pPriorityJustAbove = newPriority;
|
||||
return tbsSuccess;
|
||||
return epicsThreadBooleanStatusSuccess;
|
||||
}
|
||||
return tbsFail;
|
||||
return epicsThreadBooleanStatusFail;
|
||||
}
|
||||
|
||||
int threadIsEqual(threadId id1, threadId id2)
|
||||
int epicsThreadIsEqual(epicsThreadId id1, epicsThreadId id2)
|
||||
{
|
||||
threadInfo *p1 = (threadInfo *)id1;
|
||||
threadInfo *p2 = (threadInfo *)id2;
|
||||
return(pthread_equal(p1->tid,p2->tid));
|
||||
}
|
||||
|
||||
int threadIsSuspended(threadId id) {
|
||||
int epicsThreadIsSuspended(epicsThreadId id) {
|
||||
threadInfo *pthreadInfo = (threadInfo *)id;
|
||||
return(pthreadInfo->isSuspended ? 1 : 0);
|
||||
}
|
||||
|
||||
void threadSleep(double seconds)
|
||||
void epicsThreadSleep(double seconds)
|
||||
{
|
||||
struct timespec delayTime;
|
||||
struct timespec remainingTime;
|
||||
@@ -448,12 +448,12 @@ void threadSleep(double seconds)
|
||||
nanosleep(&delayTime,&remainingTime);
|
||||
}
|
||||
|
||||
threadId threadGetIdSelf(void) {
|
||||
epicsThreadId epicsThreadGetIdSelf(void) {
|
||||
threadInfo *pthreadInfo = (threadInfo *)pthread_getspecific(getpthreadInfo);
|
||||
return((threadId)pthreadInfo);
|
||||
return((epicsThreadId)pthreadInfo);
|
||||
}
|
||||
|
||||
threadId threadGetId(const char *name) {
|
||||
epicsThreadId epicsThreadGetId(const char *name) {
|
||||
threadInfo *pthreadInfo;
|
||||
epicsMutexMustLock(listLock);
|
||||
pthreadInfo=(threadInfo *)ellFirst(&pthreadList);
|
||||
@@ -462,36 +462,36 @@ threadId threadGetId(const char *name) {
|
||||
pthreadInfo=(threadInfo *)ellNext(&pthreadInfo->node);
|
||||
}
|
||||
epicsMutexUnlock(listLock);
|
||||
return((threadId)pthreadInfo);
|
||||
return((epicsThreadId)pthreadInfo);
|
||||
}
|
||||
|
||||
const char *threadGetNameSelf()
|
||||
const char *epicsThreadGetNameSelf()
|
||||
{
|
||||
threadInfo *pthreadInfo = (threadInfo *)pthread_getspecific(getpthreadInfo);
|
||||
return(pthreadInfo->name);
|
||||
}
|
||||
|
||||
void threadGetName(threadId id, char *name, size_t size)
|
||||
void epicsThreadGetName(epicsThreadId id, char *name, size_t size)
|
||||
{
|
||||
threadInfo *pthreadInfo = (threadInfo *)id;
|
||||
strncpy(name, pthreadInfo->name, size-1);
|
||||
name[size-1] = '\0';
|
||||
}
|
||||
|
||||
void threadShowAll(unsigned int level)
|
||||
void epicsThreadShowAll(unsigned int level)
|
||||
{
|
||||
threadInfo *pthreadInfo;
|
||||
threadShow(0,level);
|
||||
epicsThreadShow(0,level);
|
||||
epicsMutexMustLock(listLock);
|
||||
pthreadInfo=(threadInfo *)ellFirst(&pthreadList);
|
||||
while(pthreadInfo) {
|
||||
threadShow((threadId)pthreadInfo,level);
|
||||
epicsThreadShow((epicsThreadId)pthreadInfo,level);
|
||||
pthreadInfo=(threadInfo *)ellNext(&pthreadInfo->node);
|
||||
}
|
||||
epicsMutexUnlock(listLock);
|
||||
}
|
||||
|
||||
void threadShow(threadId id,unsigned int level)
|
||||
void epicsThreadShow(epicsThreadId id,unsigned int level)
|
||||
{
|
||||
threadInfo *pthreadInfo = (threadInfo *)id;
|
||||
|
||||
@@ -506,7 +506,7 @@ void threadShow(threadId id,unsigned int level)
|
||||
|
||||
status = pthread_getschedparam(pthreadInfo->tid,&policy,¶m);
|
||||
priority = (status ? 0 : param.sched_priority);
|
||||
printf("%16.16s %p %d %8d %8.8s\n", pthreadInfo->name,(threadId)
|
||||
printf("%16.16s %p %d %8d %8.8s\n", pthreadInfo->name,(epicsThreadId)
|
||||
pthreadInfo,pthreadInfo->osiPriority,priority,pthreadInfo->
|
||||
isSuspended?"SUSPEND":"OK");
|
||||
if(level>0)
|
||||
@@ -515,44 +515,44 @@ void threadShow(threadId id,unsigned int level)
|
||||
}
|
||||
|
||||
|
||||
threadPrivateId threadPrivateCreate(void)
|
||||
epicsThreadPrivateId epicsThreadPrivateCreate(void)
|
||||
{
|
||||
pthread_key_t *key;
|
||||
int status;
|
||||
|
||||
key = callocMustSucceed(1,sizeof(pthread_key_t),"threadPrivateCreate");
|
||||
key = callocMustSucceed(1,sizeof(pthread_key_t),"epicsThreadPrivateCreate");
|
||||
status = pthread_key_create(key,0);
|
||||
checkStatusQuit(status,"pthread_key_create","threadPrivateCreate");
|
||||
return((threadPrivateId)key);
|
||||
checkStatusQuit(status,"pthread_key_create","epicsThreadPrivateCreate");
|
||||
return((epicsThreadPrivateId)key);
|
||||
}
|
||||
|
||||
void threadPrivateDelete(threadPrivateId id)
|
||||
void epicsThreadPrivateDelete(epicsThreadPrivateId id)
|
||||
{
|
||||
pthread_key_t *key = (pthread_key_t *)id;
|
||||
int status;
|
||||
|
||||
status = pthread_key_delete(*key);
|
||||
checkStatusQuit(status,"pthread_key_delete","threadPrivateDelete");
|
||||
checkStatusQuit(status,"pthread_key_delete","epicsThreadPrivateDelete");
|
||||
}
|
||||
|
||||
void threadPrivateSet (threadPrivateId id, void *value)
|
||||
void epicsThreadPrivateSet (epicsThreadPrivateId id, void *value)
|
||||
{
|
||||
pthread_key_t *key = (pthread_key_t *)id;
|
||||
int status;
|
||||
|
||||
if(errVerbose && !value)
|
||||
errlogPrintf("threadPrivateSet: setting value of 0\n");
|
||||
errlogPrintf("epicsThreadPrivateSet: setting value of 0\n");
|
||||
status = pthread_setspecific(*key,value);
|
||||
checkStatusQuit(status,"pthread_setspecific","threadPrivateSet");
|
||||
checkStatusQuit(status,"pthread_setspecific","epicsThreadPrivateSet");
|
||||
}
|
||||
|
||||
void *threadPrivateGet(threadPrivateId id)
|
||||
void *epicsThreadPrivateGet(epicsThreadPrivateId id)
|
||||
{
|
||||
pthread_key_t *key = (pthread_key_t *)id;
|
||||
void *value;
|
||||
|
||||
value = pthread_getspecific(*key);
|
||||
if(errVerbose && !value)
|
||||
errlogPrintf("threadPrivateGet: pthread_getspecific returned 0\n");
|
||||
errlogPrintf("epicsThreadPrivateGet: pthread_getspecific returned 0\n");
|
||||
return(value);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ of this distribution.
|
||||
#include "epicsTypes.h"
|
||||
#include "cantProceed.h"
|
||||
#include "errlog.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "tsStamp.h"
|
||||
#include "iocClock.h"
|
||||
@@ -60,7 +60,7 @@ static void syncNTP(void)
|
||||
|
||||
while(1) {
|
||||
double diffTime;
|
||||
if(!firstTime)threadSleep(iocClockSyncRate);
|
||||
if(!firstTime)epicsThreadSleep(iocClockSyncRate);
|
||||
firstTime = 0;
|
||||
status = sntpcTimeGet(piocClockPvt->pserverAddr,
|
||||
piocClockPvt->tickRate,&Currtime);
|
||||
@@ -111,9 +111,10 @@ void iocClockInit()
|
||||
errlogPrintf("No NTP server is defined. Clock does not work\n");
|
||||
return;
|
||||
}
|
||||
threadCreate("syncNTP",
|
||||
threadPriorityHigh,threadGetStackSize(threadStackSmall),
|
||||
(THREADFUNC)syncNTP,0);
|
||||
epicsThreadCreate("syncNTP",
|
||||
epicsThreadPriorityHigh,
|
||||
epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||
(EPICSTHREADFUNC)syncNTP,0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <taskLib.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsPrint.h"
|
||||
#include "epicsVersion.h"
|
||||
#include "epicsAssert.h"
|
||||
@@ -45,13 +45,13 @@
|
||||
* epicsAssert ()
|
||||
*
|
||||
* This forces assert failures into the log file and then
|
||||
* calls threadSuspendSelf() instead of exit() so that we can debug
|
||||
* calls epicsThreadSuspendSelf() instead of exit() so that we can debug
|
||||
* the problem.
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI epicsAssert (const char *pFile, const unsigned line, const char *pExp,
|
||||
const char *pAuthorName)
|
||||
{
|
||||
threadId threadid = threadGetIdSelf();
|
||||
epicsThreadId threadid = epicsThreadGetIdSelf();
|
||||
|
||||
epicsPrintf (
|
||||
"\n\n\n%s: A call to \"assert (%s)\" failed in %s at %d\n",
|
||||
@@ -83,6 +83,6 @@ epicsShareFunc void epicsShareAPI epicsAssert (const char *pFile, const unsigned
|
||||
}
|
||||
epicsPrintf ("This problem occurred in \"%s\"\n", epicsReleaseVersion);
|
||||
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* osi/os/vxWorks/osiThread.c */
|
||||
/* osi/os/vxWorks/epicsThread.c */
|
||||
|
||||
/* Author: Marty Kraimer Date: 25AUG99 */
|
||||
|
||||
@@ -23,7 +23,7 @@ int sysClkRateGet(void);
|
||||
|
||||
#include "errlog.h"
|
||||
#include "ellLib.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "cantProceed.h"
|
||||
#include "epicsAssert.h"
|
||||
#include "vxLib.h"
|
||||
@@ -36,14 +36,14 @@ int sysClkRateGet(void);
|
||||
#else
|
||||
#define ARCH_STACK_FACTOR 2
|
||||
#endif
|
||||
static const unsigned stackSizeTable[threadStackBig+1] =
|
||||
static const unsigned stackSizeTable[epicsThreadStackBig+1] =
|
||||
{4000*ARCH_STACK_FACTOR, 6000*ARCH_STACK_FACTOR, 11000*ARCH_STACK_FACTOR};
|
||||
|
||||
/* definitions for implementation of threadPrivate */
|
||||
/* definitions for implementation of epicsThreadPrivate */
|
||||
static void **papTSD = 0;
|
||||
static int nthreadPrivate = 0;
|
||||
static int nepicsThreadPrivate = 0;
|
||||
|
||||
static SEM_ID threadOnceMutex = 0;
|
||||
static SEM_ID epicsThreadOnceMutex = 0;
|
||||
|
||||
/* Just map osi 0 to 99 into vx 100 to 199 */
|
||||
/* remember that for vxWorks lower number means higher priority */
|
||||
@@ -53,10 +53,10 @@ static SEM_ID threadOnceMutex = 0;
|
||||
static unsigned int getOsiPriorityValue(int ossPriority)
|
||||
{
|
||||
if ( ossPriority < 100 ) {
|
||||
return threadPriorityMax;
|
||||
return epicsThreadPriorityMax;
|
||||
}
|
||||
else if ( ossPriority > 199 ) {
|
||||
return threadPriorityMin;
|
||||
return epicsThreadPriorityMin;
|
||||
}
|
||||
else {
|
||||
return ( 199u - (unsigned int) ossPriority );
|
||||
@@ -73,49 +73,49 @@ static int getOssPriorityValue(unsigned int osiPriority)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int threadGetStackSize (threadStackSizeClass stackSizeClass)
|
||||
unsigned int epicsThreadGetStackSize (epicsThreadStackSizeClass stackSizeClass)
|
||||
{
|
||||
|
||||
if (stackSizeClass<threadStackSmall) {
|
||||
errlogPrintf("threadGetStackSize illegal argument (too small)");
|
||||
return stackSizeTable[threadStackBig];
|
||||
if (stackSizeClass<epicsThreadStackSmall) {
|
||||
errlogPrintf("epicsThreadGetStackSize illegal argument (too small)");
|
||||
return stackSizeTable[epicsThreadStackBig];
|
||||
}
|
||||
|
||||
if (stackSizeClass>threadStackBig) {
|
||||
errlogPrintf("threadGetStackSize illegal argument (too large)");
|
||||
return stackSizeTable[threadStackBig];
|
||||
if (stackSizeClass>epicsThreadStackBig) {
|
||||
errlogPrintf("epicsThreadGetStackSize illegal argument (too large)");
|
||||
return stackSizeTable[epicsThreadStackBig];
|
||||
}
|
||||
|
||||
return stackSizeTable[stackSizeClass];
|
||||
}
|
||||
|
||||
void threadInit(void)
|
||||
void epicsThreadInit(void)
|
||||
{
|
||||
static int lock = 0;
|
||||
|
||||
while(!vxTas(&lock)) taskDelay(1);
|
||||
if(threadOnceMutex==0) {
|
||||
threadOnceMutex = semMCreate(
|
||||
if(epicsThreadOnceMutex==0) {
|
||||
epicsThreadOnceMutex = semMCreate(
|
||||
SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY);
|
||||
assert(threadOnceMutex);
|
||||
assert(epicsThreadOnceMutex);
|
||||
}
|
||||
lock = 0;
|
||||
iocClockInit();
|
||||
}
|
||||
|
||||
void threadOnceOsd(threadOnceId *id, void (*func)(void *), void *arg)
|
||||
void epicsThreadOnceOsd(epicsThreadOnceId *id, void (*func)(void *), void *arg)
|
||||
{
|
||||
threadInit();
|
||||
assert(semTake(threadOnceMutex,WAIT_FOREVER)==OK);
|
||||
epicsThreadInit();
|
||||
assert(semTake(epicsThreadOnceMutex,WAIT_FOREVER)==OK);
|
||||
if (*id == 0) { /* 0 => first call */
|
||||
*id = -1; /* -1 => func() active */
|
||||
func(arg);
|
||||
*id = +1; /* +1 => func() done (see threadOnce() macro defn) */
|
||||
*id = +1; /* +1 => func() done (see epicsThreadOnce() macro defn) */
|
||||
}
|
||||
semGive(threadOnceMutex);
|
||||
semGive(epicsThreadOnceMutex);
|
||||
}
|
||||
|
||||
static void createFunction(THREADFUNC func, void *parm)
|
||||
static void createFunction(EPICSTHREADFUNC func, void *parm)
|
||||
{
|
||||
int tid = taskIdSelf();
|
||||
|
||||
@@ -127,14 +127,14 @@ static void createFunction(THREADFUNC func, void *parm)
|
||||
free(papTSD);
|
||||
}
|
||||
|
||||
threadId threadCreate(const char *name,
|
||||
epicsThreadId epicsThreadCreate(const char *name,
|
||||
unsigned int priority, unsigned int stackSize,
|
||||
THREADFUNC funptr,void *parm)
|
||||
EPICSTHREADFUNC funptr,void *parm)
|
||||
{
|
||||
int tid;
|
||||
if(threadOnceMutex==0) threadInit();
|
||||
if(epicsThreadOnceMutex==0) epicsThreadInit();
|
||||
if(stackSize<100) {
|
||||
errlogPrintf("threadCreate %s illegal stackSize %d\n",name,stackSize);
|
||||
errlogPrintf("epicsThreadCreate %s illegal stackSize %d\n",name,stackSize);
|
||||
return(0);
|
||||
}
|
||||
tid = taskSpawn((char *)name,getOssPriorityValue(priority),
|
||||
@@ -142,51 +142,51 @@ threadId threadCreate(const char *name,
|
||||
(FUNCPTR)createFunction,(int)funptr,(int)parm,
|
||||
0,0,0,0,0,0,0,0);
|
||||
if(tid==0) {
|
||||
errlogPrintf("threadCreate taskSpawn failure for %s\n",name);
|
||||
errlogPrintf("epicsThreadCreate taskSpawn failure for %s\n",name);
|
||||
return(0);
|
||||
}
|
||||
return((threadId)tid);
|
||||
return((epicsThreadId)tid);
|
||||
}
|
||||
|
||||
void threadSuspendSelf()
|
||||
void epicsThreadSuspendSelf()
|
||||
{
|
||||
STATUS status;
|
||||
|
||||
status = taskSuspend(taskIdSelf());
|
||||
if(status) errlogPrintf("threadSuspendSelf failed\n");
|
||||
if(status) errlogPrintf("epicsThreadSuspendSelf failed\n");
|
||||
}
|
||||
|
||||
void threadResume(threadId id)
|
||||
void epicsThreadResume(epicsThreadId id)
|
||||
{
|
||||
int tid = (int)id;
|
||||
STATUS status;
|
||||
|
||||
status = taskResume(tid);
|
||||
if(status) errlogPrintf("threadResume failed\n");
|
||||
if(status) errlogPrintf("epicsThreadResume failed\n");
|
||||
}
|
||||
|
||||
void threadExitMain(void)
|
||||
void epicsThreadExitMain(void)
|
||||
{
|
||||
errlogPrintf("threadExitMain was called for vxWorks. Why?\n");
|
||||
errlogPrintf("epicsThreadExitMain was called for vxWorks. Why?\n");
|
||||
}
|
||||
|
||||
unsigned int threadGetPriority(threadId id)
|
||||
unsigned int epicsThreadGetPriority(epicsThreadId id)
|
||||
{
|
||||
int tid = (int)id;
|
||||
STATUS status;
|
||||
int priority = 0;
|
||||
|
||||
status = taskPriorityGet(tid,&priority);
|
||||
if(status) errlogPrintf("threadGetPriority failed\n");
|
||||
if(status) errlogPrintf("epicsThreadGetPriority failed\n");
|
||||
return(getOsiPriorityValue(priority));
|
||||
}
|
||||
|
||||
unsigned int threadGetPrioritySelf(void)
|
||||
unsigned int epicsThreadGetPrioritySelf(void)
|
||||
{
|
||||
return(threadGetPriority(threadGetIdSelf()));
|
||||
return(epicsThreadGetPriority(epicsThreadGetIdSelf()));
|
||||
}
|
||||
|
||||
void threadSetPriority(threadId id,unsigned int osip)
|
||||
void epicsThreadSetPriority(epicsThreadId id,unsigned int osip)
|
||||
{
|
||||
int tid = (int)id;
|
||||
STATUS status;
|
||||
@@ -194,21 +194,21 @@ void threadSetPriority(threadId id,unsigned int osip)
|
||||
|
||||
priority = getOssPriorityValue(osip);
|
||||
status = taskPrioritySet(tid,priority);
|
||||
if(status) errlogPrintf("threadSetPriority failed\n");
|
||||
if(status) errlogPrintf("epicsThreadSetPriority failed\n");
|
||||
}
|
||||
|
||||
threadBoolStatus threadHighestPriorityLevelBelow(
|
||||
epicsThreadBooleanStatus epicsThreadHighestPriorityLevelBelow(
|
||||
unsigned int priority, unsigned *pPriorityJustBelow)
|
||||
{
|
||||
unsigned newPriority = priority - 1;
|
||||
if (newPriority <= 99) {
|
||||
*pPriorityJustBelow = newPriority;
|
||||
return tbsSuccess;
|
||||
return epicsThreadBooleanStatusSuccess;
|
||||
}
|
||||
return tbsFail;
|
||||
return epicsThreadBooleanStatusFail;
|
||||
}
|
||||
|
||||
threadBoolStatus threadLowestPriorityLevelAbove(
|
||||
epicsThreadBooleanStatus epicsThreadLowestPriorityLevelAbove(
|
||||
unsigned int priority, unsigned *pPriorityJustAbove)
|
||||
{
|
||||
unsigned newPriority = priority + 1;
|
||||
@@ -216,59 +216,59 @@ threadBoolStatus threadLowestPriorityLevelAbove(
|
||||
newPriority = priority + 1;
|
||||
if (newPriority <= 99) {
|
||||
*pPriorityJustAbove = newPriority;
|
||||
return tbsSuccess;
|
||||
return epicsThreadBooleanStatusSuccess;
|
||||
}
|
||||
return tbsFail;
|
||||
return epicsThreadBooleanStatusFail;
|
||||
}
|
||||
|
||||
int threadIsEqual(threadId id1, threadId id2)
|
||||
int epicsThreadIsEqual(epicsThreadId id1, epicsThreadId id2)
|
||||
{
|
||||
return((id1==id2) ? 1 : 0);
|
||||
}
|
||||
|
||||
int threadIsSuspended(threadId id)
|
||||
int epicsThreadIsSuspended(epicsThreadId id)
|
||||
{
|
||||
int tid = (int)id;
|
||||
return((int)taskIsSuspended(tid));
|
||||
}
|
||||
|
||||
void threadSleep(double seconds)
|
||||
void epicsThreadSleep(double seconds)
|
||||
{
|
||||
STATUS status;
|
||||
|
||||
status = taskDelay((int)(seconds*sysClkRateGet()));
|
||||
if(status) errlogPrintf(0,"threadSleep\n");
|
||||
if(status) errlogPrintf(0,"epicsThreadSleep\n");
|
||||
}
|
||||
|
||||
threadId threadGetIdSelf(void)
|
||||
epicsThreadId epicsThreadGetIdSelf(void)
|
||||
{
|
||||
return((threadId)taskIdSelf());
|
||||
return((epicsThreadId)taskIdSelf());
|
||||
}
|
||||
|
||||
threadId threadGetId(const char *name)
|
||||
epicsThreadId epicsThreadGetId(const char *name)
|
||||
{
|
||||
int tid = taskNameToId((char *)name);
|
||||
return((threadId)(tid==ERROR?0:tid));
|
||||
return((epicsThreadId)(tid==ERROR?0:tid));
|
||||
}
|
||||
|
||||
const char *threadGetNameSelf(void)
|
||||
const char *epicsThreadGetNameSelf(void)
|
||||
{
|
||||
return taskName(taskIdSelf());
|
||||
}
|
||||
|
||||
void threadGetName (threadId id, char *name, size_t size)
|
||||
void epicsThreadGetName (epicsThreadId id, char *name, size_t size)
|
||||
{
|
||||
int tid = (int)id;
|
||||
strncpy(name,taskName(tid),size-1);
|
||||
name[size-1] = '\0';
|
||||
}
|
||||
|
||||
void threadShowAll(unsigned int level)
|
||||
void epicsThreadShowAll(unsigned int level)
|
||||
{
|
||||
taskShow(0,2);
|
||||
}
|
||||
|
||||
void threadShow(threadId id,unsigned int level)
|
||||
void epicsThreadShow(epicsThreadId id,unsigned int level)
|
||||
{
|
||||
int tid = (int)id;
|
||||
taskShow(tid,level);
|
||||
@@ -277,29 +277,29 @@ void threadShow(threadId id,unsigned int level)
|
||||
/* The following algorithm was thought of by Andrew Johnson APS/ASD .
|
||||
* The basic idea is to use a single vxWorks task variable.
|
||||
* The task variable is papTSD, which is an array of pointers to the TSD
|
||||
* The array size is equal to the number of threadPrivateIds created + 1
|
||||
* when threadPrivateSet is called.
|
||||
* Until the first call to threadPrivateCreate by a application papTSD=0
|
||||
* After first call papTSD[0] is value of nthreadPrivate when
|
||||
* threadPrivateSet was last called by the thread. This is also
|
||||
* the value of threadPrivateId.
|
||||
* The algorithm allows for threadPrivateCreate being called after
|
||||
* the first call to threadPrivateSet.
|
||||
* The array size is equal to the number of epicsThreadPrivateIds created + 1
|
||||
* when epicsThreadPrivateSet is called.
|
||||
* Until the first call to epicsThreadPrivateCreate by a application papTSD=0
|
||||
* After first call papTSD[0] is value of nepicsThreadPrivate when
|
||||
* epicsThreadPrivateSet was last called by the thread. This is also
|
||||
* the value of epicsThreadPrivateId.
|
||||
* The algorithm allows for epicsThreadPrivateCreate being called after
|
||||
* the first call to epicsThreadPrivateSet.
|
||||
*/
|
||||
threadPrivateId threadPrivateCreate()
|
||||
epicsThreadPrivateId epicsThreadPrivateCreate()
|
||||
{
|
||||
static int lock = 0;
|
||||
threadPrivateId id;
|
||||
epicsThreadPrivateId id;
|
||||
|
||||
threadInit();
|
||||
/*lock is necessary because ++nthreadPrivate may not be indivisible*/
|
||||
epicsThreadInit();
|
||||
/*lock is necessary because ++nepicsThreadPrivate may not be indivisible*/
|
||||
while(!vxTas(&lock)) taskDelay(1);
|
||||
id = (threadPrivateId)++nthreadPrivate;
|
||||
id = (epicsThreadPrivateId)++nepicsThreadPrivate;
|
||||
lock = 0;
|
||||
return(id);
|
||||
}
|
||||
|
||||
void threadPrivateDelete(threadPrivateId id)
|
||||
void epicsThreadPrivateDelete(epicsThreadPrivateId id)
|
||||
{
|
||||
/*nothing to delete */
|
||||
return;
|
||||
@@ -309,34 +309,34 @@ void threadPrivateDelete(threadPrivateId id)
|
||||
* Note that it is not necessary to have mutex for following
|
||||
* because they must be called by the same thread
|
||||
*/
|
||||
void threadPrivateSet (threadPrivateId id, void *pvt)
|
||||
void epicsThreadPrivateSet (epicsThreadPrivateId id, void *pvt)
|
||||
{
|
||||
int indpthreadPrivate = (int)id;
|
||||
int nthreadPrivateOld = 0;
|
||||
int indpepicsThreadPrivate = (int)id;
|
||||
int nepicsThreadPrivateOld = 0;
|
||||
|
||||
if(papTSD) nthreadPrivateOld = (int)papTSD[0];
|
||||
if(!papTSD || (nthreadPrivateOld<indpthreadPrivate)) {
|
||||
if(papTSD) nepicsThreadPrivateOld = (int)papTSD[0];
|
||||
if(!papTSD || (nepicsThreadPrivateOld<indpepicsThreadPrivate)) {
|
||||
void **papTSDold = papTSD;
|
||||
int i;
|
||||
|
||||
papTSD = callocMustSucceed(indpthreadPrivate + 1,sizeof(void *),
|
||||
"threadPrivateSet");
|
||||
papTSD[0] = (void *)(indpthreadPrivate);
|
||||
for(i=1; i<= nthreadPrivateOld; i++) papTSD[i] = papTSDold[i];
|
||||
papTSD = callocMustSucceed(indpepicsThreadPrivate + 1,sizeof(void *),
|
||||
"epicsThreadPrivateSet");
|
||||
papTSD[0] = (void *)(indpepicsThreadPrivate);
|
||||
for(i=1; i<= nepicsThreadPrivateOld; i++) papTSD[i] = papTSDold[i];
|
||||
}
|
||||
papTSD[indpthreadPrivate] = pvt;
|
||||
papTSD[indpepicsThreadPrivate] = pvt;
|
||||
}
|
||||
|
||||
void *threadPrivateGet(threadPrivateId id)
|
||||
void *epicsThreadPrivateGet(epicsThreadPrivateId id)
|
||||
{
|
||||
int indpthreadPrivate = (int)id;
|
||||
int indpepicsThreadPrivate = (int)id;
|
||||
void *data;
|
||||
if(!papTSD) {
|
||||
papTSD = callocMustSucceed(indpthreadPrivate + 1,sizeof(void *),
|
||||
"threadPrivateSet");
|
||||
papTSD[0] = (void *)(indpthreadPrivate);
|
||||
papTSD = callocMustSucceed(indpepicsThreadPrivate + 1,sizeof(void *),
|
||||
"epicsThreadPrivateSet");
|
||||
papTSD[0] = (void *)(indpepicsThreadPrivate);
|
||||
}
|
||||
/* Note that threadPrivateGet may be called BEFORE threadPrivateSet*/
|
||||
/* Note that epicsThreadPrivateGet may be called BEFORE epicsThreadPrivateSet*/
|
||||
if ( (int) id <= (int) papTSD[0] ) {
|
||||
data = papTSD[(int)id];
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Author: Jeff Hill
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static void osiThreadCallEntryPoint ( void *pPvt ); // for gnu warning
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "osiThread.h"
|
||||
|
||||
static void osiThreadCallEntryPoint ( void *pPvt )
|
||||
{
|
||||
osiThread *pThread = static_cast <osiThread *> ( pPvt );
|
||||
pThread->begin.wait ();
|
||||
if ( ! pThread->cancel ) {
|
||||
pThread->entryPoint ();
|
||||
}
|
||||
pThread->id = 0;
|
||||
pThread->exit.signal ();
|
||||
}
|
||||
|
||||
osiThread::osiThread ( const char *name, unsigned stackSize, unsigned priority ) :
|
||||
cancel (false)
|
||||
{
|
||||
this->id = threadCreate ( name, priority, stackSize,
|
||||
osiThreadCallEntryPoint, static_cast <void *> (this) );
|
||||
}
|
||||
|
||||
osiThread::~osiThread ()
|
||||
{
|
||||
if ( this->id ) {
|
||||
this->cancel = true;
|
||||
this->begin.signal ();
|
||||
while ( ! this->exit.wait ( 5.0 ) ) {
|
||||
printf ("osiThread::~osiThread ():"
|
||||
" Warning, thread object destroyed before thread exit \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void osiThread::start ()
|
||||
{
|
||||
this->begin.signal ();
|
||||
}
|
||||
|
||||
bool osiThread::isCurrentThread () const
|
||||
{
|
||||
return ( threadGetIdSelf () == this->id );
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
#ifndef osiThreadh
|
||||
#define osiThreadh
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "shareLib.h"
|
||||
|
||||
typedef void (*THREADFUNC)(void *parm);
|
||||
|
||||
static const unsigned threadPriorityMax = 99;
|
||||
static const unsigned threadPriorityMin = 0;
|
||||
|
||||
/* some generic values */
|
||||
static const unsigned threadPriorityLow = 10;
|
||||
static const unsigned threadPriorityMedium = 50;
|
||||
static const unsigned threadPriorityHigh = 90;
|
||||
|
||||
/* some iocCore specific values */
|
||||
static const unsigned threadPriorityChannelAccessServer = 30;
|
||||
static const unsigned threadPriorityScanLow = 60;
|
||||
static const unsigned threadPriorityScanHigh = 70;
|
||||
|
||||
/* stack sizes for each stackSizeClass are implementation and CPU dependent */
|
||||
typedef enum {
|
||||
threadStackSmall, threadStackMedium, threadStackBig
|
||||
} threadStackSizeClass;
|
||||
|
||||
typedef enum {tbsFail, tbsSuccess} threadBoolStatus;
|
||||
|
||||
epicsShareFunc unsigned int epicsShareAPI threadGetStackSize(threadStackSizeClass size);
|
||||
|
||||
typedef int threadOnceId;
|
||||
#define OSITHREAD_ONCE_INIT 0
|
||||
|
||||
/* void threadOnce(threadOnceId *id, THREADFUNC, void *arg); */
|
||||
/* threadOnce is implemented as a macro */
|
||||
/* threadOnceOsd should not be called by user code */
|
||||
epicsShareFunc void epicsShareAPI threadOnceOsd(
|
||||
threadOnceId *id, THREADFUNC, void *arg);
|
||||
|
||||
#define threadOnce(id,func,arg) \
|
||||
if(*(id)<=0) threadOnceOsd((id),(func),(arg))
|
||||
|
||||
epicsShareFunc void epicsShareAPI threadInit(void);
|
||||
epicsShareFunc void epicsShareAPI threadExitMain(void);
|
||||
|
||||
/* (threadId)0 is guaranteed to be an invalid thread id */
|
||||
typedef void *threadId;
|
||||
|
||||
epicsShareFunc threadId epicsShareAPI threadCreate(const char *name,
|
||||
unsigned int priority, unsigned int stackSize,
|
||||
THREADFUNC funptr,void *parm);
|
||||
epicsShareFunc void epicsShareAPI threadSuspendSelf(void);
|
||||
epicsShareFunc void epicsShareAPI threadResume(threadId id);
|
||||
epicsShareFunc unsigned int epicsShareAPI threadGetPriority(threadId id);
|
||||
epicsShareFunc unsigned int epicsShareAPI threadGetPrioritySelf();
|
||||
epicsShareFunc void epicsShareAPI threadSetPriority(
|
||||
threadId id,unsigned int priority);
|
||||
epicsShareFunc threadBoolStatus epicsShareAPI threadHighestPriorityLevelBelow
|
||||
(unsigned int priority, unsigned *pPriorityJustBelow);
|
||||
epicsShareFunc threadBoolStatus epicsShareAPI threadLowestPriorityLevelAbove
|
||||
(unsigned int priority, unsigned *pPriorityJustAbove);
|
||||
epicsShareFunc int epicsShareAPI threadIsEqual(threadId id1, threadId id2);
|
||||
epicsShareFunc int epicsShareAPI threadIsSuspended(threadId id);
|
||||
epicsShareFunc void epicsShareAPI threadSleep(double seconds);
|
||||
epicsShareFunc threadId epicsShareAPI threadGetIdSelf(void);
|
||||
epicsShareFunc threadId epicsShareAPI threadGetId(const char *name);
|
||||
|
||||
epicsShareFunc const char * epicsShareAPI threadGetNameSelf(void);
|
||||
|
||||
/* For threadGetName name is guaranteed to be null terminated */
|
||||
/* size is size of buffer to hold name (including terminator) */
|
||||
/* Failure results in an empty string stored in name */
|
||||
epicsShareFunc void epicsShareAPI threadGetName(threadId id, char *name, size_t size);
|
||||
|
||||
epicsShareFunc void epicsShareAPI threadShowAll(unsigned int level);
|
||||
epicsShareFunc void epicsShareAPI threadShow(threadId id,unsigned int level);
|
||||
|
||||
typedef void * threadPrivateId;
|
||||
epicsShareFunc threadPrivateId epicsShareAPI threadPrivateCreate (void);
|
||||
epicsShareFunc void epicsShareAPI threadPrivateDelete (threadPrivateId id);
|
||||
epicsShareFunc void epicsShareAPI threadPrivateSet (threadPrivateId, void *);
|
||||
epicsShareFunc void * epicsShareAPI threadPrivateGet (threadPrivateId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "locationException.h"
|
||||
#include "epicsEvent.h"
|
||||
|
||||
class epicsShareClass osiThread {
|
||||
public:
|
||||
osiThread (const char *name, unsigned stackSize,
|
||||
unsigned priority=threadPriorityLow);
|
||||
virtual ~osiThread ();
|
||||
|
||||
void start();
|
||||
|
||||
virtual void entryPoint () = 0;
|
||||
|
||||
void resume ();
|
||||
void getName (char *name, size_t size) const;
|
||||
unsigned getPriority () const;
|
||||
void setPriority (unsigned);
|
||||
bool priorityIsEqual (const osiThread &otherThread) const;
|
||||
bool isSuspended () const;
|
||||
bool isCurrentThread () const;
|
||||
bool operator == (const osiThread &rhs) const;
|
||||
|
||||
/* these operate on the current thread */
|
||||
static void suspendSelf ();
|
||||
static void sleep (double seconds);
|
||||
static osiThread & getSelf ();
|
||||
static const char * getNameSelf ();
|
||||
private:
|
||||
threadId id;
|
||||
epicsEvent exit;
|
||||
epicsEvent begin;
|
||||
bool cancel;
|
||||
|
||||
osiThread ( const osiThread & );
|
||||
osiThread & operator = ( const osiThread & );
|
||||
|
||||
friend void osiThreadCallEntryPoint (void *pPvt);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class osiThreadPrivate {
|
||||
public:
|
||||
osiThreadPrivate ();
|
||||
~osiThreadPrivate ();
|
||||
T *get () const;
|
||||
void set (T *);
|
||||
class unableToCreateThreadPrivate {}; // exception
|
||||
private:
|
||||
threadPrivateId id;
|
||||
};
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "osdThread.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "epicsAssert.h"
|
||||
|
||||
inline void osiThread::resume ()
|
||||
{
|
||||
threadResume (this->id);
|
||||
}
|
||||
|
||||
inline void osiThread::getName (char *name, size_t size) const
|
||||
{
|
||||
threadGetName (this->id, name, size);
|
||||
}
|
||||
|
||||
inline unsigned osiThread::getPriority () const
|
||||
{
|
||||
return threadGetPriority (this->id);
|
||||
}
|
||||
|
||||
inline void osiThread::setPriority (unsigned priority)
|
||||
{
|
||||
threadSetPriority (this->id, priority);
|
||||
}
|
||||
|
||||
inline bool osiThread::priorityIsEqual (const osiThread &otherThread) const
|
||||
{
|
||||
if ( threadIsEqual (this->id, otherThread.id) ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool osiThread::isSuspended () const
|
||||
{
|
||||
if ( threadIsSuspended (this->id) ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool osiThread::operator == (const osiThread &rhs) const
|
||||
{
|
||||
return (this->id == rhs.id);
|
||||
}
|
||||
|
||||
inline void osiThread::suspendSelf ()
|
||||
{
|
||||
threadSuspendSelf ();
|
||||
}
|
||||
|
||||
inline void osiThread::sleep (double seconds)
|
||||
{
|
||||
threadSleep (seconds);
|
||||
}
|
||||
|
||||
inline osiThread & osiThread::getSelf ()
|
||||
{
|
||||
return * static_cast<osiThread *> ( threadGetIdSelf () );
|
||||
}
|
||||
|
||||
inline const char *osiThread::getNameSelf ()
|
||||
{
|
||||
return threadGetNameSelf ();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline osiThreadPrivate<T>::osiThreadPrivate ()
|
||||
{
|
||||
this->id = threadPrivateCreate ();
|
||||
if (this->id == 0) {
|
||||
throwWithLocation ( unableToCreateThreadPrivate () );
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline osiThreadPrivate<T>::~osiThreadPrivate ()
|
||||
{
|
||||
threadPrivateDelete ( this->id );
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T *osiThreadPrivate<T>::get () const
|
||||
{
|
||||
return static_cast<T *> ( threadPrivateGet (this->id) );
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void osiThreadPrivate<T>::set (T *pIn)
|
||||
{
|
||||
threadPrivateSet ( this->id, static_cast<void *> (pIn) );
|
||||
}
|
||||
|
||||
#endif /* ifdef __cplusplus */
|
||||
|
||||
#endif /* osiThreadh */
|
||||
@@ -24,7 +24,7 @@ of this distribution.
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "errlog.h"
|
||||
#include "ellLib.h"
|
||||
@@ -38,7 +38,7 @@ struct task_list {
|
||||
MYFUNCPTR callback;
|
||||
void *arg;
|
||||
union {
|
||||
threadId tid;
|
||||
epicsThreadId tid;
|
||||
void *userpvt;
|
||||
} id;
|
||||
int suspended;
|
||||
@@ -49,7 +49,7 @@ static ELLLIST anylist;
|
||||
static epicsMutexId lock;
|
||||
static epicsMutexId anylock;
|
||||
static epicsMutexId alloclock;
|
||||
static threadId taskwdid=0;
|
||||
static epicsThreadId taskwdid=0;
|
||||
volatile int taskwdOn=TRUE;
|
||||
struct freeList{
|
||||
struct freeList *next;
|
||||
@@ -71,19 +71,19 @@ static void taskwdInitPvt(void *arg)
|
||||
alloclock = epicsMutexMustCreate();
|
||||
ellInit(&list);
|
||||
ellInit(&anylist);
|
||||
taskwdid = threadCreate(
|
||||
"taskwd",threadPriorityLow,
|
||||
threadGetStackSize(threadStackSmall),
|
||||
(THREADFUNC)taskwdTask,0);
|
||||
taskwdid = epicsThreadCreate(
|
||||
"taskwd",epicsThreadPriorityLow,
|
||||
epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||
(EPICSTHREADFUNC)taskwdTask,0);
|
||||
}
|
||||
void epicsShareAPI taskwdInit()
|
||||
{
|
||||
static threadOnceId taskwdOnceFlag = OSITHREAD_ONCE_INIT;
|
||||
static epicsThreadOnceId taskwdOnceFlag = EPICS_THREAD_ONCE_INIT;
|
||||
void *arg = 0;
|
||||
threadOnce(&taskwdOnceFlag,taskwdInitPvt,arg);
|
||||
epicsThreadOnce(&taskwdOnceFlag,taskwdInitPvt,arg);
|
||||
}
|
||||
|
||||
void epicsShareAPI taskwdInsert(threadId tid,TASKWDFUNCPRR callback,void *arg)
|
||||
void epicsShareAPI taskwdInsert(epicsThreadId tid,TASKWDFUNCPRR callback,void *arg)
|
||||
{
|
||||
struct task_list *pt;
|
||||
|
||||
@@ -112,7 +112,7 @@ void epicsShareAPI taskwdAnyInsert(void *userpvt,TASKWDANYFUNCPRR callback,void
|
||||
epicsMutexUnlock(anylock);
|
||||
}
|
||||
|
||||
void epicsShareAPI taskwdRemove(threadId tid)
|
||||
void epicsShareAPI taskwdRemove(epicsThreadId tid)
|
||||
{
|
||||
struct task_list *pt;
|
||||
|
||||
@@ -162,7 +162,7 @@ static void taskwdTask(void)
|
||||
pt = (struct task_list *)ellFirst(&list);
|
||||
while(pt) {
|
||||
next = (struct task_list *)ellNext((void *)pt);
|
||||
if(threadIsSuspended(pt->id.tid)) {
|
||||
if(epicsThreadIsSuspended(pt->id.tid)) {
|
||||
char message[100];
|
||||
|
||||
if(!pt->suspended) {
|
||||
@@ -197,7 +197,7 @@ static void taskwdTask(void)
|
||||
}
|
||||
epicsMutexUnlock(lock);
|
||||
}
|
||||
threadSleep(TASKWD_DELAY);
|
||||
epicsThreadSleep(TASKWD_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ of this distribution.
|
||||
#ifndef INCtaskwdh
|
||||
#define INCtaskwdh 1
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "shareLib.h"
|
||||
|
||||
typedef void (*TASKWDFUNCPRR)(void *parm);
|
||||
typedef void (*TASKWDANYFUNCPRR)(void *parm,threadId tid);
|
||||
typedef void (*TASKWDANYFUNCPRR)(void *parm,epicsThreadId tid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -34,10 +34,10 @@ extern "C" {
|
||||
|
||||
epicsShareFunc void epicsShareAPI taskwdInit(void);
|
||||
epicsShareFunc void epicsShareAPI taskwdInsert(
|
||||
threadId tid, TASKWDFUNCPRR callback,void *arg);
|
||||
epicsThreadId tid, TASKWDFUNCPRR callback,void *arg);
|
||||
epicsShareFunc void epicsShareAPI taskwdAnyInsert(
|
||||
void *userpvt, TASKWDANYFUNCPRR callback,void *arg);
|
||||
epicsShareFunc void epicsShareAPI taskwdRemove(threadId tid);
|
||||
epicsShareFunc void epicsShareAPI taskwdRemove(epicsThreadId tid);
|
||||
epicsShareFunc void epicsShareAPI taskwdAnyRemove(void *userpvt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -6,6 +6,11 @@ PROD_LIBS += Com
|
||||
|
||||
USR_LIBS_hpux += cma
|
||||
|
||||
|
||||
epicsThreadTestHost_SRCS += epicsThreadTestMain.cpp epicsThreadTest.cpp
|
||||
PROD += epicsThreadTestHost
|
||||
OBJS_IOC += epicsThreadTest
|
||||
|
||||
timerTestHost_SRCS += timerTestMain.c timerTest.c
|
||||
PROD += timerTestHost
|
||||
OBJS_IOC += timerTest
|
||||
@@ -22,10 +27,6 @@ epicsMutexTestHost_SRCS += epicsMutexTestMain.cpp epicsMutexTest.cpp
|
||||
PROD += epicsMutexTestHost
|
||||
OBJS_IOC += epicsMutexTest
|
||||
|
||||
threadTestHost_SRCS += threadTestMain.c threadTest.c
|
||||
PROD += threadTestHost
|
||||
OBJS_IOC += threadTest
|
||||
|
||||
#fdmgrTest_SRCS += fdmgrTest.c
|
||||
#PROD += fdmgrTest
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ of this distribution.
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsRingPointer.h"
|
||||
@@ -30,11 +30,15 @@ typedef struct info {
|
||||
epicsRingPointerId ring;
|
||||
}info;
|
||||
|
||||
extern "C" {
|
||||
static void consumer(void *arg);
|
||||
}
|
||||
|
||||
static void consumer(void *arg)
|
||||
{
|
||||
info *pinfo = (info *)arg;
|
||||
time_t tp;
|
||||
threadId idSelf = threadGetIdSelf();
|
||||
epicsThreadId idSelf = epicsThreadGetIdSelf();
|
||||
|
||||
printf("consumer %p starting time %ld\n",idSelf,time(&tp));
|
||||
while(1) {
|
||||
@@ -50,7 +54,7 @@ static void consumer(void *arg)
|
||||
idSelf,(int)status,time(&tp));
|
||||
}
|
||||
while(epicsRingPointerGetUsed(pinfo->ring)>=2) {
|
||||
threadId message[2];
|
||||
epicsThreadId message[2];
|
||||
int i;
|
||||
|
||||
for(i=0; i<2; i++) {
|
||||
@@ -66,11 +70,15 @@ static void consumer(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
static void producer(void *arg);
|
||||
}
|
||||
|
||||
static void producer(void *arg)
|
||||
{
|
||||
info *pinfo = (info *)arg;
|
||||
time_t tp;
|
||||
threadId idSelf = threadGetIdSelf();
|
||||
epicsThreadId idSelf = epicsThreadGetIdSelf();
|
||||
int ntimes=0;
|
||||
|
||||
printf("producer %p starting time %ld\n",idSelf,time(&tp));
|
||||
@@ -94,14 +102,14 @@ static void producer(void *arg)
|
||||
for(i=0; i<2; i++) {
|
||||
if(!epicsRingPointerPush(pinfo->ring,idSelf))
|
||||
printf("producer %p error\n",idSelf);
|
||||
if(i==0 && (ntimes%4==0)) threadSleep(.1);
|
||||
if(i==0 && (ntimes%4==0)) epicsThreadSleep(.1);
|
||||
}
|
||||
printf("producer %p sending\n",idSelf);
|
||||
} else {
|
||||
printf("producer %p ring buffer is full\n",idSelf);
|
||||
}
|
||||
epicsMutexUnlock(pinfo->lockRing);
|
||||
threadSleep(1.0);
|
||||
epicsThreadSleep(1.0);
|
||||
epicsEventSignal(pinfo->event);
|
||||
}
|
||||
}
|
||||
@@ -109,7 +117,7 @@ static void producer(void *arg)
|
||||
extern "C" void epicsEventTest(int nthreads,int verbose)
|
||||
{
|
||||
unsigned int stackSize;
|
||||
threadId *id;
|
||||
epicsThreadId *id;
|
||||
char **name;
|
||||
int i;
|
||||
info *pinfo;
|
||||
@@ -118,7 +126,6 @@ extern "C" void epicsEventTest(int nthreads,int verbose)
|
||||
time_t tp;
|
||||
int errVerboseSave = errVerbose;
|
||||
|
||||
threadInit ();
|
||||
errVerbose = verbose;
|
||||
event = epicsEventMustCreate(epicsEventEmpty);
|
||||
printf("calling epicsEventWaitWithTimeout(event,2.0) time %ld\n",time(&tp));
|
||||
@@ -146,23 +153,23 @@ extern "C" void epicsEventTest(int nthreads,int verbose)
|
||||
pinfo->event = event;
|
||||
pinfo->lockRing = epicsMutexCreate();
|
||||
pinfo->ring = epicsRingPointerCreate(1024*2);
|
||||
stackSize = threadGetStackSize(threadStackSmall);
|
||||
threadCreate("consumer",50,stackSize,consumer,pinfo);
|
||||
id = (threadId *)calloc(nthreads,sizeof(threadId));
|
||||
stackSize = epicsThreadGetStackSize(epicsThreadStackSmall);
|
||||
epicsThreadCreate("consumer",50,stackSize,consumer,pinfo);
|
||||
id = (epicsThreadId *)calloc(nthreads,sizeof(epicsThreadId));
|
||||
name = (char **)calloc(nthreads,sizeof(char *));
|
||||
for(i=0; i<nthreads; i++) {
|
||||
name[i] = (char *)calloc(10,sizeof(char));
|
||||
sprintf(name[i],"producer%d",i);
|
||||
id[i] = threadCreate(name[i],40,stackSize,producer,pinfo);
|
||||
id[i] = epicsThreadCreate(name[i],40,stackSize,producer,pinfo);
|
||||
printf("created producer %d id %p time %ld\n",
|
||||
i, id[i],time(&tp));
|
||||
}
|
||||
threadSleep(5.0);
|
||||
epicsThreadSleep(5.0);
|
||||
printf("semTest setting quit time %ld\n",time(&tp));
|
||||
pinfo->quit = 1;
|
||||
threadSleep(2.0);
|
||||
epicsThreadSleep(2.0);
|
||||
epicsEventSignal(pinfo->event);
|
||||
threadSleep(1.0);
|
||||
epicsThreadSleep(1.0);
|
||||
printf("semTest returning time %ld\n",time(&tp));
|
||||
errVerbose = errVerboseSave;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ of this distribution.
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
extern "C" void epicsEventTest(int nthreads,int errVerbose);
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ of this distribution.
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "errlog.h"
|
||||
|
||||
@@ -46,16 +46,16 @@ static void mutexThread(void *arg)
|
||||
}
|
||||
printf("mutexThread %d epicsMutexLock time %ld\n",
|
||||
pinfo->threadnum,time(&tp));
|
||||
threadSleep(.1);
|
||||
epicsThreadSleep(.1);
|
||||
epicsMutexUnlock(pinfo->mutex);
|
||||
threadSleep(.9);
|
||||
epicsThreadSleep(.9);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void epicsMutexTest(int nthreads,int verbose)
|
||||
{
|
||||
unsigned int stackSize;
|
||||
threadId *id;
|
||||
epicsThreadId *id;
|
||||
int i;
|
||||
char **name;
|
||||
void **arg;
|
||||
@@ -65,7 +65,6 @@ extern "C" void epicsMutexTest(int nthreads,int verbose)
|
||||
time_t tp;
|
||||
int errVerboseSave = errVerbose;
|
||||
|
||||
threadInit ();
|
||||
errVerbose = verbose;
|
||||
mutex = epicsMutexMustCreate();
|
||||
printf("calling epicsMutexLock(mutex) time %ld\n",time(&tp));
|
||||
@@ -90,11 +89,11 @@ extern "C" void epicsMutexTest(int nthreads,int verbose)
|
||||
errVerbose = errVerboseSave;
|
||||
return;
|
||||
}
|
||||
id = (void **)calloc(nthreads,sizeof(threadId));
|
||||
id = (void **)calloc(nthreads,sizeof(epicsThreadId));
|
||||
name = (char **)calloc(nthreads,sizeof(char *));
|
||||
arg = (void **)calloc(nthreads,sizeof(void *));
|
||||
pinfo = (info **)calloc(nthreads,sizeof(info *));
|
||||
stackSize = threadGetStackSize(threadStackSmall);
|
||||
stackSize = epicsThreadGetStackSize(epicsThreadStackSmall);
|
||||
for(i=0; i<nthreads; i++) {
|
||||
name[i] = (char *)calloc(10,sizeof(char));
|
||||
sprintf(name[i],"task%d",i);
|
||||
@@ -102,15 +101,15 @@ extern "C" void epicsMutexTest(int nthreads,int verbose)
|
||||
pinfo[i]->threadnum = i;
|
||||
pinfo[i]->mutex = mutex;
|
||||
arg[i] = pinfo[i];
|
||||
id[i] = threadCreate(name[i],40,stackSize,(THREADFUNC)mutexThread,arg[i]);
|
||||
id[i] = epicsThreadCreate(name[i],40,stackSize,(EPICSTHREADFUNC)mutexThread,arg[i]);
|
||||
printf("semTest created mutexThread %d id %p time %ld\n",
|
||||
i, id[i],time(&tp));
|
||||
}
|
||||
threadSleep(5.0);
|
||||
epicsThreadSleep(5.0);
|
||||
printf("semTest setting quit time %ld\n",time(&tp));
|
||||
for(i=0; i<nthreads; i++) {
|
||||
pinfo[i]->quit = 1;
|
||||
}
|
||||
threadSleep(2.0);
|
||||
epicsThreadSleep(2.0);
|
||||
errVerbose = errVerboseSave;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ of this distribution.
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
extern "C" void epicsMutexTest(int nthreads,int errVerbose);
|
||||
|
||||
|
||||
|
||||
88
src/libCom/test/epicsThreadTest.cpp
Normal file
88
src/libCom/test/epicsThreadTest.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/* epicsThreadTest.cpp */
|
||||
|
||||
/* Author: Marty Kraimer Date: 26JAN2000 */
|
||||
|
||||
/********************COPYRIGHT NOTIFICATION**********************************
|
||||
This software was developed under a United States Government license
|
||||
described on the COPYRIGHT_UniversityOfChicago file included as part
|
||||
of this distribution.
|
||||
****************************************************************************/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "epicsThread.h"
|
||||
#include "errlog.h"
|
||||
|
||||
static epicsThreadPrivate<int> privateKey;
|
||||
|
||||
class myThread: public epicsThreadRunable {
|
||||
public:
|
||||
myThread(int arg,const char *name);
|
||||
virtual ~myThread();
|
||||
virtual void run();
|
||||
epicsThread thread;
|
||||
private:
|
||||
int *argvalue;
|
||||
};
|
||||
|
||||
myThread::myThread(int arg,const char *name) :
|
||||
thread(*this,name,epicsThreadGetStackSize(epicsThreadStackSmall),50+arg),
|
||||
argvalue(0)
|
||||
{
|
||||
argvalue = new int;
|
||||
*argvalue = arg;
|
||||
thread.start();
|
||||
}
|
||||
|
||||
myThread::~myThread() {delete argvalue;}
|
||||
|
||||
void myThread::run()
|
||||
{
|
||||
int myPrivate = *argvalue;
|
||||
privateKey.set(argvalue);
|
||||
errlogPrintf("threadFunc %d starting argvalue %p\n",myPrivate,argvalue);
|
||||
epicsThreadSleep(2.0);
|
||||
argvalue = privateKey.get();
|
||||
errlogPrintf("threadFunc %d stopping argvalue %p\n",myPrivate,argvalue);
|
||||
}
|
||||
|
||||
extern "C" void threadTest(int ntasks,int verbose)
|
||||
{
|
||||
myThread **papmyThread;
|
||||
int i;
|
||||
char **name;
|
||||
int startPriority,minPriority,maxPriority;
|
||||
int errVerboseSave = errVerbose;
|
||||
|
||||
errVerbose = verbose;
|
||||
errlogInit(4096);
|
||||
papmyThread = (myThread **)calloc(ntasks,sizeof(myThread *));
|
||||
name = (char **)calloc(ntasks,sizeof(char **));
|
||||
errlogPrintf("threadTest starting\n");
|
||||
for(i=0; i<ntasks; i++) {
|
||||
name[i] = (char *)calloc(10,sizeof(char));
|
||||
sprintf(name[i],"task%d",i);
|
||||
papmyThread[i] = new myThread(i,name[i]);
|
||||
errlogPrintf("threadTest created %d myThread %p\n",i,papmyThread[i]);
|
||||
startPriority = papmyThread[i]->thread.getPriority();
|
||||
papmyThread[i]->thread.setPriority(epicsThreadPriorityMin);
|
||||
minPriority = papmyThread[i]->thread.getPriority();
|
||||
papmyThread[i]->thread.setPriority(epicsThreadPriorityMax);
|
||||
maxPriority = papmyThread[i]->thread.getPriority();
|
||||
papmyThread[i]->thread.setPriority(50+i);
|
||||
if(i==0)errlogPrintf("startPriority %d minPriority %d maxPriority %d\n",
|
||||
startPriority,minPriority,maxPriority);
|
||||
}
|
||||
epicsThreadSleep(.1);
|
||||
epicsThreadShowAll(0);
|
||||
epicsThreadSleep(5.0);
|
||||
errlogPrintf("epicsThreadTest returning\n");
|
||||
epicsThreadSleep(.5);
|
||||
errVerbose = errVerboseSave;
|
||||
}
|
||||
@@ -15,8 +15,8 @@ of this distribution.
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
void threadTest(int nthreads,int errVerbose);
|
||||
#include "epicsThread.h"
|
||||
extern "C" void threadTest(int nthreads,int errVerbose);
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#include "osiTime.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "errlog.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -16,7 +16,7 @@ of this distribution.
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsRingPointer.h"
|
||||
#include "errlog.h"
|
||||
#include "epicsEvent.h"
|
||||
@@ -62,7 +62,7 @@ void ringPointerTest()
|
||||
if(!consumerEvent) {printf("epicsEventMustCreate failed\n");exit(1);}
|
||||
pinfo->ring = ring = epicsRingPointerCreate(ringSize);
|
||||
if(!ring) {printf("epicsRingPointerCreate failed\n");exit(1);}
|
||||
threadCreate("consumer",50,threadGetStackSize(threadStackSmall),
|
||||
epicsThreadCreate("consumer",50,epicsThreadGetStackSize(epicsThreadStackSmall),
|
||||
consumer,pinfo);
|
||||
if(!epicsRingPointerIsEmpty(ring)) printf("epicsRingPointerIsEmpty failed\n");
|
||||
printf("fill ring\n");
|
||||
@@ -83,11 +83,11 @@ void ringPointerTest()
|
||||
for(i=0; i<ringSize*2; i++) {
|
||||
while(epicsRingPointerIsFull(ring)) {
|
||||
epicsEventSignal(consumerEvent);
|
||||
threadSleep(2.0);
|
||||
epicsThreadSleep(2.0);
|
||||
}
|
||||
if(!epicsRingPointerPush(ring,(void *)&value[i]))
|
||||
printf("Why is ring full\n");
|
||||
}
|
||||
epicsEventSignal(consumerEvent);
|
||||
threadSleep(2.0);
|
||||
epicsThreadSleep(2.0);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ of this distribution.
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
void ringPointerTest(void);
|
||||
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/* threadTest.c */
|
||||
|
||||
/* Author: Marty Kraimer Date: 26JAN2000 */
|
||||
|
||||
/********************COPYRIGHT NOTIFICATION**********************************
|
||||
This software was developed under a United States Government license
|
||||
described on the COPYRIGHT_UniversityOfChicago file included as part
|
||||
of this distribution.
|
||||
****************************************************************************/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "errlog.h"
|
||||
|
||||
threadPrivateId privateKey;
|
||||
|
||||
static void threadFunc(void *arg)
|
||||
{
|
||||
int myPrivate;
|
||||
int argvalue = *(int *)arg;
|
||||
myPrivate = argvalue;
|
||||
threadPrivateSet(privateKey,(void *)argvalue);
|
||||
errlogPrintf("threadFunc %d starting\n",argvalue);
|
||||
threadSleep(2.0);
|
||||
argvalue = -1;
|
||||
argvalue = (int)threadPrivateGet(privateKey);
|
||||
errlogPrintf("threadFunc %d stopping myPrivate %d\n",argvalue,myPrivate);
|
||||
}
|
||||
|
||||
void threadTest(int ntasks,int verbose)
|
||||
{
|
||||
unsigned int stackSize;
|
||||
threadId *id;
|
||||
int i;
|
||||
char **name;
|
||||
void **arg;
|
||||
int startPriority,minPriority,maxPriority;
|
||||
int errVerboseSave = errVerbose;
|
||||
|
||||
threadInit ();
|
||||
errVerbose = verbose;
|
||||
errlogInit(4096);
|
||||
id = calloc(ntasks,sizeof(threadId *));
|
||||
name = calloc(ntasks,sizeof(char **));
|
||||
arg = calloc(ntasks,sizeof(void *));
|
||||
errlogPrintf("threadTest starting\n");
|
||||
stackSize = threadGetStackSize(threadStackSmall);
|
||||
errlogPrintf("stackSize %u\n",stackSize);
|
||||
privateKey = threadPrivateCreate();
|
||||
for(i=0; i<ntasks; i++) {
|
||||
int *argvalue;
|
||||
name[i] = calloc(10,sizeof(char));
|
||||
sprintf(name[i],"task%d",i);
|
||||
arg[i] = calloc(1,sizeof(int));
|
||||
argvalue = (int *)arg[i];
|
||||
*argvalue = i;
|
||||
startPriority = 50+i;
|
||||
|
||||
id[i] = threadCreate(name[i],startPriority,stackSize,threadFunc,arg[i]);
|
||||
errlogPrintf("threadTest created %d id %p\n",i,id[i]);
|
||||
startPriority = threadGetPriority(id[i]);
|
||||
threadSetPriority(id[i],threadPriorityMin);
|
||||
minPriority = threadGetPriority(id[i]);
|
||||
threadSetPriority(id[i],threadPriorityMax);
|
||||
maxPriority = threadGetPriority(id[i]);
|
||||
threadSetPriority(id[i],50+i);
|
||||
if(i==0)errlogPrintf("startPriority %d minPriority %d maxPriority %d\n",
|
||||
startPriority,minPriority,maxPriority);
|
||||
}
|
||||
threadSleep(.1);
|
||||
threadShowAll(0);
|
||||
threadSleep(5.0);
|
||||
errlogPrintf("threadTest terminating\n");
|
||||
threadSleep(.5);
|
||||
errVerbose = errVerboseSave;
|
||||
}
|
||||
@@ -14,7 +14,7 @@ of this distribution.
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "osiTimer.h"
|
||||
#include "errlog.h"
|
||||
#include "tsStamp.h"
|
||||
@@ -42,8 +42,7 @@ void timerTest(void)
|
||||
TS_STAMP start;
|
||||
int i;
|
||||
|
||||
threadInit ();
|
||||
timerQueue = osiTimerQueueCreate(threadPriorityLow);
|
||||
timerQueue = osiTimerQueueCreate(epicsThreadPriorityLow);
|
||||
for(i=0; i<ntimers ; i++) {
|
||||
timer[i] = calloc(1,sizeof(myPvt));
|
||||
timer[i]->timer = osiTimerCreate(&jumpTable,timerQueue,(void *)timer[i]);
|
||||
@@ -52,7 +51,7 @@ void timerTest(void)
|
||||
timer[i]->requestedDiff = (double)i;
|
||||
osiTimerArm(timer[i]->timer,(double)i);
|
||||
}
|
||||
threadSleep((double)(ntimers + 2));
|
||||
epicsThreadSleep((double)(ntimers + 2));
|
||||
printf("timerTest returning\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -39,13 +39,17 @@
|
||||
#include "locationException.h"
|
||||
#include "errlog.h"
|
||||
|
||||
class osiTimerThread : public osiThread {
|
||||
class osiTimerThread : public epicsThreadRunable {
|
||||
public:
|
||||
osiTimerThread (osiTimerQueue &, unsigned priority);
|
||||
virtual ~osiTimerThread();
|
||||
private:
|
||||
friend class osiTimer;
|
||||
friend class osiTimerQueue;
|
||||
epicsThread thread;
|
||||
osiTimerQueue &queue;
|
||||
|
||||
virtual void entryPoint ();
|
||||
virtual void run();
|
||||
};
|
||||
|
||||
//
|
||||
@@ -460,7 +464,7 @@ void osiTimerQueue::terminateManagerThread ()
|
||||
|
||||
this->rescheduleEvent.signal ();
|
||||
|
||||
while ( ! this->exitFlag && ! this->pMgrThread->isSuspended () ) {
|
||||
while ( ! this->exitFlag && ! this->pMgrThread->thread.isSuspended () ) {
|
||||
this->exitEvent.wait ( 1.0 );
|
||||
}
|
||||
|
||||
@@ -480,16 +484,19 @@ void osiTimerQueue::terminateManagerThread ()
|
||||
// osiTimerThread::osiTimerThread ()
|
||||
//
|
||||
osiTimerThread::osiTimerThread (osiTimerQueue &queueIn, unsigned priority) :
|
||||
osiThread ("osiTimerQueue", threadGetStackSize (threadStackMedium), priority),
|
||||
thread( *this, "osiTimerQueue",
|
||||
epicsThreadGetStackSize (epicsThreadStackMedium), priority) ,
|
||||
queue (queueIn)
|
||||
{
|
||||
this->start ();
|
||||
this->thread.start ();
|
||||
}
|
||||
|
||||
osiTimerThread::~osiTimerThread() {};
|
||||
|
||||
//
|
||||
// osiTimerThread::entryPoint ()
|
||||
// osiTimerThread::run ()
|
||||
//
|
||||
void osiTimerThread::entryPoint ()
|
||||
void osiTimerThread::run ()
|
||||
{
|
||||
queue.exitFlag = false;
|
||||
while ( ! queue.terminateFlag ) {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#define osiTimerHInclude
|
||||
|
||||
#include "shareLib.h" /* reset share lib defines */
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "tsStamp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
mtsCreateManagerThread // manager thread expires timers asnychronously
|
||||
};
|
||||
epicsShareFunc osiTimerQueue ( managerThreadSelect mts,
|
||||
unsigned managerThreadPriority = threadPriorityMin );
|
||||
unsigned managerThreadPriority = epicsThreadPriorityMin );
|
||||
epicsShareFunc virtual ~osiTimerQueue();
|
||||
epicsShareFunc double delayToFirstExpire () const; /* returns seconds */
|
||||
epicsShareFunc void process ();
|
||||
@@ -235,7 +235,7 @@ typedef struct osiTimerJumpTable {
|
||||
}osiTimerJumpTable;
|
||||
|
||||
typedef void * osiTimerQueueId;
|
||||
/* see osiThread.h for the range of priorities allowed here */
|
||||
/* see epicsThread.h for the range of priorities allowed here */
|
||||
epicsShareFunc osiTimerQueueId epicsShareAPI osiTimerQueueCreate (unsigned managerThreadPriority);
|
||||
|
||||
typedef void * osiTimerId;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "tsStamp.h"
|
||||
#include "cadef.h"
|
||||
#include "dbDefs.h"
|
||||
|
||||
@@ -13,14 +13,14 @@ of this distribution.
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "ioccrf.h"
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
if(argc>=2) {
|
||||
ioccrf(argv[1]);
|
||||
threadSleep(.2);
|
||||
epicsThreadSleep(.2);
|
||||
}
|
||||
ioccrf(NULL);
|
||||
return(0);
|
||||
|
||||
@@ -52,7 +52,7 @@ of this distribution.
|
||||
#include <errno.h>
|
||||
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsPrint.h"
|
||||
#include "tsStamp.h"
|
||||
#include "ellLib.h"
|
||||
@@ -121,7 +121,7 @@ int epicsShareAPI iocInit()
|
||||
taskwdInit();
|
||||
callbackInit();
|
||||
/* let threads start */
|
||||
threadSleep(.1);
|
||||
epicsThreadSleep(.1);
|
||||
initHooks(initHookAfterCallbackInit);
|
||||
dbCaLinkInit(); initHooks(initHookAfterCaLinkInit);
|
||||
initDrvSup(); initHooks(initHookAfterInitDrvSup);
|
||||
@@ -139,7 +139,7 @@ int epicsShareAPI iocInit()
|
||||
errlogPrintf("iocInit: asInit Failed during initialization\n");
|
||||
return(-1);
|
||||
}
|
||||
threadSleep(.5);
|
||||
epicsThreadSleep(.5);
|
||||
initHooks(initHookAfterScanInit);
|
||||
|
||||
/* Enable scan tasks and some driver support functions. */
|
||||
|
||||
@@ -53,9 +53,9 @@ void camsgtask (struct client *client)
|
||||
int nchars;
|
||||
int status;
|
||||
|
||||
client->tid = threadGetIdSelf ();
|
||||
client->tid = epicsThreadGetIdSelf ();
|
||||
|
||||
taskwdInsert (threadGetIdSelf(), NULL, NULL);
|
||||
taskwdInsert (epicsThreadGetIdSelf(), NULL, NULL);
|
||||
|
||||
while (TRUE) {
|
||||
client->recv.stk = 0;
|
||||
|
||||
@@ -231,11 +231,11 @@ struct client *create_client (SOCKET sock)
|
||||
}
|
||||
|
||||
{
|
||||
unsigned priorityOfSelf = threadGetPrioritySelf ();
|
||||
threadBoolStatus tbs;
|
||||
unsigned priorityOfSelf = epicsThreadGetPrioritySelf ();
|
||||
epicsThreadBooleanStatus tbs;
|
||||
|
||||
tbs = threadLowestPriorityLevelAbove ( priorityOfSelf, &priorityOfEvents );
|
||||
if ( tbs != tbsSuccess ) {
|
||||
tbs = epicsThreadLowestPriorityLevelAbove ( priorityOfSelf, &priorityOfEvents );
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
priorityOfEvents = priorityOfSelf;
|
||||
}
|
||||
}
|
||||
@@ -276,17 +276,17 @@ struct client *create_client (SOCKET sock)
|
||||
*/
|
||||
LOCAL int req_server (void)
|
||||
{
|
||||
unsigned priorityOfSelf = threadGetPrioritySelf ();
|
||||
unsigned priorityOfSelf = epicsThreadGetPrioritySelf ();
|
||||
unsigned priorityOfUDP;
|
||||
threadBoolStatus tbs;
|
||||
epicsThreadBooleanStatus tbs;
|
||||
struct sockaddr_in serverAddr; /* server's address */
|
||||
osiSocklen_t addrSize;
|
||||
int status;
|
||||
SOCKET clientSock;
|
||||
threadId tid;
|
||||
epicsThreadId tid;
|
||||
int portChange;
|
||||
|
||||
taskwdInsert ( threadGetIdSelf (), NULL, NULL );
|
||||
taskwdInsert ( epicsThreadGetIdSelf (), NULL, NULL );
|
||||
|
||||
ca_server_port = envGetInetPortConfigParam (&EPICS_CA_SERVER_PORT, CA_SERVER_PORT);
|
||||
|
||||
@@ -300,7 +300,7 @@ LOCAL int req_server (void)
|
||||
*/
|
||||
if ( ( IOC_sock = socket(AF_INET, SOCK_STREAM, 0) ) == INVALID_SOCKET ) {
|
||||
errlogPrintf ("CAS: Socket creation error\n");
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -346,7 +346,7 @@ LOCAL int req_server (void)
|
||||
if ( status < 0 ) {
|
||||
errlogPrintf ( "CAS: Socket bind error was \"%s\"\n",
|
||||
SOCKERRSTR (SOCKERRNO) );
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
portChange = 1;
|
||||
}
|
||||
@@ -360,7 +360,7 @@ LOCAL int req_server (void)
|
||||
if ( status ) {
|
||||
errlogPrintf ( "CAS: getsockname() error %s\n",
|
||||
SOCKERRSTR(SOCKERRNO) );
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
ca_server_port = ntohs (serverAddr.sin_port);
|
||||
@@ -378,17 +378,17 @@ LOCAL int req_server (void)
|
||||
if ( listen ( IOC_sock, 10 ) < 0 ) {
|
||||
errlogPrintf ("CAS: Listen error\n");
|
||||
socket_close (IOC_sock);
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
tbs = threadHighestPriorityLevelBelow ( priorityOfSelf, &priorityOfUDP );
|
||||
if ( tbs != tbsSuccess ) {
|
||||
tbs = epicsThreadHighestPriorityLevelBelow ( priorityOfSelf, &priorityOfUDP );
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
priorityOfUDP = priorityOfSelf;
|
||||
}
|
||||
|
||||
tid = threadCreate ( "CAS-UDP", priorityOfUDP,
|
||||
threadGetStackSize (threadStackMedium),
|
||||
(THREADFUNC) cast_server, 0 );
|
||||
tid = epicsThreadCreate ( "CAS-UDP", priorityOfUDP,
|
||||
epicsThreadGetStackSize (epicsThreadStackMedium),
|
||||
(EPICSTHREADFUNC) cast_server, 0 );
|
||||
if ( tid == 0 ) {
|
||||
epicsPrintf ( "CAS: unable to start connection request thread\n" );
|
||||
}
|
||||
@@ -400,19 +400,19 @@ LOCAL int req_server (void)
|
||||
if ( ( clientSock = accept ( IOC_sock, &sockAddr, &addLen ) ) == INVALID_SOCKET ) {
|
||||
errlogPrintf("CAS: Client accept error was \"%s\"\n",
|
||||
(int) SOCKERRSTR(SOCKERRNO));
|
||||
threadSleep(15.0);
|
||||
epicsThreadSleep(15.0);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
unsigned priorityOfClient;
|
||||
threadId id;
|
||||
epicsThreadId id;
|
||||
struct client *pClient;
|
||||
|
||||
pClient = create_client (clientSock);
|
||||
if (!pClient) {
|
||||
errlogPrintf ( "CAS: unable to create new client because \"%s\"\n",
|
||||
strerror (errno) );
|
||||
threadSleep(15.0);
|
||||
epicsThreadSleep(15.0);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -420,25 +420,25 @@ LOCAL int req_server (void)
|
||||
* go up two levels in priority so that the event task is above the
|
||||
* task waiting in accept ()
|
||||
*/
|
||||
tbs = threadLowestPriorityLevelAbove ( priorityOfSelf, &priorityOfClient );
|
||||
if ( tbs != tbsSuccess ) {
|
||||
tbs = epicsThreadLowestPriorityLevelAbove ( priorityOfSelf, &priorityOfClient );
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
priorityOfClient = priorityOfSelf;
|
||||
}
|
||||
else {
|
||||
unsigned belowPriorityOfClient = priorityOfClient;
|
||||
tbs = threadLowestPriorityLevelAbove ( belowPriorityOfClient, &priorityOfClient );
|
||||
if ( tbs != tbsSuccess ) {
|
||||
tbs = epicsThreadLowestPriorityLevelAbove ( belowPriorityOfClient, &priorityOfClient );
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
priorityOfClient = belowPriorityOfClient;
|
||||
}
|
||||
}
|
||||
|
||||
id = threadCreate ( "CAS-client", priorityOfClient,
|
||||
threadGetStackSize (threadStackBig),
|
||||
(THREADFUNC)camsgtask, (void *)pClient );
|
||||
id = epicsThreadCreate ( "CAS-client", priorityOfClient,
|
||||
epicsThreadGetStackSize (epicsThreadStackBig),
|
||||
(EPICSTHREADFUNC)camsgtask, (void *)pClient );
|
||||
if (id==0) {
|
||||
destroy_client ( pClient );
|
||||
errlogPrintf ( "CAS: task creation for new client failed\n" );
|
||||
threadSleep ( 15.0 );
|
||||
epicsThreadSleep ( 15.0 );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -450,7 +450,7 @@ LOCAL int req_server (void)
|
||||
*/
|
||||
epicsShareFunc int epicsShareAPI rsrv_init (void)
|
||||
{
|
||||
threadId tid;
|
||||
epicsThreadId tid;
|
||||
|
||||
clientQlock = epicsMutexMustCreate();
|
||||
|
||||
@@ -462,10 +462,10 @@ epicsShareFunc int epicsShareAPI rsrv_init (void)
|
||||
prsrv_cast_client = NULL;
|
||||
pCaBucket = NULL;
|
||||
|
||||
tid = threadCreate ("CAS-TCP",
|
||||
threadPriorityChannelAccessServer,
|
||||
threadGetStackSize(threadStackMedium),
|
||||
(THREADFUNC)req_server,0);
|
||||
tid = epicsThreadCreate ("CAS-TCP",
|
||||
epicsThreadPriorityChannelAccessServer,
|
||||
epicsThreadGetStackSize(epicsThreadStackMedium),
|
||||
(EPICSTHREADFUNC)req_server,0);
|
||||
if ( tid == 0 ) {
|
||||
epicsPrintf ( "CAS: unable to start connection request thread\n" );
|
||||
}
|
||||
|
||||
@@ -121,9 +121,9 @@ LOCAL void clean_addrq()
|
||||
*/
|
||||
int cast_server(void)
|
||||
{
|
||||
unsigned priorityOfSelf = threadGetPrioritySelf ();
|
||||
unsigned priorityOfSelf = epicsThreadGetPrioritySelf ();
|
||||
unsigned priorityOfBeacon;
|
||||
threadBoolStatus tbs;
|
||||
epicsThreadBooleanStatus tbs;
|
||||
struct sockaddr_in sin;
|
||||
int status;
|
||||
int count=0;
|
||||
@@ -131,10 +131,10 @@ int cast_server(void)
|
||||
osiSocklen_t recv_addr_size;
|
||||
unsigned short port;
|
||||
int nchars;
|
||||
threadId tid;
|
||||
epicsThreadId tid;
|
||||
int flag;
|
||||
|
||||
taskwdInsert(threadGetIdSelf(),NULL,NULL);
|
||||
taskwdInsert(epicsThreadGetIdSelf(),NULL,NULL);
|
||||
|
||||
port = envGetInetPortConfigParam (&EPICS_CA_SERVER_PORT, CA_SERVER_PORT);
|
||||
|
||||
@@ -153,7 +153,7 @@ int cast_server(void)
|
||||
|
||||
if ( ( IOC_cast_sock = socket (AF_INET, SOCK_DGRAM, 0) ) == INVALID_SOCKET ) {
|
||||
epicsPrintf ("CAS: cast socket creation error\n");
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -203,7 +203,7 @@ int cast_server(void)
|
||||
if( bind(IOC_cast_sock, (struct sockaddr *)&sin, sizeof (sin)) < 0){
|
||||
epicsPrintf ("CAS: UDP server port bind error was \"%s\"\n", SOCKERRSTR ( SOCKERRNO ) );
|
||||
socket_close (IOC_cast_sock);
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
flag = 1;
|
||||
@@ -216,14 +216,14 @@ int cast_server(void)
|
||||
__FILE__, SOCKERRSTR (errnoCpy) );
|
||||
}
|
||||
|
||||
tbs = threadHighestPriorityLevelBelow ( priorityOfSelf, &priorityOfBeacon );
|
||||
if ( tbs != tbsSuccess ) {
|
||||
tbs = epicsThreadHighestPriorityLevelBelow ( priorityOfSelf, &priorityOfBeacon );
|
||||
if ( tbs != epicsThreadBooleanStatusSuccess ) {
|
||||
priorityOfBeacon = priorityOfSelf;
|
||||
}
|
||||
|
||||
tid = threadCreate ( "CAS-beacon", priorityOfBeacon,
|
||||
threadGetStackSize (threadStackSmall),
|
||||
(THREADFUNC) rsrv_online_notify_task, 0 );
|
||||
tid = epicsThreadCreate ( "CAS-beacon", priorityOfBeacon,
|
||||
epicsThreadGetStackSize (epicsThreadStackSmall),
|
||||
(EPICSTHREADFUNC) rsrv_online_notify_task, 0 );
|
||||
if ( tid == 0 ) {
|
||||
epicsPrintf ( "CAS: unable to start beacon thread\n" );
|
||||
}
|
||||
@@ -238,11 +238,11 @@ int cast_server(void)
|
||||
if (prsrv_cast_client) {
|
||||
break;
|
||||
}
|
||||
threadSleep(300.0);
|
||||
epicsThreadSleep(300.0);
|
||||
}
|
||||
|
||||
prsrv_cast_client->sock = IOC_cast_sock;
|
||||
prsrv_cast_client->tid = threadGetIdSelf ();
|
||||
prsrv_cast_client->tid = epicsThreadGetIdSelf ();
|
||||
|
||||
while (TRUE) {
|
||||
status = recvfrom (
|
||||
@@ -255,7 +255,7 @@ int cast_server(void)
|
||||
if (status<0) {
|
||||
epicsPrintf ("CAS: UDP recv error (errno=%s)\n",
|
||||
SOCKERRSTR(SOCKERRNO));
|
||||
threadSleep(1.0);
|
||||
epicsThreadSleep(1.0);
|
||||
}
|
||||
else {
|
||||
prsrv_cast_client->recv.cnt = (unsigned long) status;
|
||||
|
||||
@@ -86,7 +86,7 @@ int rsrv_online_notify_task()
|
||||
|
||||
casSufficentSpaceInPool = osiSufficentSpaceInPool ();
|
||||
|
||||
taskwdInsert (threadGetIdSelf(),NULL,NULL);
|
||||
taskwdInsert (epicsThreadGetIdSelf(),NULL,NULL);
|
||||
|
||||
longStatus = envGetDoubleConfigParam (
|
||||
&EPICS_CA_BEACON_PERIOD, &maxPeriod);
|
||||
@@ -108,14 +108,14 @@ int rsrv_online_notify_task()
|
||||
*/
|
||||
if ( (sock = socket (AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET) {
|
||||
errlogPrintf ("CAS: online socket creation error\n");
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
status = setsockopt (sock, SOL_SOCKET, SO_BROADCAST,
|
||||
(char *)&true, sizeof(true));
|
||||
if (status<0) {
|
||||
errlogPrintf ("CAS: online socket set up error\n");
|
||||
threadSuspendSelf ();
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -199,7 +199,7 @@ int rsrv_online_notify_task()
|
||||
pNode = (osiSockAddrNode *) pNode->node.next;
|
||||
}
|
||||
|
||||
threadSleep(delay);
|
||||
epicsThreadSleep(delay);
|
||||
if (delay<maxdelay) {
|
||||
delay *= 2.0;
|
||||
if (delay>maxdelay) {
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
# error suspect that libCom is being exported from rsrv?
|
||||
#endif /* ifdef epicsExportSharedSymbols */
|
||||
|
||||
#include "osiThread.h"
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "bucketLib.h"
|
||||
@@ -109,7 +109,7 @@ struct client {
|
||||
epicsEventId blockSem; /* used whenever the client blocks */
|
||||
SOCKET sock;
|
||||
int proto;
|
||||
threadId tid;
|
||||
epicsThreadId tid;
|
||||
unsigned minor_version_number;
|
||||
char disconnect; /* disconnect detected */
|
||||
};
|
||||
|
||||
@@ -32,12 +32,10 @@
|
||||
|
||||
#include "ca_test.h"
|
||||
#include "dbDefs.h"
|
||||
#include "osiThread.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
threadInit ();
|
||||
/*
|
||||
* print error and return if arguments are invalid
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user