osiInterrupt=>epicsInterrupt; epicsThreadInit now static
This commit is contained in:
@@ -117,7 +117,7 @@ SRC_DIRS += $(LIBCOM)/osi
|
||||
INC += osiFileName.h
|
||||
INC += osiSock.h
|
||||
INC += osdSock.h
|
||||
INC += osiInterrupt.h
|
||||
INC += epicsInterrupt.h
|
||||
INC += osdInterrupt.h
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ of this distribution.
|
||||
#include "epicsThread.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsEvent.h"
|
||||
#include "osiInterrupt.h"
|
||||
#include "epicsInterrupt.h"
|
||||
#include "epicsAssert.h"
|
||||
#include "errMdef.h"
|
||||
#include "error.h"
|
||||
@@ -90,8 +90,8 @@ epicsShareFunc int epicsShareAPIV errlogPrintf( const char *pFormat, ...)
|
||||
va_list pvar;
|
||||
int nchar;
|
||||
|
||||
if(interruptIsInterruptContext()) {
|
||||
interruptContextMessage
|
||||
if(epicsInterruptIsInterruptContext()) {
|
||||
epicsInterruptContextMessage
|
||||
("errlogPrintf called from interrupt level\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -108,8 +108,8 @@ epicsShareFunc int epicsShareAPIV errlogVprintf(
|
||||
int nchar;
|
||||
char *pbuffer;
|
||||
|
||||
if(interruptIsInterruptContext()) {
|
||||
interruptContextMessage
|
||||
if(epicsInterruptIsInterruptContext()) {
|
||||
epicsInterruptContextMessage
|
||||
("errlogVprintf called from interrupt level\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -125,8 +125,8 @@ epicsShareFunc int epicsShareAPI errlogMessage(const char *message)
|
||||
{
|
||||
char *pbuffer;
|
||||
|
||||
if(interruptIsInterruptContext()) {
|
||||
interruptContextMessage
|
||||
if(epicsInterruptIsInterruptContext()) {
|
||||
epicsInterruptContextMessage
|
||||
("errlogMessage called from interrupt level\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -144,8 +144,8 @@ epicsShareFunc int epicsShareAPIV errlogSevPrintf(
|
||||
va_list pvar;
|
||||
int nchar;
|
||||
|
||||
if(interruptIsInterruptContext()) {
|
||||
interruptContextMessage
|
||||
if(epicsInterruptIsInterruptContext()) {
|
||||
epicsInterruptContextMessage
|
||||
("errlogSevPrintf called from interrupt level\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -165,8 +165,8 @@ epicsShareFunc int epicsShareAPIV errlogSevVprintf(
|
||||
int totalChar=0;
|
||||
|
||||
if(pvtData.sevToLog>severity) return(0);
|
||||
if(interruptIsInterruptContext()) {
|
||||
interruptContextMessage
|
||||
if(epicsInterruptIsInterruptContext()) {
|
||||
epicsInterruptContextMessage
|
||||
("errlogSevVprintf called from interrupt level\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -255,8 +255,8 @@ epicsShareFunc void epicsShareAPIV errPrintf(long status, const char *pFileName,
|
||||
int nchar;
|
||||
int totalChar=0;
|
||||
|
||||
if(interruptIsInterruptContext()) {
|
||||
interruptContextMessage("errPrintf called from interrupt level\n");
|
||||
if(epicsInterruptIsInterruptContext()) {
|
||||
epicsInterruptContextMessage("errPrintf called from interrupt level\n");
|
||||
return;
|
||||
}
|
||||
errlogInit(0);
|
||||
|
||||
23
src/libCom/osi/epicsInterrupt.h
Normal file
23
src/libCom/osi/epicsInterrupt.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef epicsInterrupth
|
||||
#define epicsInterrupth
|
||||
|
||||
/*THIS MAY BE A BIG PROBLEM */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "shareLib.h"
|
||||
|
||||
epicsShareFunc int epicsShareAPI epicsInterruptLock(void);
|
||||
epicsShareFunc void epicsShareAPI epicsInterruptUnlock(int key);
|
||||
epicsShareFunc int epicsShareAPI epicsInterruptIsInterruptContext(void);
|
||||
epicsShareFunc void epicsShareAPI epicsInterruptContextMessage(const char *message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "osdInterrupt.h"
|
||||
|
||||
#endif /* epicsInterrupth */
|
||||
@@ -48,7 +48,6 @@ epicsShareFunc void epicsShareAPI epicsThreadOnceOsd(
|
||||
#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 */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* RTEMS osiInterrupt.c
|
||||
* RTEMS osdInterrupt.c
|
||||
* $Id$
|
||||
* Author: W. Eric Norum
|
||||
* eric@cls.usask.ca
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <rtems.h>
|
||||
#include <rtems/error.h>
|
||||
#include "errlog.h"
|
||||
#include "osiInterrupt.h"
|
||||
#include "epicsInterrupt.h"
|
||||
#include "epicsThread.h"
|
||||
|
||||
#define INTERRUPT_CONTEXT_MESSAGE_QUEUE_COUNT 100
|
||||
@@ -18,7 +18,7 @@
|
||||
static rtems_id interruptContextMessageQueue;
|
||||
|
||||
int
|
||||
interruptLock (void)
|
||||
epicsInterruptLock (void)
|
||||
{
|
||||
rtems_interrupt_level level;
|
||||
|
||||
@@ -27,7 +27,7 @@ interruptLock (void)
|
||||
}
|
||||
|
||||
void
|
||||
interruptUnlock (int key)
|
||||
epicsInterruptUnlock (int key)
|
||||
{
|
||||
rtems_interrupt_level level = key;
|
||||
|
||||
@@ -35,7 +35,7 @@ interruptUnlock (int key)
|
||||
}
|
||||
|
||||
int
|
||||
interruptIsInterruptContext (void)
|
||||
epicsInterruptIsInterruptContext (void)
|
||||
{
|
||||
return rtems_interrupt_is_in_progress ();
|
||||
}
|
||||
@@ -47,7 +47,7 @@ interruptIsInterruptContext (void)
|
||||
* interrupt context is no longer active.
|
||||
*/
|
||||
void
|
||||
interruptContextMessage (const char *message)
|
||||
epicsInterruptContextMessage (const char *message)
|
||||
{
|
||||
rtems_message_queue_send (interruptContextMessageQueue, &message, sizeof message);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "errlog.h"
|
||||
#include "epicsMutex.h"
|
||||
#include "epicsThread.h"
|
||||
#include "osiInterrupt.h"
|
||||
#include "cantProceed.h"
|
||||
|
||||
/*
|
||||
@@ -221,7 +220,7 @@ setThreadInfo (rtems_id tid, const char *name, EPICSTHREADFUNC funptr,void *parm
|
||||
* it must be called before epicsThreadCreate creates
|
||||
* any new threads.
|
||||
*/
|
||||
void
|
||||
static void
|
||||
epicsThreadInit (void)
|
||||
{
|
||||
if (!initialized) {
|
||||
|
||||
@@ -85,69 +85,6 @@ epicsShareFunc void epicsShareAPI epicsThreadExitMain (void)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* epicsThreadInit ()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI epicsThreadInit (void)
|
||||
{
|
||||
HANDLE win32ThreadGlobalMutexTmp;
|
||||
DWORD status;
|
||||
BOOL success;
|
||||
int crtlStatus;
|
||||
|
||||
if (win32ThreadGlobalMutex) {
|
||||
/* wait for init to complete */
|
||||
status = WaitForSingleObject (win32ThreadGlobalMutex, INFINITE);
|
||||
assert ( status == WAIT_OBJECT_0 );
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
win32ThreadGlobalMutexTmp = CreateMutex (NULL, TRUE, NULL);
|
||||
if ( win32ThreadGlobalMutexTmp == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if 1
|
||||
/* not arch neutral, but at least supported by w95 and borland */
|
||||
if ( InterlockedExchange ( (LPLONG) &win32ThreadGlobalMutex, (LONG) win32ThreadGlobalMutexTmp ) ) {
|
||||
#else
|
||||
/* not supported on W95, but the alternative requires assuming that pointer and integer are the same */
|
||||
if (InterlockedCompareExchange ( (PVOID *) &win32ThreadGlobalMutex, (PVOID) win32ThreadGlobalMutexTmp, (PVOID)0 ) != 0) {
|
||||
#endif
|
||||
CloseHandle (win32ThreadGlobalMutexTmp);
|
||||
/* wait for init to complete */
|
||||
status = WaitForSingleObject (win32ThreadGlobalMutex, INFINITE);
|
||||
assert ( status == WAIT_OBJECT_0 );
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (tlsIndexWIN32==0xFFFFFFFF) {
|
||||
tlsIndexWIN32 = TlsAlloc();
|
||||
if (tlsIndexWIN32==0xFFFFFFFF) {
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
crtlStatus = atexit (threadCleanupWIN32);
|
||||
if (crtlStatus) {
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
return;
|
||||
}
|
||||
|
||||
win32ThreadInitOK = TRUE;
|
||||
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
}
|
||||
|
||||
/*
|
||||
* osdPriorityMagFromPriorityOSI ()
|
||||
*/
|
||||
@@ -302,6 +239,69 @@ static unsigned WINAPI epicsWin32ThreadEntry (LPVOID lpParameter)
|
||||
return ( (unsigned) stat ); /* this indirectly closes the thread handle */
|
||||
}
|
||||
|
||||
/*
|
||||
* epicsThreadInit ()
|
||||
*/
|
||||
static void epicsThreadInit (void)
|
||||
{
|
||||
HANDLE win32ThreadGlobalMutexTmp;
|
||||
DWORD status;
|
||||
BOOL success;
|
||||
int crtlStatus;
|
||||
|
||||
if (win32ThreadGlobalMutex) {
|
||||
/* wait for init to complete */
|
||||
status = WaitForSingleObject (win32ThreadGlobalMutex, INFINITE);
|
||||
assert ( status == WAIT_OBJECT_0 );
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
win32ThreadGlobalMutexTmp = CreateMutex (NULL, TRUE, NULL);
|
||||
if ( win32ThreadGlobalMutexTmp == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if 1
|
||||
/* not arch neutral, but at least supported by w95 and borland */
|
||||
if ( InterlockedExchange ( (LPLONG) &win32ThreadGlobalMutex, (LONG) win32ThreadGlobalMutexTmp ) ) {
|
||||
#else
|
||||
/* not supported on W95, but the alternative requires assuming that pointer and integer are the same */
|
||||
if (InterlockedCompareExchange ( (PVOID *) &win32ThreadGlobalMutex, (PVOID) win32ThreadGlobalMutexTmp, (PVOID)0 ) != 0) {
|
||||
#endif
|
||||
CloseHandle (win32ThreadGlobalMutexTmp);
|
||||
/* wait for init to complete */
|
||||
status = WaitForSingleObject (win32ThreadGlobalMutex, INFINITE);
|
||||
assert ( status == WAIT_OBJECT_0 );
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (tlsIndexWIN32==0xFFFFFFFF) {
|
||||
tlsIndexWIN32 = TlsAlloc();
|
||||
if (tlsIndexWIN32==0xFFFFFFFF) {
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
crtlStatus = atexit (threadCleanupWIN32);
|
||||
if (crtlStatus) {
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
return;
|
||||
}
|
||||
|
||||
win32ThreadInitOK = TRUE;
|
||||
|
||||
success = ReleaseMutex (win32ThreadGlobalMutex);
|
||||
assert (success);
|
||||
}
|
||||
|
||||
/*
|
||||
* epicsThreadCreate ()
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* osi/osiInterrupt.c */
|
||||
/* osi/default/osdInterrupt.c */
|
||||
|
||||
/* Author: Marty Kraimer Date: 15JUL99 */
|
||||
|
||||
@@ -20,12 +20,12 @@ of this distribution.
|
||||
#include "epicsMutex.h"
|
||||
#include "cantProceed.h"
|
||||
#include "errlog.h"
|
||||
#include "osiInterrupt.h"
|
||||
#include "epicsInterrupt.h"
|
||||
|
||||
static epicsMutexId globalLock=0;
|
||||
static int firstTime = 1;
|
||||
|
||||
epicsShareFunc int epicsShareAPI interruptLock()
|
||||
epicsShareFunc int epicsShareAPI epicsInterruptLock()
|
||||
{
|
||||
if(firstTime) {
|
||||
globalLock = epicsMutexMustCreate();
|
||||
@@ -35,15 +35,16 @@ epicsShareFunc int epicsShareAPI interruptLock()
|
||||
return(0);
|
||||
}
|
||||
|
||||
epicsShareFunc void epicsShareAPI interruptUnlock(int key)
|
||||
epicsShareFunc void epicsShareAPI epicsInterruptUnlock(int key)
|
||||
{
|
||||
if(firstTime) cantProceed("interruptUnlock called before interruptLock\n");
|
||||
if(firstTime) cantProceed(
|
||||
"epicsInterruptUnlock called before epicsInterruptLock\n");
|
||||
epicsMutexUnlock(globalLock);
|
||||
}
|
||||
|
||||
epicsShareFunc int epicsShareAPI interruptIsInterruptContext() { return(0);}
|
||||
epicsShareFunc int epicsShareAPI epicsInterruptIsInterruptContext() { return(0);}
|
||||
|
||||
epicsShareFunc void epicsShareAPI interruptContextMessage(const char *message)
|
||||
epicsShareFunc void epicsShareAPI epicsInterruptContextMessage(const char *message)
|
||||
{
|
||||
errlogPrintf("%s",message);
|
||||
}
|
||||
|
||||
@@ -258,6 +258,15 @@ static void * start_routine(void *arg)
|
||||
free_threadInfo(pthreadInfo);
|
||||
return(0);
|
||||
}
|
||||
|
||||
static void epicsThreadInit(void)
|
||||
{
|
||||
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
||||
int status = pthread_once(&once_control,once);
|
||||
epicsThreadInitCalled = 1;
|
||||
checkStatusQuit(status,"pthread_once","epicsThreadInit");
|
||||
}
|
||||
|
||||
|
||||
#if CPU_FAMILY == MC680X0
|
||||
#define ARCH_STACK_FACTOR 1
|
||||
@@ -290,14 +299,6 @@ unsigned int epicsThreadGetStackSize (epicsThreadStackSizeClass stackSizeClass)
|
||||
#endif /*_POSIX_THREAD_ATTR_STACKSIZE*/
|
||||
}
|
||||
|
||||
void epicsThreadInit(void)
|
||||
{
|
||||
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
|
||||
int status = pthread_once(&once_control,once);
|
||||
epicsThreadInitCalled = 1;
|
||||
checkStatusQuit(status,"pthread_once","epicsThreadInit");
|
||||
}
|
||||
|
||||
/* epicsThreadOnce is a macro that calls epicsThreadOnceOsd */
|
||||
void epicsThreadOnceOsd(epicsThreadOnceId *id, void (*func)(void *), void *arg)
|
||||
{
|
||||
|
||||
@@ -12,15 +12,15 @@ of this distribution.
|
||||
#include <intLib.h>
|
||||
#include <logLib.h>
|
||||
|
||||
#include "osiInterrupt.h"
|
||||
#include "epicsInterrupt.h"
|
||||
|
||||
int interruptLock() {return(intLock());}
|
||||
int epicsInterruptLock() {return(intLock());}
|
||||
|
||||
void interruptUnlock(int key) {intUnlock(key);}
|
||||
void epicsInterruptUnlock(int key) {intUnlock(key);}
|
||||
|
||||
int interruptIsInterruptContext() {return(intContext());}
|
||||
int epicsInterruptIsInterruptContext() {return(intContext());}
|
||||
|
||||
void interruptContextMessage(const char *message)
|
||||
void epicsInterruptContextMessage(const char *message)
|
||||
{
|
||||
logMsg((char *)message,0,0,0,0,0,0);
|
||||
}
|
||||
|
||||
@@ -73,6 +73,20 @@ static int getOssPriorityValue(unsigned int osiPriority)
|
||||
}
|
||||
}
|
||||
|
||||
static void epicsThreadInit(void)
|
||||
{
|
||||
static int lock = 0;
|
||||
|
||||
while(!vxTas(&lock)) taskDelay(1);
|
||||
if(epicsThreadOnceMutex==0) {
|
||||
epicsThreadOnceMutex = semMCreate(
|
||||
SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY);
|
||||
assert(epicsThreadOnceMutex);
|
||||
}
|
||||
lock = 0;
|
||||
iocClockInit();
|
||||
}
|
||||
|
||||
unsigned int epicsThreadGetStackSize (epicsThreadStackSizeClass stackSizeClass)
|
||||
{
|
||||
|
||||
@@ -89,20 +103,6 @@ unsigned int epicsThreadGetStackSize (epicsThreadStackSizeClass stackSizeClass)
|
||||
return stackSizeTable[stackSizeClass];
|
||||
}
|
||||
|
||||
void epicsThreadInit(void)
|
||||
{
|
||||
static int lock = 0;
|
||||
|
||||
while(!vxTas(&lock)) taskDelay(1);
|
||||
if(epicsThreadOnceMutex==0) {
|
||||
epicsThreadOnceMutex = semMCreate(
|
||||
SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY);
|
||||
assert(epicsThreadOnceMutex);
|
||||
}
|
||||
lock = 0;
|
||||
iocClockInit();
|
||||
}
|
||||
|
||||
void epicsThreadOnceOsd(epicsThreadOnceId *id, void (*func)(void *), void *arg)
|
||||
{
|
||||
epicsThreadInit();
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef osiInterrupth
|
||||
#define osiInterrupth
|
||||
|
||||
/*THIS MAY BE A BIG PROBLEM */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "shareLib.h"
|
||||
|
||||
epicsShareFunc int epicsShareAPI interruptLock(void);
|
||||
epicsShareFunc void epicsShareAPI interruptUnlock(int key);
|
||||
epicsShareFunc int epicsShareAPI interruptIsInterruptContext(void);
|
||||
epicsShareFunc void epicsShareAPI interruptContextMessage(const char *message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "osdInterrupt.h"
|
||||
|
||||
#endif /* osiInterrupth */
|
||||
Reference in New Issue
Block a user