diff --git a/src/libCom/osi/epicsStdioRedirect.h b/src/libCom/osi/epicsStdioRedirect.h new file mode 100644 index 000000000..f335ecafc --- /dev/null +++ b/src/libCom/osi/epicsStdioRedirect.h @@ -0,0 +1,37 @@ +/* epicsStdioRedirect.h */ +/*************************************************************************\ +* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2002 The Regents of the University of California, as +* Operator of Los Alamos National Laboratory. +* EPICS BASE Versions 3.13.7 +* and higher are distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +#ifndef epicsStdioRedirecth +#define epicsStdioRedirecth + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#undef stdin +#define stdin epicsGetStdin() +#undef stdout +#define stdout epicsGetStdout() +#undef stderr +#define stderr epicsGetStderr() + +/*The following are for making printf be fprintf(stdout */ +#ifdef printf +#undef printf +#endif /*printf*/ +#define printf epicsStdoutPrintf + +#ifdef __cplusplus +} +#endif + +#endif /* epicsStdioRedirecth */ diff --git a/src/libCom/test/epicsExitTest.c b/src/libCom/test/epicsExitTest.c new file mode 100644 index 000000000..a1d01531f --- /dev/null +++ b/src/libCom/test/epicsExitTest.c @@ -0,0 +1,67 @@ +/*************************************************************************\ +* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2002 The Regents of the University of California, as +* Operator of Los Alamos National Laboratory. +* EPICS BASE Versions 3.13.7 +* and higher are distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* epicsExitTest.cpp */ + +/* Author: Marty Kraimer Date: 09JUL2004*/ + +#include +#include +#include +#include +#include +#include + +#include "epicsThread.h" +#include "epicsAssert.h" +#include "epicsEvent.h" +#include "epicsExit.h" + + +typedef struct info { + epicsEventId terminate; + epicsEventId terminated; +}info; + +static void atExit(void *pvt) +{ + info *pinfo = (info *)pvt; + epicsEventSignal(pinfo->terminate); + /*Now wait for thread to terminate*/ + epicsEventMustWait(pinfo->terminated); + epicsEventDestroy(pinfo->terminate); + epicsEventDestroy(pinfo->terminated); + free(pinfo); +} + +static void thread(void *arg) +{ + info *pinfo = (info *)arg; + + printf("thread %s starting\n", epicsThreadGetNameSelf()); + pinfo->terminate = epicsEventMustCreate(epicsEventEmpty); + pinfo->terminated = epicsEventMustCreate(epicsEventEmpty); + epicsAtExit(atExit,pinfo); + printf("thread %s waiting for atExit\n", epicsThreadGetNameSelf()); + epicsEventMustWait(pinfo->terminate); + printf("thread %s terminating\n", epicsThreadGetNameSelf()); + epicsEventSignal(pinfo->terminated); +} +void epicsExitTest(void) +{ + unsigned int stackSize; + info *pinfoA; + info *pinfoB; + + stackSize = epicsThreadGetStackSize(epicsThreadStackSmall); + pinfoA = (info *)calloc(1,sizeof(info)); + epicsThreadCreate("threadA",50,stackSize,thread,pinfoA); + pinfoB = (info *)calloc(1,sizeof(info)); + epicsThreadCreate("threadB",50,stackSize,thread,pinfoB); +} diff --git a/src/libCom/test/epicsExitTestMain.c b/src/libCom/test/epicsExitTestMain.c new file mode 100644 index 000000000..423c8db77 --- /dev/null +++ b/src/libCom/test/epicsExitTestMain.c @@ -0,0 +1,34 @@ +/*************************************************************************\ +* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2002 The Regents of the University of California, as +* Operator of Los Alamos National Laboratory. +* EPICS BASE Versions 3.13.7 +* and higher are distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* epicsExitTestMain.c */ + +/* Author: Marty Kraimer Date: 24AUG2004 */ + +#include +#include +#include +#include +#include +#include + +#include "epicsExit.h" +#include "epicsThread.h" + +void epicsExitTest(void); + + +int main(int argc,char *argv[]) +{ + epicsExitTest(); + epicsThreadSleep(1.0); + printf("main calling epicsExit\n"); + epicsExit(0); + return(0); +}