Changeset 1487:827c5e2990c9


Ignore:
Timestamp:
08/30/10 15:52:48 (18 months ago)
Author:
niam
Branch:
default
Message:

[pc::execution::scheduler] exploit pc::notification

Location:
sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sources/include/libdodo/pcExecutionScheduler.h

    r1474 r1487  
    3838    namespace pc { 
    3939        namespace sync { 
    40             class protector; 
     40            class thread; 
    4141        }; 
    4242 
    43         struct __manager__; 
     43        namespace notification { 
     44            class thread; 
     45        }; 
    4446 
    4547        namespace execution { 
     
    103105                unsigned long counter;              ///< job id counter 
    104106 
    105                 sync::protector *keeper;            ///< section locker 
     107                sync::thread *keeper;            ///< section locker 
    106108                execution::thread *thread; 
    107109 
    108                 __manager__ *handle; ///< schedule manager handle 
     110                notification::thread *notification; ///< thread wake handler 
     111 
     112                bool closing;                   ///< closing flag 
    109113            }; 
    110114        }; 
  • sources/include/libdodo/pcExecutionSchedulerEx.h

    r1439 r1487  
    5454             */ 
    5555            enum schedulerFunctionsID { 
    56                 SCHEDULEREX___MANAGER__CONSTRUCTOR, 
    5756                SCHEDULEREX_CONSTRUCTOR, 
    5857                SCHEDULEREX_SCHEDULE, 
  • sources/src/pcExecutionScheduler.cc

    r1478 r1487  
    3030#include <libdodo/directives.h> 
    3131 
    32 #ifdef PTHREAD_EXT 
    33 #include <pthread.h> 
    34 #endif 
    35 #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 information 
    44              */ 
    45             struct __manager__ { 
    46                 /** 
    47                  * contructor 
    48                  */ 
    49                 __manager__(); 
    50  
    51                 /** 
    52                  * destructor 
    53                  */ 
    54                 ~__manager__(); 
    55  
    56                 bool exit; ///< true if the scheduler thread should exit 
    57  
    58 #ifdef PTHREAD_EXT 
    59                 pthread_mutex_t     mutex;          ///< event mutex 
    60                 pthread_cond_t      condition;      ///< condition lock 
    61 #endif 
    62             }; 
    63         }; 
    64     }; 
    65 }; 
    66  
    6732#include <libdodo/pcExecutionScheduler.h> 
    6833#include <libdodo/pcExecutionSchedulerEx.h> 
     
    7035#include <libdodo/pcExecutionThread.h> 
    7136#include <libdodo/pcExecutionProcess.h> 
     37#include <libdodo/pcNotificationThread.h> 
    7238#include <libdodo/types.h> 
    7339#include <libdodo/pcSyncThread.h> 
     
    7743using namespace dodo::pc::execution; 
    7844 
    79 __manager__::__manager__() : exit(false) 
    80 { 
    81 #ifdef PTHREAD_EXT 
    82     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 #endif 
    104 } 
    105  
    106 //------------------------------------------------------------------- 
    107  
    108 __manager__::~__manager__() 
    109 { 
    110 #ifdef PTHREAD_EXT 
    111     pthread_mutex_destroy(&mutex); 
    112  
    113     pthread_cond_destroy(&condition); 
    114 #endif 
    115 } 
    116  
    117 //------------------------------------------------------------------- 
    118  
    11945scheduler::scheduler() : counter(0), 
    12046                         keeper(NULL), 
    12147                         thread(NULL), 
    122                          handle(NULL) 
     48                         notification(NULL), 
     49                         closing(false) 
    12350{ 
    12451    dodo_try { 
    12552        keeper = new pc::sync::thread; 
    126         handle = new __manager__; 
     53        notification = new pc::notification::thread(*keeper); 
    12754        thread = new execution::thread(scheduler::manager, this, execution::ON_DESTRUCTION_STOP, false); 
    12855 
     
    13057    } dodo_catch (exception::basic *e UNUSED) { 
    13158        delete thread; 
    132         delete handle; 
     59        delete notification; 
    13360        delete keeper; 
    13461 
     
    14067scheduler::~scheduler() 
    14168{ 
    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(); */ 
    15276 
    15377    delete thread; 
    154     delete handle; 
     78    delete notification; 
    15579    delete keeper; 
    15680} 
     
    16791    while (true) { 
    16892        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(); 
    18898 
    18999                return 0; 
    190100            } 
    191             pthread_mutex_unlock(&parent->handle->mutex); 
     101            parent->keeper->release(); 
    192102 
    193103            idle = 0; 
     
    199109            dodoMap<unsigned long, scheduler::__job__>::iterator i = parent->handles.begin(), j = parent->handles.end(); 
    200110            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) 
    205112                    return 0; 
    206                 } 
    207                 pthread_mutex_unlock(&parent->handle->mutex); 
    208113 
    209114                scheduler::__job__ &j = i->second; 
     
    271176    handles.insert(std::make_pair(counter, j)); 
    272177 
    273     pthread_mutex_lock(&handle->mutex); 
    274     pthread_cond_signal(&handle->condition); 
    275     pthread_mutex_unlock(&handle->mutex); 
     178    notification->notify(); 
    276179 
    277180    return counter++; 
Note: See TracChangeset for help on using the changeset viewer.