Changeset 1415:fb86a04acfb0
- Timestamp:
- 11/21/09 09:55:49 (2 years ago)
- Branch:
- default
- Location:
- sources
- Files:
-
- 11 edited
- 1 moved
-
examples/io_network.pc_thread/test.cc (modified) (2 diffs)
-
examples/io_pipe.io_file_fifo.pc_thread/test.cc (modified) (1 diff)
-
examples/pc_job/test.cc (modified) (5 diffs)
-
examples/pc_process/test.cc (modified) (1 diff)
-
examples/pc_thread/test.cc (modified) (2 diffs)
-
include/libdodo/pcExecutionJob.h (modified) (3 diffs)
-
include/libdodo/pcExecutionManager.h (modified) (4 diffs)
-
include/libdodo/pcExecutionManagerEx.h (modified) (3 diffs)
-
src/pcExecutionJob.cc (modified) (1 diff)
-
src/pcExecutionManager.cc (moved) (moved from sources/include/libdodo/pcExecutionManager.inline) (10 diffs)
-
src/pcExecutionProcess.cc (modified) (2 diffs)
-
src/pcExecutionThread.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sources/examples/io_network.pc_thread/test.cc
r1406 r1415 96 96 bool exit_condition(false); 97 97 98 execution::manager <execution::thread>manager;98 execution::manager manager; 99 99 100 100 ::data.set((void *)&exit_condition); … … 108 108 109 109 exchange *ex = new exchange(accepted); 110 execution::thread t(::process, (void *)ex, execution::ON_DESTRUCTION_KEEP_ALIVE); 111 t.run(); 112 manager.add(t); 110 manager.run(manager.add(execution::thread(::process, (void *)ex, execution::ON_DESTRUCTION_KEEP_ALIVE))); 113 111 114 112 try { -
sources/examples/io_pipe.io_file_fifo.pc_thread/test.cc
r1406 r1415 84 84 { 85 85 try { 86 manager <thread>threads;86 manager threads; 87 87 88 88 cout << "\n~~using one pipe for the thread~~\n"; -
sources/examples/pc_job/test.cc
r1410 r1415 32 32 cout << endl << ">>" << (char *)data << ": " << tools::time::millinow() << endl; 33 33 34 tools::os::sleep( 2);34 tools::os::sleep(tools::string::stringToUL((char *)data)); 35 35 36 36 cout << endl << "<<" << (char *)data << ": " << tools::time::millinow() << endl; … … 58 58 scheduler.schedule(&oneshot1, 3000); 59 59 60 execution:: job *jobs[amount];60 execution::manager manager; 61 61 62 62 dodoString ids[amount]; 63 int pos[amount]; 63 64 for (int i = 0; i < amount; ++i) { 64 65 ids[i] = tools::string::lToString(i); 65 if (i % 2 == 0) 66 jobs[i] = new execution::thread(::job1, (void *)ids[i].c_str(), execution::ON_DESTRUCTION_STOP); 67 else 68 jobs[i] = new execution::process(::job1, (void *)ids[i].c_str(), execution::ON_DESTRUCTION_STOP); 66 if (i % 2 == 0) { 67 pos[i] = manager.add(execution::thread(::job1, (void *)ids[i].c_str(), execution::ON_DESTRUCTION_STOP)); 68 cout << "Job #"<< pos[i] << " is a thread" << endl; 69 } else { 70 pos[i] = manager.add(execution::process(::job1, (void *)ids[i].c_str(), execution::ON_DESTRUCTION_STOP)); 71 cout << "Job #"<< pos[i] << " is a process" << endl; 72 } 69 73 } 70 74 … … 73 77 74 78 for (int i = 0; i < amount; ++i) 75 jobs[i]->run(); 79 manager.run(pos[i]); 80 81 for (int i = 0; i < amount; ++i) 82 cout << "Job #"<< pos[i] << " is " << (manager.isRunning(pos[i])?"running":"not running") << endl; 76 83 77 84 cout << tools::time::millinow() << endl; … … 79 86 cout << tools::time::millinow() << endl; 80 87 scheduler.remove(pID); 88 89 for (int i = 0; i < amount; ++i) 90 cout << "Job #"<< pos[i] << " is " << (manager.isRunning(pos[i])?"running":"not running") << endl; 91 81 92 pID = scheduler.schedule(&periodic, 100, true); 82 93 cout << tools::time::millinow() << endl; … … 88 99 89 100 for (int i = 0; i < amount; ++i) 90 cout << " status: " << jobs[i]->wait() << endl;101 cout << "Job #"<< pos[i] << " is " << (manager.isRunning(pos[i])?"running":"not running") << endl; 91 102 92 103 for (int i = 0; i < amount; ++i) 93 delete jobs[i]; 104 cout << "status: " << manager.wait(pos[i]) << endl; 105 106 for (int i = 0; i < amount; ++i) 107 cout << "Job #"<< pos[i] << " is " << (manager.isRunning(pos[i])?"running":"not running") << endl; 94 108 } catch (dodo::exception::basic &ex) { 95 109 cout << (dodoString)ex << "\t" << ex.line << "\t" << ex.file << endl; -
sources/examples/pc_process/test.cc
r1406 r1415 102 102 data0.set((char *)"!test!\n"); 103 103 104 execution::manager <execution::process>manager;104 execution::manager manager; 105 105 106 106 const int amount = 10; -
sources/examples/pc_thread/test.cc
r1406 r1415 49 49 ::data.set((void *)data); 50 50 51 execution::manager <execution::thread>manager;51 execution::manager manager; 52 52 53 53 const int amount = 10; … … 70 70 71 71 for (int i = 0; i < amount; ++i) { 72 dodo::exception::basic *ex = manager.job(pos[i])->exception();72 dodo::exception::basic *ex = dynamic_cast<execution::thread *>(manager.job(pos[i]))->exception(); 73 73 if (ex) { 74 74 cout << "Thread " << i << ":\t" << (dodoString)*ex << "\t" << ex->line << "\t" << ex->file << endl; -
sources/include/libdodo/pcExecutionJob.h
r1406 r1415 38 38 namespace pc { 39 39 namespace execution { 40 class manager; 41 40 42 /** 41 43 * @typedef routine … … 59 61 */ 60 62 class job { 63 friend class manager; 64 61 65 public: 66 67 enum typeEnum { 68 TYPE_PROCESS, 69 TYPE_THREAD 70 }; 62 71 63 72 /** 64 73 * constructor 74 * @param type defines type of job[@see job::typeEnum] 65 75 */ 66 job( );76 job(short type); 67 77 68 78 /** … … 100 110 101 111 mutable bool cloned; ///< true if object was cloned 112 113 short type; ///< type of job[@see job::typeEnum] 102 114 }; 103 115 }; -
sources/include/libdodo/pcExecutionManager.h
r1410 r1415 42 42 43 43 namespace execution { 44 class job; 45 44 46 /** 45 47 * @class manager 46 48 * @brief provides interface for jobs management 47 49 */ 48 template <typename T>49 50 class manager { 50 51 public: … … 65 66 * @param job defines job for managing 66 67 */ 67 unsigned long add(const T&job);68 unsigned long add(const job &job); 68 69 69 70 /** … … 124 125 * @param id defines job identificator 125 126 */ 126 T*job(unsigned long id);127 execution::job *job(unsigned long id); 127 128 128 129 protected: 129 130 130 dodoMap<unsigned long, T> handles; ///< managed jobs131 dodoMap<unsigned long, execution::job *> handles; ///< managed jobs 131 132 132 133 unsigned long counter; ///< job id counter … … 138 139 }; 139 140 140 #include <libdodo/pcExecutionManager.inline>141 142 141 #endif -
sources/include/libdodo/pcExecutionManagerEx.h
r1406 r1415 43 43 enum managerExR { 44 44 MANAGEREX_NOTFOUND, 45 MANAGEREX_UNKNOWNJOB, 45 46 }; 46 47 … … 49 50 */ 50 51 #define PCEXECUTIONMANAGEREX_NOTFOUND_STR "Job was not found" 52 #define PCEXECUTIONMANAGEREX_UNKNOWNJOB_STR "Unknown type of job" 51 53 /** 52 54 * ID of function where exception was thrown … … 58 60 MANAGEREX_ISRUNNING, 59 61 MANAGEREX_JOB, 62 MANAGEREX_ADD, 60 63 }; 61 64 }; -
sources/src/pcExecutionJob.cc
r1406 r1415 34 34 using namespace dodo::pc::execution; 35 35 36 job::job() : cloned(false) 36 job::job(short type) : cloned(false), 37 type(type) 37 38 { 38 39 } -
sources/src/pcExecutionManager.cc
r1406 r1415 1 1 /*************************************************************************** 2 * pcExecutionManager. inline2 * pcExecutionManager.cc 3 3 * 4 4 * Sun Oct 30 2007 … … 31 31 32 32 #include <libdodo/pcExecutionManager.h> 33 #include <libdodo/pcExecutionJob.h> 34 #include <libdodo/pcExecutionThread.h> 35 #include <libdodo/pcExecutionProcess.h> 33 36 #include <libdodo/pcExecutionManagerEx.h> 34 37 #include <libdodo/types.h> … … 36 39 #include <libdodo/pcSyncStack.h> 37 40 38 template <typename T> 39 dodo::pc::execution::manager<T>::manager() : counter(0), 40 keeper(new pc::sync::thread) 41 { 42 } 43 44 //------------------------------------------------------------------- 45 46 template <typename T> 47 dodo::pc::execution::manager<T>::~manager() 48 { 41 using namespace dodo::pc::execution; 42 43 manager::manager() : counter(0), 44 keeper(new pc::sync::thread) 45 { 46 } 47 48 //------------------------------------------------------------------- 49 50 manager::~manager() 51 { 52 dodoMap<unsigned long, execution::job *>::const_iterator i = handles.begin(), j = handles.end(); 53 54 for (; i != j; ++i) 55 delete i->second; 56 49 57 delete keeper; 50 58 } … … 52 60 //------------------------------------------------------------------- 53 61 54 template <typename T>55 62 unsigned long 56 dodo::pc::execution::manager<T>::add(const T &job) 57 { 58 pc::sync::stack tg(keeper); 59 60 handles.insert(make_pair(counter, job)); 63 manager::add(const execution::job &job) 64 { 65 pc::sync::stack tg(keeper); 66 67 execution::job *j; 68 69 execution::job *orig = const_cast<execution::job *>(&job); 70 71 switch (job.type) { 72 case execution::job::TYPE_PROCESS: 73 j = new process(*dynamic_cast<process *>(orig)); 74 75 break; 76 77 case execution::job::TYPE_THREAD: 78 j = new thread(*dynamic_cast<thread *>(orig)); 79 80 break; 81 82 default: 83 throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_RUN, exception::ERRNO_LIBDODO, MANAGEREX_UNKNOWNJOB, PCEXECUTIONMANAGEREX_UNKNOWNJOB_STR, __LINE__, __FILE__); 84 } 85 86 handles.insert(std::make_pair(counter, j)); 61 87 62 88 return counter++; … … 65 91 //------------------------------------------------------------------- 66 92 67 template <typename T> 68 void 69 dodo::pc::execution::manager<T>::remove(unsigned long id, 70 bool terminate) 71 { 72 pc::sync::stack tg(keeper); 73 74 typename dodoMap<unsigned long, T>::iterator job = handles.find(id); 93 void 94 manager::remove(unsigned long id, 95 bool terminate) 96 { 97 pc::sync::stack tg(keeper); 98 99 dodoMap<unsigned long, execution::job *>::iterator job = handles.find(id); 75 100 76 101 if (job == handles.end()) 77 102 return; 78 103 79 if (terminate && job->second.isRunning()) 80 job->second.stop(); 104 if (terminate && job->second->isRunning()) 105 job->second->stop(); 106 107 delete job->second; 81 108 82 109 handles.erase(job); … … 85 112 //------------------------------------------------------------------- 86 113 87 template <typename T> 88 void 89 dodo::pc::execution::manager<T>::run(unsigned long id) 90 { 91 pc::sync::stack tg(keeper); 92 93 typename dodoMap<unsigned long, T>::iterator job = handles.find(id); 114 void 115 manager::run(unsigned long id) 116 { 117 pc::sync::stack tg(keeper); 118 119 dodoMap<unsigned long, execution::job *>::iterator job = handles.find(id); 94 120 95 121 if (job == handles.end()) 96 122 throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_RUN, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 97 123 98 job->second.run(); 99 } 100 101 //------------------------------------------------------------------- 102 103 template <typename T> 104 void 105 dodo::pc::execution::manager<T>::stop(unsigned long id) 106 { 107 pc::sync::stack tg(keeper); 108 109 typename dodoMap<unsigned long, T>::iterator job = handles.find(id); 124 job->second->run(); 125 } 126 127 //------------------------------------------------------------------- 128 129 void 130 manager::stop(unsigned long id) 131 { 132 pc::sync::stack tg(keeper); 133 134 dodoMap<unsigned long, execution::job *>::iterator job = handles.find(id); 110 135 111 136 if (job == handles.end()) 112 137 throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_STOP, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 113 138 114 job->second.stop(); 115 } 116 117 //------------------------------------------------------------------- 118 119 template <typename T> 120 void 121 dodo::pc::execution::manager<T>::stop() 122 { 123 pc::sync::stack tg(keeper); 124 125 typename dodoMap<unsigned long, T>::iterator i = handles.begin(), j = handles.end(); 126 127 for (; i != j; ++i) 128 i->second.stop(); 129 } 130 131 //------------------------------------------------------------------- 132 133 template <typename T> 139 job->second->stop(); 140 } 141 142 //------------------------------------------------------------------- 143 144 void 145 manager::stop() 146 { 147 pc::sync::stack tg(keeper); 148 149 dodoMap<unsigned long, execution::job *>::iterator i = handles.begin(), j = handles.end(); 150 151 for (; i != j; ++i) 152 i->second->stop(); 153 } 154 155 //------------------------------------------------------------------- 156 134 157 int 135 dodo::pc::execution::manager<T>::wait(unsigned long id)136 { 137 pc::sync::stack tg(keeper); 138 139 typename dodoMap<unsigned long, T>::iterator job = handles.find(id);158 manager::wait(unsigned long id) 159 { 160 pc::sync::stack tg(keeper); 161 162 dodoMap<unsigned long, execution::job *>::iterator job = handles.find(id); 140 163 141 164 if (job == handles.end()) 142 165 throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_WAIT, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 143 166 144 return job->second.wait(); 145 } 146 147 //------------------------------------------------------------------- 148 149 template <typename T> 150 void 151 dodo::pc::execution::manager<T>::wait() 152 { 153 pc::sync::stack tg(keeper); 154 155 typename dodoMap<unsigned long, T>::iterator i = handles.begin(), j = handles.end(); 156 157 for (; i != j; ++i) 158 i->second.wait(); 159 } 160 161 //------------------------------------------------------------------- 162 163 template <typename T> 167 return job->second->wait(); 168 } 169 170 //------------------------------------------------------------------- 171 172 void 173 manager::wait() 174 { 175 pc::sync::stack tg(keeper); 176 177 dodoMap<unsigned long, execution::job *>::iterator i = handles.begin(), j = handles.end(); 178 179 for (; i != j; ++i) 180 i->second->wait(); 181 } 182 183 //------------------------------------------------------------------- 184 164 185 bool 165 dodo::pc::execution::manager<T>::isRunning(unsigned long id) const166 { 167 pc::sync::stack tg(keeper); 168 169 typename dodoMap<unsigned long, T>::const_iterator job = handles.find(id);186 manager::isRunning(unsigned long id) const 187 { 188 pc::sync::stack tg(keeper); 189 190 dodoMap<unsigned long, execution::job *>::const_iterator job = handles.find(id); 170 191 171 192 if (job == handles.end()) 172 193 throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_ISRUNNING, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 173 194 174 return job->second.isRunning(); 175 } 176 177 //------------------------------------------------------------------- 178 179 template <typename T> 195 return job->second->isRunning(); 196 } 197 198 //------------------------------------------------------------------- 199 180 200 unsigned long 181 dodo::pc::execution::manager<T>::running() const201 manager::running() const 182 202 { 183 203 pc::sync::stack tg(keeper); … … 185 205 unsigned long jobs; 186 206 187 typename dodoMap<unsigned long, T>::const_iterator i = handles.begin(), j = handles.end();188 189 for (; i != j; ++i) 190 if (i->second .isRunning())207 dodoMap<unsigned long, execution::job *>::const_iterator i = handles.begin(), j = handles.end(); 208 209 for (; i != j; ++i) 210 if (i->second->isRunning()) 191 211 ++jobs; 192 212 … … 196 216 //------------------------------------------------------------------- 197 217 198 template <typename T>199 218 dodoList<unsigned long> 200 dodo::pc::execution::manager<T>::jobs()219 manager::jobs() 201 220 { 202 221 pc::sync::stack tg(keeper); … … 204 223 dodoList<unsigned long> jobs; 205 224 206 typename dodoMap<unsigned long, T>::const_iterator i = handles.begin(), j = handles.end();225 dodoMap<unsigned long, execution::job *>::const_iterator i = handles.begin(), j = handles.end(); 207 226 208 227 for (; i != j; ++i) … … 214 233 //------------------------------------------------------------------- 215 234 216 template <typename T> 217 T * 218 dodo::pc::execution::manager<T>::job(unsigned long id) 219 { 220 pc::sync::stack tg(keeper); 221 222 typename dodoMap<unsigned long, T>::const_iterator job = handles.find(id); 235 dodo::pc::execution::job * 236 manager::job(unsigned long id) 237 { 238 pc::sync::stack tg(keeper); 239 240 dodoMap<unsigned long, execution::job *>::const_iterator job = handles.find(id); 223 241 224 242 if (job == handles.end()) 225 243 throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_JOB, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 226 244 227 return (T *)&job->second;228 } 229 230 //------------------------------------------------------------------- 245 return job->second; 246 } 247 248 //------------------------------------------------------------------- -
sources/src/pcExecutionProcess.cc
r1406 r1415 98 98 process::process(routine func, 99 99 void *data, 100 short action) : job( ),100 short action) : job(TYPE_PROCESS), 101 101 handle(new __process__) 102 102 { … … 116 116 void *data, 117 117 void *toInit) 118 try : job( ),118 try : job(TYPE_PROCESS), 119 119 handle(NULL) 120 120 { -
sources/src/pcExecutionThread.cc
r1410 r1415 148 148 bool detached, 149 149 unsigned long stackSize) 150 try : job( ),150 try : job(TYPE_THREAD), 151 151 handle(NULL) 152 152 { … … 193 193 void *data, 194 194 void *toInit) 195 try : job( ),195 try : job(TYPE_THREAD), 196 196 handle(NULL) 197 197 {
Note: See TracChangeset
for help on using the changeset viewer.
