Changeset 1487:827c5e2990c9
- Timestamp:
- 08/30/10 15:52:48 (18 months ago)
- Branch:
- default
- Location:
- sources
- Files:
-
- 3 edited
-
include/libdodo/pcExecutionScheduler.h (modified) (2 diffs)
-
include/libdodo/pcExecutionSchedulerEx.h (modified) (1 diff)
-
src/pcExecutionScheduler.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sources/include/libdodo/pcExecutionScheduler.h
r1474 r1487 38 38 namespace pc { 39 39 namespace sync { 40 class protector;40 class thread; 41 41 }; 42 42 43 struct __manager__; 43 namespace notification { 44 class thread; 45 }; 44 46 45 47 namespace execution { … … 103 105 unsigned long counter; ///< job id counter 104 106 105 sync:: protector*keeper; ///< section locker107 sync::thread *keeper; ///< section locker 106 108 execution::thread *thread; 107 109 108 __manager__ *handle; ///< schedule manager handle 110 notification::thread *notification; ///< thread wake handler 111 112 bool closing; ///< closing flag 109 113 }; 110 114 }; -
sources/include/libdodo/pcExecutionSchedulerEx.h
r1439 r1487 54 54 */ 55 55 enum schedulerFunctionsID { 56 SCHEDULEREX___MANAGER__CONSTRUCTOR,57 56 SCHEDULEREX_CONSTRUCTOR, 58 57 SCHEDULEREX_SCHEDULE, -
sources/src/pcExecutionScheduler.cc
r1478 r1487 30 30 #include <libdodo/directives.h> 31 31 32 #ifdef PTHREAD_EXT33 #include <pthread.h>34 #endif35 #include <errno.h>36 #include <string.h>37 38 namespace dodo {39 namespace pc {40 namespace execution {41 /**42 * @struct __manager__43 * @brief defines process information44 */45 struct __manager__ {46 /**47 * contructor48 */49 __manager__();50 51 /**52 * destructor53 */54 ~__manager__();55 56 bool exit; ///< true if the scheduler thread should exit57 58 #ifdef PTHREAD_EXT59 pthread_mutex_t mutex; ///< event mutex60 pthread_cond_t condition; ///< condition lock61 #endif62 };63 };64 };65 };66 67 32 #include <libdodo/pcExecutionScheduler.h> 68 33 #include <libdodo/pcExecutionSchedulerEx.h> … … 70 35 #include <libdodo/pcExecutionThread.h> 71 36 #include <libdodo/pcExecutionProcess.h> 37 #include <libdodo/pcNotificationThread.h> 72 38 #include <libdodo/types.h> 73 39 #include <libdodo/pcSyncThread.h> … … 77 43 using namespace dodo::pc::execution; 78 44 79 __manager__::__manager__() : exit(false)80 {81 #ifdef PTHREAD_EXT82 pthread_mutexattr_t attr;83 84 errno = pthread_mutexattr_init(&attr);85 if (errno != 0)86 dodo_throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);87 88 errno = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);89 if (errno != 0)90 dodo_throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);91 92 errno = pthread_mutex_init(&mutex, &attr);93 if (errno != 0)94 dodo_throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);95 96 errno = pthread_mutexattr_destroy(&attr);97 if (errno != 0)98 dodo_throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);99 100 errno = pthread_cond_init(&condition, NULL);101 if (errno != 0)102 dodo_throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);103 #endif104 }105 106 //-------------------------------------------------------------------107 108 __manager__::~__manager__()109 {110 #ifdef PTHREAD_EXT111 pthread_mutex_destroy(&mutex);112 113 pthread_cond_destroy(&condition);114 #endif115 }116 117 //-------------------------------------------------------------------118 119 45 scheduler::scheduler() : counter(0), 120 46 keeper(NULL), 121 47 thread(NULL), 122 handle(NULL) 48 notification(NULL), 49 closing(false) 123 50 { 124 51 dodo_try { 125 52 keeper = new pc::sync::thread; 126 handle = new __manager__;53 notification = new pc::notification::thread(*keeper); 127 54 thread = new execution::thread(scheduler::manager, this, execution::ON_DESTRUCTION_STOP, false); 128 55 … … 130 57 } dodo_catch (exception::basic *e UNUSED) { 131 58 delete thread; 132 delete handle;59 delete notification; 133 60 delete keeper; 134 61 … … 140 67 scheduler::~scheduler() 141 68 { 142 #ifdef PTHREAD_EXT 143 pthread_mutex_lock(&handle->mutex); 144 145 handle->exit = true; 146 147 pthread_cond_signal(&handle->condition); 148 pthread_mutex_unlock(&handle->mutex); 149 #endif 150 151 thread->wait(); 69 keeper->acquire(); 70 closing = true; 71 keeper->release(); 72 73 notification->notify(); 74 75 /* thread->wait(); */ 152 76 153 77 delete thread; 154 delete handle;78 delete notification; 155 79 delete keeper; 156 80 } … … 167 91 while (true) { 168 92 if (idle != 0) { 169 pthread_mutex_lock(&parent->handle->mutex); 170 if (idle == ~0UL) { 171 pthread_cond_wait(&parent->handle->condition, &parent->handle->mutex); 172 } else { 173 timespec ts; 174 175 clock_gettime(CLOCK_REALTIME, &ts); 176 ts.tv_sec += idle/1000; 177 ts.tv_nsec += (idle % 1000) * 1000000; 178 if (ts.tv_nsec > 999999999) { 179 ts.tv_sec += 1; 180 ts.tv_nsec -= 999999999; 181 } 182 183 pthread_cond_timedwait(&parent->handle->condition, &parent->handle->mutex, &ts); 184 } 185 186 if (parent->handle->exit) { 187 pthread_mutex_unlock(&parent->handle->mutex); 93 parent->keeper->acquire(); 94 parent->notification->wait(idle); 95 96 if (parent->closing) { 97 parent->keeper->release(); 188 98 189 99 return 0; 190 100 } 191 p thread_mutex_unlock(&parent->handle->mutex);101 parent->keeper->release(); 192 102 193 103 idle = 0; … … 199 109 dodoMap<unsigned long, scheduler::__job__>::iterator i = parent->handles.begin(), j = parent->handles.end(); 200 110 while (i!=j) { 201 pthread_mutex_lock(&parent->handle->mutex); 202 if (parent->handle->exit) { 203 pthread_mutex_unlock(&parent->handle->mutex); 204 111 if (parent->closing) 205 112 return 0; 206 }207 pthread_mutex_unlock(&parent->handle->mutex);208 113 209 114 scheduler::__job__ &j = i->second; … … 271 176 handles.insert(std::make_pair(counter, j)); 272 177 273 pthread_mutex_lock(&handle->mutex); 274 pthread_cond_signal(&handle->condition); 275 pthread_mutex_unlock(&handle->mutex); 178 notification->notify(); 276 179 277 180 return counter++;
Note: See TracChangeset
for help on using the changeset viewer.
