From d5193b058ca06db9bda772ccdf49a8c4976c7274 Mon Sep 17 00:00:00 2001 From: Comment Date: Sun, 24 Feb 2013 23:24:18 +0000 Subject: working threading --- rotord/rotor.h | 13 ++++++------- rotord/rotord.cpp | 10 ++++++---- rotord/rotord.h | 5 ++++- 3 files changed, 16 insertions(+), 12 deletions(-) (limited to 'rotord') diff --git a/rotord/rotor.h b/rotord/rotor.h index b21673b..ac4532a 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -89,18 +89,17 @@ namespace Rotor { int num_performances; int num_clips; }; - class Render_context: public Poco::Runnable{ //Poco thread object + class Render_context: public Poco::Task{ //Poco task object //manages a 'patchbay' //high level interfaces for the wizard //and low level interface onto the graph public: - void run() { - printf("Rotor: starting thread\n"); - while (1) sleep(1); - - } - ~Render_context() { + Render_context(const std::string& name): Task(name) { + }; + void runTask() { + while (!isCancelled()) sleep(1); printf("Rotor: stopping thread\n"); + } Render_status get_status(); void cancel(); //interrupt locking process diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp index 1843c9c..cb106d0 100755 --- a/rotord/rotord.cpp +++ b/rotord/rotord.cpp @@ -145,13 +145,15 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS if (command.size()) { if (command[0]=="new") { string sID=idGen.create().toString(); - context[sID]=Rotor::Render_context(); - pool.start(context[sID]); + printf("Rotor: starting thread\n"); + manager.start(new Rotor::Render_context(sID)); content=""+sID+"\n"; } else if (command[0]=="list") { - for (std::unordered_map::iterator it = context.begin(); it != context.end(); ++it) { - content+=""+it->first+"\n"; + std::list < Poco::AutoPtr < Poco::Task > >::iterator it; + it=manager.taskList().begin(); + for (it=manager.taskList().begin();it !=manager.taskList().end();++it) { + content+=""+(*it)->name()+"\n"; } } else { diff --git a/rotord/rotord.h b/rotord/rotord.h index 472a879..b948577 100755 --- a/rotord/rotord.h +++ b/rotord/rotord.h @@ -11,6 +11,8 @@ #include "Poco/DateTimeFormat.h" #include "Poco/Exception.h" #include "Poco/ThreadPool.h" +#include "Poco/Task.h" +#include "Poco/TaskManager.h" #include "Poco/Util/ServerApplication.h" #include "Poco/Util/Option.h" #include "Poco/Util/OptionSet.h" @@ -32,6 +34,7 @@ using Poco::Timestamp; using Poco::DateTimeFormatter; using Poco::DateTimeFormat; using Poco::ThreadPool; +using Poco::TaskManager; using Poco::Util::ServerApplication; using Poco::Util::Application; using Poco::Util::Option; @@ -79,7 +82,7 @@ class RotorRequestHandlerFactory: public HTTPRequestHandlerFactory private: std::unordered_map context; Poco::UUIDGenerator idGen; - Poco::ThreadPool pool; + Poco::TaskManager manager; }; class RotorServer: public Poco::Util::ServerApplication -- cgit v1.2.3