changes for osiThread=>epicsThread
This commit is contained in:
+6
-4
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
@@ -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 */
|
||||
+13
-13
@@ -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);
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user