update documentation; fix bug in executor; add typedefs to thread.h
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -57,6 +57,7 @@ void Executor::run()
|
||||
xx.lock();
|
||||
}
|
||||
CommandPtr command = head;
|
||||
head = command->next;
|
||||
if(command.get()==NULL) continue;
|
||||
if(command.get()==shutdown.get()) break;
|
||||
xx.unlock();
|
||||
@@ -83,7 +84,8 @@ void Executor::execute(CommandPtr const & command)
|
||||
moreWork.signal();
|
||||
return;
|
||||
}
|
||||
if(tail.get()==NULL) return;
|
||||
CommandPtr tail = head;
|
||||
while(tail->next!=NULL) tail = tail->next;
|
||||
tail->next = command;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,10 @@ enum ThreadPriority {
|
||||
highestPriority =epicsThreadPriorityHigh
|
||||
};
|
||||
|
||||
class Thread;
|
||||
typedef std::tr1::shared_ptr<Thread> ThreadPtr;
|
||||
typedef std::tr1::shared_ptr<epicsThread> EpicsThreadPtr;
|
||||
|
||||
typedef epicsThreadRunable Runnable;
|
||||
|
||||
class Thread : public epicsThread, private NoDefaultMethods {
|
||||
@@ -62,5 +66,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}}
|
||||
#endif /* THREAD_H */
|
||||
|
||||
@@ -24,13 +24,11 @@
|
||||
#include <pv/requester.h>
|
||||
#include <pv/messageQueue.h>
|
||||
#include <pv/event.h>
|
||||
#include <pv/thread.h>
|
||||
#include <pv/executor.h>
|
||||
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
static void testBasic(FILE * fd,FILE */*auxfd*/) {
|
||||
static void testBasic(FILE * fd,FILE *auxfd) {
|
||||
int queueSize = 3;
|
||||
StringArray messages;
|
||||
messages.reserve(5);
|
||||
|
||||
@@ -18,13 +18,12 @@
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsThread.h>
|
||||
|
||||
#include <pv/lock.h>
|
||||
#include <pv/timeStamp.h>
|
||||
#include <pv/queue.h>
|
||||
#include <pv/event.h>
|
||||
#include <pv/thread.h>
|
||||
#include <pv/executor.h>
|
||||
|
||||
|
||||
using namespace epics::pvData;
|
||||
@@ -43,7 +42,7 @@ typedef Queue<Data> DataQueue;
|
||||
class Sink;
|
||||
typedef std::tr1::shared_ptr<Sink> SinkPtr;
|
||||
|
||||
class Sink : public Runnable {
|
||||
class Sink : public epicsThreadRunable {
|
||||
public:
|
||||
static SinkPtr create(DataQueue &queue,FILE *auxfd);
|
||||
Sink(DataQueue &queue,FILE *auxfd);
|
||||
@@ -59,7 +58,7 @@ private:
|
||||
Event *stopped;
|
||||
Event *waitReturn;
|
||||
Event *waitEmpty;
|
||||
Thread *thread;
|
||||
epicsThread *thread;
|
||||
};
|
||||
|
||||
SinkPtr Sink::create(DataQueue &queue,FILE *auxfd)
|
||||
@@ -75,8 +74,9 @@ Sink::Sink(DataQueue &queue,FILE *auxfd)
|
||||
stopped(new Event()),
|
||||
waitReturn(new Event()),
|
||||
waitEmpty(new Event()),
|
||||
thread(new Thread(String("sink"),middlePriority,this))
|
||||
thread(new epicsThread(*this,"sink",epicsThreadGetStackSize(epicsThreadStackSmall)))
|
||||
{
|
||||
thread->start();
|
||||
}
|
||||
|
||||
Sink::~Sink() {
|
||||
|
||||
@@ -27,8 +27,14 @@
|
||||
|
||||
using namespace epics::pvData;
|
||||
|
||||
static String actionName("action");
|
||||
|
||||
class Action;
|
||||
typedef std::tr1::shared_ptr<Action> ActionPtr;
|
||||
|
||||
class Action : public Runnable {
|
||||
public:
|
||||
virtual ~Action() {}
|
||||
FILE *out;
|
||||
bool actuallyRan;
|
||||
Event begin, end;
|
||||
@@ -42,30 +48,45 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::tr1::shared_ptr<Thread> ThreadPtr;
|
||||
static void testThreadRun(FILE *fd) {
|
||||
// show that we can control thread start and stop
|
||||
Action ax(fd);
|
||||
ActionPtr ax(new Action(fd));
|
||||
{
|
||||
Thread tr("Action", lowPriority, &ax);
|
||||
bool w=ax.begin.wait();
|
||||
ThreadPtr tr(new Thread(actionName,lowPriority,ax.get()));
|
||||
bool w=ax->begin.wait();
|
||||
fprintf(fd, "main %s\n", w?"true":"false");
|
||||
fprintf(fd, "Action is %s\n", ax.actuallyRan?"true":"false");
|
||||
ax.end.signal();
|
||||
fprintf(fd, "Action is %s\n", ax->actuallyRan?"true":"false");
|
||||
ax->end.signal();
|
||||
}
|
||||
fprintf(fd, "Action is %s\n", ax.actuallyRan?"true":"false");
|
||||
fprintf(fd, "Action is %s\n", ax->actuallyRan?"true":"false");
|
||||
fprintf(fd,"testThreadRun PASSED\n");
|
||||
}
|
||||
|
||||
class Basic;
|
||||
typedef std::tr1::shared_ptr<Basic> BasicPtr;
|
||||
|
||||
class Basic :
|
||||
public Command,
|
||||
public std::tr1::enable_shared_from_this<Basic>
|
||||
{
|
||||
public:
|
||||
POINTER_DEFINITIONS(Basic);
|
||||
Basic(ExecutorPtr const &executor);
|
||||
~Basic();
|
||||
void run();
|
||||
virtual void command();
|
||||
Basic(ExecutorPtr const &executor)
|
||||
: executor(executor) {}
|
||||
~Basic()
|
||||
{
|
||||
}
|
||||
void run()
|
||||
{
|
||||
executor->execute(getPtrSelf());
|
||||
bool result = wait.wait();
|
||||
if(result==false) printf("basic::run wait returned false\n");
|
||||
}
|
||||
virtual void command()
|
||||
{
|
||||
wait.signal();
|
||||
}
|
||||
private:
|
||||
Basic::shared_pointer getPtrSelf()
|
||||
{
|
||||
@@ -77,29 +98,8 @@ private:
|
||||
|
||||
typedef std::tr1::shared_ptr<Basic> BasicPtr;
|
||||
|
||||
Basic::Basic(ExecutorPtr const &executor)
|
||||
: executor(executor)
|
||||
{
|
||||
}
|
||||
|
||||
Basic::~Basic() {
|
||||
}
|
||||
|
||||
void Basic::run()
|
||||
{
|
||||
executor->execute(getPtrSelf());
|
||||
bool result = wait.wait();
|
||||
if(result==false) printf("basic::run wait returned false\n");
|
||||
}
|
||||
|
||||
void Basic::command()
|
||||
{
|
||||
wait.signal();
|
||||
}
|
||||
|
||||
|
||||
static void testBasic(FILE *fd) {
|
||||
ExecutorPtr executor( new Executor(String("basic"),middlePriority));
|
||||
ExecutorPtr executor(new Executor(String("basic"),middlePriority));
|
||||
BasicPtr basic( new Basic(executor));
|
||||
basic->run();
|
||||
fprintf(fd,"testBasic PASSED\n");
|
||||
@@ -125,6 +125,8 @@ void MyFunc::function()
|
||||
|
||||
typedef std::tr1::shared_ptr<MyFunc> MyFuncPtr;
|
||||
|
||||
#ifdef TESTTHREADCONTEXT
|
||||
|
||||
static void testThreadContext(FILE *fd,FILE *auxFd) {
|
||||
ExecutorPtr executor(new Executor(String("basic"),middlePriority));
|
||||
BasicPtr basic(new Basic(executor));
|
||||
@@ -135,6 +137,7 @@ static void testThreadContext(FILE *fd,FILE *auxFd) {
|
||||
fprintf(auxFd,"time per call %f microseconds\n",perCall);
|
||||
fprintf(fd,"testThreadContext PASSED\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *fileName = 0;
|
||||
@@ -151,7 +154,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
testThreadRun(fd);
|
||||
testBasic(fd);
|
||||
#ifdef TESTTHREADCONTEXT
|
||||
testThreadContext(fd,auxFd);
|
||||
epicsExitCallAtExits();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/requester.h>
|
||||
#include <pv/executor.h>
|
||||
#include <pv/pvIntrospect.h>
|
||||
#include <pv/pvData.h>
|
||||
#include <pv/standardField.h>
|
||||
|
||||
Reference in New Issue
Block a user