From a239b95ca10038737e3d042e5adf034c853189f5 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 28 Dec 2017 12:12:11 -0600 Subject: [PATCH] remove previously deprecated executor.h, queue.h and timerFunction.h --- src/misc/Makefile | 5 - src/misc/executor.cpp | 103 -------------------- src/misc/pv/executor.h | 92 ------------------ src/misc/pv/queue.h | 183 ------------------------------------ src/misc/pv/timeFunction.h | 72 -------------- src/misc/timeFunction.cpp | 56 ----------- testApp/misc/Makefile | 5 - testApp/misc/testQueue.cpp | 164 -------------------------------- testApp/misc/testThread.cpp | 68 +------------- testApp/pvDataAllTests.c | 2 - 10 files changed, 1 insertion(+), 749 deletions(-) delete mode 100644 src/misc/executor.cpp delete mode 100644 src/misc/pv/executor.h delete mode 100644 src/misc/pv/queue.h delete mode 100644 src/misc/pv/timeFunction.h delete mode 100644 src/misc/timeFunction.cpp delete mode 100644 testApp/misc/testQueue.cpp diff --git a/src/misc/Makefile b/src/misc/Makefile index 48e6366..1f2986c 100644 --- a/src/misc/Makefile +++ b/src/misc/Makefile @@ -11,10 +11,7 @@ INC += pv/epicsException.h INC += pv/serializeHelper.h INC += pv/event.h INC += pv/thread.h -INC += pv/executor.h -INC += pv/timeFunction.h INC += pv/timer.h -INC += pv/queue.h INC += pv/status.h INC += pv/sharedPtr.h INC += pv/debugPtr.h @@ -32,8 +29,6 @@ LIBSRCS += bitSet.cpp LIBSRCS += epicsException.cpp LIBSRCS += serializeHelper.cpp LIBSRCS += event.cpp -LIBSRCS += executor.cpp -LIBSRCS += timeFunction.cpp LIBSRCS += timer.cpp LIBSRCS += status.cpp LIBSRCS += localStaticLock.cpp diff --git a/src/misc/executor.cpp b/src/misc/executor.cpp deleted file mode 100644 index fc9453b..0000000 --- a/src/misc/executor.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* executor.cpp */ -/* - * Copyright information and license terms for this software can be - * found in the file LICENSE that is included with the distribution - */ -/** - * @author mrk - */ -#include -#include -#include -#include -#include - -#include -#include -#include - -// Suppress deprecation warnings for the implementation -#include -#undef EPICS_DEPRECATED -#define EPICS_DEPRECATED - -#define epicsExportSharedSymbols -#include - -using std::string; - -namespace epics { namespace pvData { - -// special instance to stop the executor thread -class ExecutorShutdown : public Command { - virtual void command(); -}; - -void ExecutorShutdown::command() -{ -} - -static -std::tr1::shared_ptr shutdown(new ExecutorShutdown()); - - -Executor::Executor(string const & threadName,ThreadPriority priority) -: thread(threadName,priority,this) -{ -} - -Executor::~Executor() -{ - execute(shutdown); - stopped.wait(); - // The thread signals 'stopped' while still holding - // the lock. By taking it we wait for the run() function - // to actually return - Lock xx(mutex); - head.reset(); - tail.reset(); -} - -void Executor::run() -{ - Lock xx(mutex); - while(true) { - while(!head.get()) { - xx.unlock(); - moreWork.wait(); - xx.lock(); - } - CommandPtr command = head; - head = command->next; - if(!command.get()) continue; - if(command.get()==shutdown.get()) break; - xx.unlock(); - try { - command->command(); - }catch(std::exception& e){ - //TODO: feed into logging mechanism - fprintf(stderr, "Executor: Unhandled exception: %s",e.what()); - }catch(...){ - fprintf(stderr, "Executor: Unhandled exception"); - } - - xx.lock(); - } - stopped.signal(); -} - -void Executor::execute(CommandPtr const & command) -{ - Lock xx(mutex); - command->next.reset(); - if(!head.get()) { - head = command; - moreWork.signal(); - return; - } - CommandPtr tail = head; - while(tail->next) tail = tail->next; - tail->next = command; -} - -}} diff --git a/src/misc/pv/executor.h b/src/misc/pv/executor.h deleted file mode 100644 index 4e7f2ae..0000000 --- a/src/misc/pv/executor.h +++ /dev/null @@ -1,92 +0,0 @@ -/* executor.h */ -/* - * Copyright information and license terms for this software can be - * found in the file LICENSE that is included with the distribution - */ -/** - * @author mrk - */ -#ifndef EXECUTOR_H -#define EXECUTOR_H - -#include - -#include - -#include -#include -#include -#include -#include - -#include - -namespace epics { namespace pvData { - -class Command; -class Executor; -typedef std::tr1::shared_ptr CommandPtr; -typedef std::tr1::shared_ptr ExecutorPtr; - -/** - * @brief A command to be called by Executor - * - */ -class epicsShareClass EPICS_DEPRECATED Command { -public: - POINTER_DEFINITIONS(Command); - /** - * - * Destructor - */ - virtual ~Command(){} - /** - * - * The command that is executed. - */ - virtual void command() = 0; -private: - CommandPtr next; - friend class Executor; -}; - -/** - * @brief A class that executes commands. - * - */ -class epicsShareClass EPICS_DEPRECATED Executor : public Runnable{ -public: - POINTER_DEFINITIONS(Executor); - /** - * Constructor - * - * @param threadName name for the executor thread. - * @param priority The thread priority. - */ - Executor(std::string const & threadName,ThreadPriority priority); - /** - * Destructor - */ - ~Executor(); - /** - * - * Request to execute a command. - * @param command A shared pointer to the command instance. - */ - void execute(CommandPtr const &command); - /** - * - * The thread run method. - */ - virtual void run(); -private: - CommandPtr head; - CommandPtr tail; - epics::pvData::Mutex mutex; - epics::pvData::Event moreWork; - epics::pvData::Event stopped; - epics::pvData::Thread thread; -}; - -}} -#endif /* EXECUTOR_H */ diff --git a/src/misc/pv/queue.h b/src/misc/pv/queue.h deleted file mode 100644 index edff47f..0000000 --- a/src/misc/pv/queue.h +++ /dev/null @@ -1,183 +0,0 @@ -/* queue.h */ -/* - * Copyright information and license terms for this software can be - * found in the file LICENSE that is included with the distribution - */ -/** - * @author mrk - */ -#ifndef QUEUE_H -#define QUEUE_H - -#include -#include -#include - -#include -#include - -namespace epics { namespace pvData { - -/** - * @brief Template class for a bounded queue. - * - * An instance can make a queueElement be any class desired - * but must create a std::vector of shared_ptr to queueElements. - */ -template -class EPICS_DEPRECATED Queue -{ -public: - POINTER_DEFINITIONS(Queue); - typedef std::tr1::shared_ptr queueElementPtr; - typedef std::vector queueElementPtrArray; - /** - * Constructor - * @param elementArray The vector of shared_ptr to queue elements. - */ - Queue(queueElementPtrArray & elementArray); - /** - * Destructor - */ - virtual ~Queue(); - /** - * Clear the queue. - */ - void clear(); - /** - * get the capacity of the queue, i. e. number of queue elements, - * @return The capacity. - */ - int capacity(); - /** - * Get the number of free elements in the queue. - * @return The number. - */ - int getNumberFree(); - /** - * Get the number of used elements in the queue. - * This is the number that have been setUsed but not released. - * @return The number. - */ - int getNumberUsed(); - /** - * Get the next free element. - * @return a shared_ptr to the queue element. - * This is null if queue was full. - */ - queueElementPtr getFree(); - /** - * Set the element returned by getFree as used. - * Until this is called getUsed will not return it. - * @param element The element. It must be the element returned - * by the most recent call to getUsed. - */ - void setUsed(queueElementPtr const &element); - /** - * Get the oldest used element; - * @return a shared_ptr to the queue element. - * This is null if no used element is available.` - */ - queueElementPtr getUsed(); - /** - * Release the element obtained by the most recent call to getUsed. - * @param element The element. - */ - void releaseUsed(queueElementPtr const &element); -private: - queueElementPtrArray elements; - // TODO use size_t instead - int size; - int numberFree; - int numberUsed; - int nextGetFree; - int nextSetUsed; - int nextGetUsed; - int nextReleaseUsed; -}; - -template -Queue::Queue(std::vector &xxx) -: size(static_cast(xxx.size())), - numberFree(size), - numberUsed(0), - nextGetFree(0), - nextSetUsed(0), - nextGetUsed(0), - nextReleaseUsed(0) -{ - elements.swap(xxx); -} - -template -Queue::~Queue(){} - -template -int Queue::capacity(){return size;} - -template -int Queue::getNumberFree(){return numberFree;} - -template -int Queue::getNumberUsed(){return numberUsed;} - -template -void Queue::clear() -{ - numberFree = size; - numberUsed = 0; - nextGetFree = 0; - nextSetUsed = 0; - nextGetUsed = 0; - nextReleaseUsed = 0; -} - -template -std::tr1::shared_ptr Queue::getFree() -{ - if(numberFree==0) return queueElementPtr(); - numberFree--; - int ind = nextGetFree; - std::tr1::shared_ptr queueElement = elements[nextGetFree++]; - if(nextGetFree>=size) nextGetFree = 0; - return elements[ind]; -} - -template -void Queue::setUsed(std::tr1::shared_ptr const &element) -{ - if(element!=elements[nextSetUsed++]) { - throw std::logic_error("not correct queueElement"); - } - numberUsed++; - if(nextSetUsed>=size) nextSetUsed = 0; -} - -template -std::tr1::shared_ptr Queue::getUsed() -{ - if(numberUsed==0) return queueElementPtr(); - int ind = nextGetUsed; - std::tr1::shared_ptr queueElement = elements[nextGetUsed++]; - if(nextGetUsed>=size) nextGetUsed = 0; - return elements[ind]; -} - -template -void Queue::releaseUsed(std::tr1::shared_ptr const &element) -{ - if(element!=elements[nextReleaseUsed++]) { - throw std::logic_error( - "not queueElement returned by last call to getUsed"); - } - if(nextReleaseUsed>=size) nextReleaseUsed = 0; - numberUsed--; - numberFree++; -} - - -}} -#endif /* QUEUE_H */ - - - diff --git a/src/misc/pv/timeFunction.h b/src/misc/pv/timeFunction.h deleted file mode 100644 index 3ac6f35..0000000 --- a/src/misc/pv/timeFunction.h +++ /dev/null @@ -1,72 +0,0 @@ -/* timeFunction.h */ -/* - * Copyright information and license terms for this software can be - * found in the file LICENSE that is included with the distribution - */ -/** - * @author mrk - */ -#ifndef TIMEFUNCTION_H -#define TIMEFUNCTION_H - -#include - -#include - -#include - -namespace epics { namespace pvData { - -class TimeFunctionRequester; -class TimeFunction; -typedef std::tr1::shared_ptr TimeFunctionRequesterPtr; -typedef std::tr1::shared_ptr TimeFunctionPtr; - -/** - * @brief Class that must be implemented by timeFunction requester. - * - */ -class epicsShareClass EPICS_DEPRECATED TimeFunctionRequester { -public: - POINTER_DEFINITIONS(TimeFunctionRequester); - /** - * Destructor - */ - virtual ~TimeFunctionRequester(){} - /** - * function to be timed. - * It will get called multiple times. - */ - virtual void function() = 0; -}; - - -/** - * @brief Class for measuring time it takes to execute a function. - * - */ -class epicsShareClass EPICS_DEPRECATED TimeFunction { -public: - POINTER_DEFINITIONS(TimeFunction); - /** - * Constructor - * @param requester The class that has a function method. - */ - TimeFunction(TimeFunctionRequesterPtr const & requester); - /** - * Destructor - */ - ~TimeFunction(); - /** - * Time the function. - * @return the time in seconds to execute the function. - * Note that the function may be called many times. - */ - double timeCall(); -private: - TimeFunctionRequesterPtr requester; -}; - - -}} -#endif /* TIMEFUNCTION_H */ diff --git a/src/misc/timeFunction.cpp b/src/misc/timeFunction.cpp deleted file mode 100644 index 5a9a361..0000000 --- a/src/misc/timeFunction.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* timeFunction.cpp */ -/* - * Copyright information and license terms for this software can be - * found in the file LICENSE that is included with the distribution - */ -/** - * @author mrk - */ -#include -#include -#include -#include -#include - -#include - -// Suppress deprecation warnings for the implementation -#include -#undef EPICS_DEPRECATED -#define EPICS_DEPRECATED - -#define epicsExportSharedSymbols -#include -#include -#include - -namespace epics { namespace pvData { - -TimeFunction::TimeFunction(TimeFunctionRequesterPtr const &requester) -: requester(requester) {} - - -TimeFunction::~TimeFunction() {} - -double TimeFunction::timeCall() -{ - TimeStamp startTime; - TimeStamp endTime; - double perCall = 0.0; - long ntimes = 1; - while(true) { - startTime.getCurrent(); - for(long i=0; ifunction(); - endTime.getCurrent(); - double diff = TimeStamp::diff(endTime,startTime); - if(diff>=1.0) { - perCall = diff/(double)ntimes; - break; - } - ntimes *= 2; - } - return perCall; - -} - -}} diff --git a/testApp/misc/Makefile b/testApp/misc/Makefile index 2118b9b..2ce8143 100644 --- a/testApp/misc/Makefile +++ b/testApp/misc/Makefile @@ -59,11 +59,6 @@ testTimeStamp_SRCS += testTimeStamp.cpp testHarness_SRCS += testTimeStamp.cpp TESTS += testTimeStamp -TESTPROD_HOST += testQueue -testQueue_SRCS += testQueue.cpp -testHarness_SRCS += testQueue.cpp -TESTS += testQueue - TESTPROD_HOST += testTypeCast testTypeCast_SRCS += testTypeCast.cpp testHarness_SRCS += testTypeCast.cpp diff --git a/testApp/misc/testQueue.cpp b/testApp/misc/testQueue.cpp deleted file mode 100644 index 37c4464..0000000 --- a/testApp/misc/testQueue.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright information and license terms for this software can be - * found in the file LICENSE that is included with the distribution - */ -/* - * testQueue.cpp - * - * Created on: 2010.12 - * Author: Marty Kraimer - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include - - -using namespace epics::pvData; - -struct Data { - int a; - int b; -}; - -typedef std::tr1::shared_ptr DataPtr; -typedef std::vector DataPtrArray; - -static const int numElements = 5; -typedef Queue DataQueue; - -class Sink; -typedef std::tr1::shared_ptr SinkPtr; - -class Sink : public epicsThreadRunable { -public: - static SinkPtr create(DataQueue &queue); - Sink(DataQueue &queue); - ~Sink(); - void stop(); - void look(); - virtual void run(); -private: - DataQueue &queue; - bool isStopped; - Event *wait; - Event *stopped; - Event *waitReturn; - Event *waitEmpty; - epicsThread *thread; -}; - -SinkPtr Sink::create(DataQueue &queue) -{ - return SinkPtr(new Sink(queue)); -} - -Sink::Sink(DataQueue &queue) -: queue(queue), - isStopped(false), - wait(new Event()), - stopped(new Event()), - waitReturn(new Event()), - waitEmpty(new Event()), - thread(new epicsThread(*this,"sink",epicsThreadGetStackSize(epicsThreadStackSmall))) -{ - thread->start(); -} - -Sink::~Sink() { - delete thread; - delete waitEmpty; - delete waitReturn; - delete stopped; - delete wait; -} - -void Sink::stop() -{ - isStopped = true; - wait->signal(); - stopped->wait(); -} - -void Sink::look() -{ - wait->signal(); - waitEmpty->wait(); -} - -void Sink::run() -{ - while(!isStopped) { - wait->wait(); - if(isStopped) break; - while(true) { - DataPtr data = queue.getUsed(); - if(data.get()==NULL) { - waitEmpty->signal(); - break; - } - printf(" sink a %d b %d\n",data->a,data->b); - queue.releaseUsed(data); - } - } - stopped->signal(); -} - -static void testBasic() { - DataPtrArray dataArray; - dataArray.reserve(numElements); - for(int i=0; ia = value; - data->b = value*10; - value++; - queue.setUsed(data); - data = queue.getFree(); - } - SinkPtr sink = SinkPtr(new Sink(queue)); - queue.clear(); - while(true) { - data = queue.getFree(); - if(data.get()==NULL) break; - printf("source a %d b %d\n",data->a,data->b); - queue.setUsed(data); - } - sink->look(); - // now alternate - for(int i=0; ia,data->b); - queue.setUsed(data); - sink->look(); - } - sink->stop(); - printf("PASSED\n"); -} - - -MAIN(testQueue) -{ - testPlan(5); - testDiag("Tests queue"); - testBasic(); - return testDone(); -} - diff --git a/testApp/misc/testThread.cpp b/testApp/misc/testThread.cpp index 3e71520..f3b5fe7 100644 --- a/testApp/misc/testThread.cpp +++ b/testApp/misc/testThread.cpp @@ -23,8 +23,6 @@ #include #include -#include -#include using namespace epics::pvData; using std::string; @@ -65,49 +63,6 @@ static void testThreadRun() { testDiag("testThreadRun PASSED"); } -class Basic; -typedef std::tr1::shared_ptr BasicPtr; - -class Basic : - public Command, - public std::tr1::enable_shared_from_this -{ -public: - POINTER_DEFINITIONS(Basic); - Basic(ExecutorPtr const &executor) - : executor(executor) {} - ~Basic() - { - } - void run() - { - executor->execute(getPtrSelf()); - bool result = wait.wait(); - testOk1(result==true); - if(result==false) testDiag("basic::run wait returned false"); - } - virtual void command() - { - wait.signal(); - } -private: - Basic::shared_pointer getPtrSelf() - { - return shared_from_this(); - } - ExecutorPtr executor; - Event wait; -}; - -typedef std::tr1::shared_ptr BasicPtr; - -static void testBasic() { - ExecutorPtr executor(new Executor(string("basic"),middlePriority)); - BasicPtr basic( new Basic(executor)); - basic->run(); - testDiag("testBasic PASSED"); -} - namespace { struct fninfo { int cnt; @@ -197,26 +152,6 @@ static void testBinders() #endif } -class MyFunc : public TimeFunctionRequester { -public: - POINTER_DEFINITIONS(MyFunc); - MyFunc(BasicPtr const &basic); - virtual void function(); -private: - BasicPtr basic; -}; - -MyFunc::MyFunc(BasicPtr const &basic) - : basic(basic) - {} -void MyFunc::function() -{ - basic->run(); -} - - -typedef std::tr1::shared_ptr MyFuncPtr; - #ifdef TESTTHREADCONTEXT static void testThreadContext() { @@ -233,10 +168,9 @@ static void testThreadContext() { MAIN(testThread) { - testPlan(7); + testPlan(6); testDiag("Tests thread"); testThreadRun(); - testBasic(); testBinders(); #ifdef TESTTHREADCONTEXT testThreadContext(); diff --git a/testApp/pvDataAllTests.c b/testApp/pvDataAllTests.c index 53618f0..ca43a0b 100644 --- a/testApp/pvDataAllTests.c +++ b/testApp/pvDataAllTests.c @@ -22,7 +22,6 @@ int testBaseException(void); int testBitSet(void); int testByteBuffer(void); int testOverrunBitSet(void); -int testQueue(void); int testSerialization(void); int testSharedVector(void); int testThread(void); @@ -71,7 +70,6 @@ void pvDataAllTests(void) runTest(testBitSet); runTest(testByteBuffer); runTest(testOverrunBitSet); - runTest(testQueue); runTest(testSerialization); runTest(testSharedVector); runTest(testThread);