changes for osiThread=>epicsThread
This commit is contained in:
88
src/libCom/test/epicsThreadTest.cpp
Normal file
88
src/libCom/test/epicsThreadTest.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/* epicsThreadTest.cpp */
|
||||
|
||||
/* Author: Marty Kraimer Date: 26JAN2000 */
|
||||
|
||||
/********************COPYRIGHT NOTIFICATION**********************************
|
||||
This software was developed under a United States Government license
|
||||
described on the COPYRIGHT_UniversityOfChicago file included as part
|
||||
of this distribution.
|
||||
****************************************************************************/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "epicsThread.h"
|
||||
#include "errlog.h"
|
||||
|
||||
static epicsThreadPrivate<int> privateKey;
|
||||
|
||||
class myThread: public epicsThreadRunable {
|
||||
public:
|
||||
myThread(int arg,const char *name);
|
||||
virtual ~myThread();
|
||||
virtual void run();
|
||||
epicsThread thread;
|
||||
private:
|
||||
int *argvalue;
|
||||
};
|
||||
|
||||
myThread::myThread(int arg,const char *name) :
|
||||
thread(*this,name,epicsThreadGetStackSize(epicsThreadStackSmall),50+arg),
|
||||
argvalue(0)
|
||||
{
|
||||
argvalue = new int;
|
||||
*argvalue = arg;
|
||||
thread.start();
|
||||
}
|
||||
|
||||
myThread::~myThread() {delete argvalue;}
|
||||
|
||||
void myThread::run()
|
||||
{
|
||||
int myPrivate = *argvalue;
|
||||
privateKey.set(argvalue);
|
||||
errlogPrintf("threadFunc %d starting argvalue %p\n",myPrivate,argvalue);
|
||||
epicsThreadSleep(2.0);
|
||||
argvalue = privateKey.get();
|
||||
errlogPrintf("threadFunc %d stopping argvalue %p\n",myPrivate,argvalue);
|
||||
}
|
||||
|
||||
extern "C" void threadTest(int ntasks,int verbose)
|
||||
{
|
||||
myThread **papmyThread;
|
||||
int i;
|
||||
char **name;
|
||||
int startPriority,minPriority,maxPriority;
|
||||
int errVerboseSave = errVerbose;
|
||||
|
||||
errVerbose = verbose;
|
||||
errlogInit(4096);
|
||||
papmyThread = (myThread **)calloc(ntasks,sizeof(myThread *));
|
||||
name = (char **)calloc(ntasks,sizeof(char **));
|
||||
errlogPrintf("threadTest starting\n");
|
||||
for(i=0; i<ntasks; i++) {
|
||||
name[i] = (char *)calloc(10,sizeof(char));
|
||||
sprintf(name[i],"task%d",i);
|
||||
papmyThread[i] = new myThread(i,name[i]);
|
||||
errlogPrintf("threadTest created %d myThread %p\n",i,papmyThread[i]);
|
||||
startPriority = papmyThread[i]->thread.getPriority();
|
||||
papmyThread[i]->thread.setPriority(epicsThreadPriorityMin);
|
||||
minPriority = papmyThread[i]->thread.getPriority();
|
||||
papmyThread[i]->thread.setPriority(epicsThreadPriorityMax);
|
||||
maxPriority = papmyThread[i]->thread.getPriority();
|
||||
papmyThread[i]->thread.setPriority(50+i);
|
||||
if(i==0)errlogPrintf("startPriority %d minPriority %d maxPriority %d\n",
|
||||
startPriority,minPriority,maxPriority);
|
||||
}
|
||||
epicsThreadSleep(.1);
|
||||
epicsThreadShowAll(0);
|
||||
epicsThreadSleep(5.0);
|
||||
errlogPrintf("epicsThreadTest returning\n");
|
||||
epicsThreadSleep(.5);
|
||||
errVerbose = errVerboseSave;
|
||||
}
|
||||
Reference in New Issue
Block a user