Changeset 1410:a443cf659b82


Ignore:
Timestamp:
11/08/09 09:50:50 (2 years ago)
Author:
niam
Branch:
default
Children:
1411:c4e7d7b15215, 1414:90d39a446bbc
Message:

{issue #20[resolved]} scheduler interface for pc::execution::job

Location:
sources
Files:
8 edited
3 copied

Legend:

Unmodified
Added
Removed
  • sources/examples/pc_job/test.cc

    r1406 r1410  
    1515 
    1616int 
    17 job(void *data) 
     17job0(void *data) 
    1818{ 
    1919    try { 
    20         cout << endl << (char *)data << ": " << tools::time::now() << endl; 
    21         cout.flush(); 
     20        cout << endl << (char *)data << ": " << tools::time::millinow() << endl; 
     21    } catch (dodo::exception::basic &ex)   { 
     22        cout << (dodoString)ex << "\t" << ex.line << "\t" << ex.file << endl; 
     23    } 
     24 
     25    return 10; 
     26} 
     27 
     28int 
     29job1(void *data) 
     30{ 
     31    try { 
     32        cout << endl << ">>" << (char *)data << ": " << tools::time::millinow() << endl; 
    2233 
    2334        tools::os::sleep(2); 
    2435 
    25         cout << endl << (char *)data << ": " << tools::time::now() << endl; 
    26         cout.flush(); 
     36        cout << endl << "<<" << (char *)data << ": " << tools::time::millinow() << endl; 
    2737    } catch (dodo::exception::basic &ex)   { 
    2838        cout << (dodoString)ex << "\t" << ex.line << "\t" << ex.file << endl; 
     
    3949        const int amount = 10; 
    4050 
     51        execution::thread periodic(::job0, (void *)"periodic", execution::ON_DESTRUCTION_STOP); 
     52        execution::thread oneshot0(::job0, (void *)"oneshot", execution::ON_DESTRUCTION_STOP); 
     53        execution::process oneshot1(::job0, (void *)"oneshot", execution::ON_DESTRUCTION_STOP); 
     54        execution::scheduler scheduler; 
     55 
     56        unsigned long pID = scheduler.schedule(&periodic, 1000, true); 
     57        scheduler.schedule(&oneshot0, 2000); 
     58        scheduler.schedule(&oneshot1, 3000); 
     59 
    4160        execution::job *jobs[amount]; 
    4261 
     
    4564            ids[i] = tools::string::lToString(i); 
    4665            if (i % 2 == 0) 
    47                 jobs[i] = new execution::thread(::job, (void *)ids[i].c_str(), execution::ON_DESTRUCTION_STOP); 
     66                jobs[i] = new execution::thread(::job1, (void *)ids[i].c_str(), execution::ON_DESTRUCTION_STOP); 
    4867            else 
    49                 jobs[i] = new execution::process(::job, (void *)ids[i].c_str(), execution::ON_DESTRUCTION_STOP); 
     68                jobs[i] = new execution::process(::job1, (void *)ids[i].c_str(), execution::ON_DESTRUCTION_STOP); 
    5069        } 
    5170 
    5271        cout << "Launching jobs" << endl; 
    53         cout << tools::time::now() << endl; 
    54         cout.flush(); 
     72        cout << tools::time::millinow() << endl; 
    5573 
    5674        for (int i = 0; i < amount; ++i) 
    5775            jobs[i]->run(); 
     76 
     77        cout << tools::time::millinow() << endl; 
     78        tools::os::sleep(2); 
     79        cout << tools::time::millinow() << endl; 
     80        scheduler.remove(pID); 
     81        pID = scheduler.schedule(&periodic, 100, true); 
     82        cout << tools::time::millinow() << endl; 
     83        tools::os::sleep(2); 
     84        scheduler.remove(pID); 
     85        cout << tools::time::millinow() << endl; 
     86        tools::os::sleep(2); 
     87        cout << tools::time::millinow() << endl; 
    5888 
    5989        for (int i = 0; i < amount; ++i) 
  • sources/include/libdodo/exceptionBasic.h

    r1406 r1410  
    9898            MODULE_IOEVENTMANAGER, 
    9999            MODULE_PCEXECUTIONMANAGER, 
     100            MODULE_PCEXECUTIONSCHEDULER, 
    100101            MODULE_PCEXECUTIONPROCESS, 
    101102            MODULE_PCEXECUTIONTHREAD, 
  • sources/include/libdodo/pc.h

    r1406 r1410  
    3737#include <libdodo/pcExecutionProcessEx.h> 
    3838#include <libdodo/pcExecutionManager.h> 
     39#include <libdodo/pcExecutionScheduler.h> 
     40#include <libdodo/pcExecutionSchedulerEx.h> 
    3941#include <libdodo/pcSyncDataObject.h> 
    4042#include <libdodo/pcSyncProcess.h> 
  • sources/include/libdodo/pcExecutionManager.h

    r1406 r1410  
    3434 
    3535#include <libdodo/types.h> 
    36 #include <libdodo/pcSyncStack.h> 
    3736 
    3837namespace dodo { 
    3938    namespace pc { 
     39        namespace sync { 
     40            class protector; 
     41        }; 
     42 
    4043        namespace execution { 
    4144            /** 
     
    7073                 */ 
    7174                void remove(unsigned long id, 
    72                                     bool          terminate = false); 
     75                            bool          terminate = false); 
    7376 
    7477                /** 
  • sources/include/libdodo/pcExecutionScheduler.h

    r1406 r1410  
    11/*************************************************************************** 
    2  *            pcExecutionManager.h 
     2 *            pcExecutionScheduler.h 
    33 * 
    4  *  Mon Mar 05 2007 
    5  *  Copyright  2007  Ni@m 
     4 *  Sun Nov 08 2009 
     5 *  Copyright  2009  Ni@m 
    66 *  niam.niam@gmail.com 
    77 ****************************************************************************/ 
     
    2828 */ 
    2929 
    30 #ifndef _PCEXECUTIONMANAGER_H_ 
    31 #define _PCEXECUTIONMANAGER_H_ 1 
     30#ifndef _PCEXECUTIONSCHEDULER_H_ 
     31#define _PCEXECUTIONSCHEDULER_H_ 1 
    3232 
    3333#include <libdodo/directives.h> 
    3434 
    3535#include <libdodo/types.h> 
    36 #include <libdodo/pcSyncStack.h> 
    3736 
    3837namespace dodo { 
    3938    namespace pc { 
     39        namespace sync { 
     40            class protector; 
     41        }; 
     42 
     43        struct __manager__; 
     44 
    4045        namespace execution { 
     46            class job; 
     47 
    4148            /** 
    42              * @class manager 
     49             * @class scheduler 
    4350             * @brief provides interface for jobs management 
    4451             */ 
    45             template <typename T> 
    46             class manager { 
     52            class scheduler { 
     53                friend struct __manager__; 
     54 
    4755              public: 
    4856 
     
    5058                 * constructor 
    5159                 */ 
    52                 manager(); 
     60                scheduler(); 
    5361 
    5462                /** 
    5563                 * destructor 
    5664                 */ 
    57                 ~manager(); 
     65                ~scheduler(); 
    5866 
    5967                /** 
    60                  * add a job 
     68                 * schedule a job 
    6169                 * @return job identificator 
    62                  * @param job defines job for managing 
     70                 * @param job defines job for scheduling 
     71                 * @param timeout defines timeout of job scheduling in milliseconds 
     72                 * @param repeat defines if job should be rescheduled again 
    6373                 */ 
    64                 unsigned long add(const T &job); 
     74                unsigned long schedule(execution::job *job, 
     75                                       unsigned long timeout, 
     76                                       bool repeat = false); 
    6577 
    6678                /** 
     
    7082                 */ 
    7183                void remove(unsigned long id, 
    72                                     bool          terminate = false); 
    73  
    74                 /** 
    75                  * execute job 
    76                  * @param id defines job identificator 
    77                  */ 
    78                 void run(unsigned long id); 
    79  
    80                 /** 
    81                  * stop job 
    82                  * @param id defines job identificator 
    83                  */ 
    84                 void stop(unsigned long id); 
    85  
    86                 /** 
    87                  * stop all registered jobs 
    88                  */ 
    89                 void stop(); 
    90  
    91                 /** 
    92                  * wait for job termination 
    93                  * @return status of the job 
    94                  * @param id defines job identificator 
    95                  */ 
    96                 int wait(unsigned long id); 
    97  
    98                 /** 
    99                  * wait for all registered jobs termination 
    100                  */ 
    101                 void wait(); 
    102  
    103                 /** 
    104                  * @return true if job is running 
    105                  * @param id defines job identificator 
    106                  */ 
    107                 bool isRunning(unsigned long id) const; 
    108  
    109                 /** 
    110                  * @return amount of running jobs 
    111                  */ 
    112                 unsigned long running() const; 
    113  
    114                 /** 
    115                  * @return list of jobs in object 
    116                  */ 
    117                 dodoList<unsigned long> jobs(); 
    118  
    119                 /** 
    120                  * @return job object 
    121                  * @param id defines job identificator 
    122                  */ 
    123                 T *job(unsigned long id); 
     84                            bool          terminate = false); 
    12485 
    12586              protected: 
    12687 
    127                 dodoMap<unsigned long, T> handles;  ///< managed jobs 
     88                struct __job__ { 
     89                    execution::job *job; ///< job for scheduling 
     90                    unsigned long timeout; ///< timeout for job scheduling 
     91                    unsigned long ts; ///< timestamp of last time job was executed or added 
     92                    bool repeat; ///< if the job is to be rescheduled 
     93                }; 
     94 
     95                dodoMap<unsigned long, __job__> handles;  ///< managed jobs 
    12896 
    12997                unsigned long counter;              ///< job id counter 
    13098 
    13199                sync::protector *keeper;            ///< section locker 
     100 
     101                __manager__ *manager; ///< schedule manager handle 
    132102            }; 
    133103        }; 
     
    135105}; 
    136106 
    137 #include <libdodo/pcExecutionManager.inline> 
    138  
    139107#endif 
  • sources/include/libdodo/pcExecutionSchedulerEx.h

    r1406 r1410  
    11/*************************************************************************** 
    2  *            pcExecutionManagerEx.h 
     2 *            pcExecutionSchedulerEx.h 
    33 * 
    4  *  Wed Oct 07 2009 
     4 *  Sun Nov 08 2009 
    55 *  Copyright  2009  Ni@m 
    66 *  niam.niam@gmail.com 
     
    2828 */ 
    2929 
    30 #ifndef _PCEXECUTIONMANAGEREX_H_ 
    31 #define _PCEXECUTIONMANAGEREX_H_ 1 
     30#ifndef _PCEXECUTIONSCHEDULEREX_H_ 
     31#define _PCEXECUTIONSCHEDULEREX_H_ 1 
    3232 
    3333#include <libdodo/directives.h> 
     
    3939        namespace execution { 
    4040            /** 
    41              * libdodo defined errors 
    42              */ 
    43             enum managerExR { 
    44                 MANAGEREX_NOTFOUND, 
    45             }; 
    46  
    47             /** 
    48              * libdodo defined errors explanation 
    49              */ 
    50 #define PCEXECUTIONMANAGEREX_NOTFOUND_STR    "Job was not found" 
    51             /** 
    5241             * ID of function where exception was thrown 
    5342             */ 
    54             enum managerFunctionsID { 
    55                 MANAGEREX_RUN, 
    56                 MANAGEREX_WAIT, 
    57                 MANAGEREX_STOP, 
    58                 MANAGEREX_ISRUNNING, 
    59                 MANAGEREX_JOB, 
     43            enum schedulerFunctionsID { 
     44                SCHEDULEREX___MANAGER__CONSTRUCTOR, 
     45                SCHEDULEREX_CONSTRUCTOR, 
    6046            }; 
    6147        }; 
  • sources/include/libdodo/toolsOs.h

    r1406 r1410  
    125125             */ 
    126126            struct __usage__ { 
    127                 long time;                  ///< processor time of execution in miliseconds 
     127                long time;                  ///< processor time of execution in milliseconds 
    128128                long mem;                   ///< memory usage in bytes 
    129129            }; 
  • sources/src/exceptionBasic.cc

    r1406 r1410  
    9999    false, 
    100100    false, 
     101    false, 
    101102    false 
    102103}; 
     
    150151    NULL, 
    151152    NULL, 
     153    NULL, 
    152154    NULL 
    153155}; 
     
    201203    NULL, 
    202204    NULL, 
     205    NULL, 
    203206    NULL 
    204207}; 
     
    252255    false, 
    253256    false, 
     257    false, 
    254258    false 
    255259}; 
     
    303307    NULL, 
    304308    NULL, 
     309    NULL, 
    305310    NULL 
    306311}; 
     
    309314 
    310315char basic::cookies[][32] = { 
     316    {'\0', }, 
    311317    {'\0', }, 
    312318    {'\0', }, 
  • sources/src/pcExecutionScheduler.cc

    r1406 r1410  
    11/*************************************************************************** 
    2  *            pcExecutionManager.inline 
     2 *            pcExecutionScheduler.cc 
    33 * 
    4  *  Sun Oct  30 2007 
    5  *  Copyright  2007  Ni@m 
     4 *  Sun Nov 08 2009 
     5 *  Copyright  2009  Ni@m 
    66 *  niam.niam@gmail.com 
    77 ****************************************************************************/ 
    88 
    99/* 
    10  *  This program is free software; you can redistribute it and/or modify 
     10 *  jobhis program is free software; you can redistribute it and/or modify 
    1111 *  it under the terms of the GNU Lesser General Public License version 2.1 as published by 
    1212 *  the Free Software Foundation; 
    1313 * 
    14  *  This program is distributed in the hope that it will be useful, 
    15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 *  jobhis program is distributed in the hope that it will be useful, 
     15 *  but WIjobHOUjob ANY WARRANjobY; without even the implied warranty of 
     16 *  MERCHANjobABILIjobY or FIjobNESS FOR A PARjobICULAR PURPOSE.  See the 
    1717 *  GNU Library General Public License for more details. 
    1818 * 
    1919 *  You should have received a copy of the GNU Lesser General Public License 
    2020 *  along with this program; if not, write to the Free Software 
    21  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
     21 *  Foundation, Inc., 59 jobemple Place - Suite 330, Boston, MA 02111-1307, USA. 
    2222 */ 
    2323 
     
    3030#include <libdodo/directives.h> 
    3131 
    32 #include <libdodo/pcExecutionManager.h> 
    33 #include <libdodo/pcExecutionManagerEx.h> 
     32#ifdef PTHREAD_EXT 
     33#include <pthread.h> 
     34#endif 
     35#include <errno.h> 
     36#include <string.h> 
     37 
     38namespace 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_t      thread;              ///< thread descriptor 
     60 
     61                pthread_mutex_t     mutex;          ///< event mutex 
     62                pthread_cond_t      condition;      ///< condition lock 
     63 
     64                /** 
     65                 * schedule manager 
     66                 * @return thread exit status 
     67                 * @param data defines user data 
     68                 */ 
     69                static void *manager(void *data); 
     70#endif 
     71            }; 
     72        }; 
     73    }; 
     74}; 
     75 
     76#include <libdodo/pcExecutionScheduler.h> 
     77#include <libdodo/pcExecutionSchedulerEx.h> 
     78#include <libdodo/pcExecutionJob.h> 
    3479#include <libdodo/types.h> 
    3580#include <libdodo/pcSyncThread.h> 
    3681#include <libdodo/pcSyncStack.h> 
    37  
    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 { 
     82#include <libdodo/toolsTime.h> 
     83 
     84using namespace dodo::pc::execution; 
     85 
     86__manager__::__manager__() : exit(false) 
     87#ifdef PTHREAD_EXT 
     88                           , 
     89                             thread(0) 
     90#endif 
     91{ 
     92#ifdef PTHREAD_EXT 
     93    pthread_mutexattr_t attr; 
     94 
     95    errno = pthread_mutexattr_init(&attr); 
     96    if (errno != 0) 
     97        throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     98 
     99    errno = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); 
     100    if (errno != 0) 
     101        throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     102 
     103    errno = pthread_mutex_init(&mutex, &attr); 
     104    if (errno != 0) 
     105        throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     106 
     107    errno = pthread_mutexattr_destroy(&attr); 
     108    if (errno != 0) 
     109        throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     110 
     111    errno = pthread_cond_init(&condition, NULL); 
     112    if (errno != 0) 
     113        throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX___MANAGER__CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     114#endif 
     115} 
     116 
     117//------------------------------------------------------------------- 
     118 
     119__manager__::~__manager__() 
     120{ 
     121#ifdef PTHREAD_EXT 
     122    pthread_mutex_destroy(&mutex); 
     123 
     124    pthread_cond_destroy(&condition); 
     125#endif 
     126} 
     127 
     128//------------------------------------------------------------------- 
     129 
     130#ifdef PTHREAD_EXT 
     131void * 
     132__manager__::manager(void *data) 
     133{ 
     134    scheduler *parent = (scheduler *)data; 
     135 
     136    unsigned long idle = 0; 
     137 
     138    while (true) { 
     139        if (idle != 0) { 
     140            pthread_mutex_lock(&parent->manager->mutex); 
     141            if (idle == ~0UL) { 
     142                pthread_cond_wait(&parent->manager->condition, &parent->manager->mutex); 
     143            } else { 
     144                timespec ts; 
     145 
     146                clock_gettime(CLOCK_REALTIME, &ts); 
     147                ts.tv_sec += idle/1000; 
     148                ts.tv_nsec += (idle % 1000) * 1000000; 
     149 
     150                pthread_cond_timedwait(&parent->manager->condition, &parent->manager->mutex, &ts); 
     151            } 
     152 
     153            if (parent->manager->exit) { 
     154                pthread_mutex_unlock(&parent->manager->mutex); 
     155 
     156                return NULL; 
     157            } 
     158            pthread_mutex_unlock(&parent->manager->mutex); 
     159 
     160            idle = 0; 
     161        } else { 
     162            pc::sync::stack tg(parent->keeper); 
     163 
     164            idle = ~0UL; 
     165 
     166            dodoMap<unsigned long, scheduler::__job__>::iterator i = parent->handles.begin(), j = parent->handles.end(); 
     167            while (i!=j) { 
     168                pthread_mutex_lock(&parent->manager->mutex); 
     169                if (parent->manager->exit) { 
     170                    pthread_mutex_unlock(&parent->manager->mutex); 
     171 
     172                    return NULL; 
     173                } 
     174                pthread_mutex_unlock(&parent->manager->mutex); 
     175 
     176                scheduler::__job__ &j = i->second; 
     177                unsigned long ts = tools::time::millinow(); 
     178                if (ts - j.ts >= j.timeout) { 
     179                    if (!j.job->isRunning()) { 
     180                        j.job->run(); 
     181                        if (j.repeat) { 
     182                            j.ts = ts; 
     183 
     184                            if (idle > j.timeout) 
     185                                idle = j.timeout; 
     186                        } else { 
     187                            parent->handles.erase(i++); 
     188 
     189                            continue; 
     190                        } 
     191                    } else { 
     192                        idle = 0; 
     193                    } 
     194                } else { 
     195                    ts = j.ts + j.timeout - ts; 
     196                    if (idle > ts) 
     197                        idle = ts; 
     198                } 
     199 
     200                ++i; 
     201            } 
     202        } 
     203    } 
     204 
     205    return NULL; 
     206} 
     207#endif 
     208 
     209//------------------------------------------------------------------- 
     210 
     211scheduler::scheduler() 
     212try : counter(0), 
     213      keeper(NULL), 
     214      manager(NULL) 
     215 { 
     216     keeper = new pc::sync::thread; 
     217     manager = new __manager__; 
     218 
     219#ifdef PTHREAD_EXT 
     220     errno = pthread_create(&manager->thread, NULL, __manager__::manager, this); 
     221     if (errno != 0) 
     222         throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX_CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     223#endif 
     224 } catch (...) { 
     225    delete manager; 
    49226    delete keeper; 
    50 } 
    51  
    52 //------------------------------------------------------------------- 
    53  
    54 template <typename T> 
     227 } 
     228 
     229//------------------------------------------------------------------- 
     230 
     231scheduler::~scheduler() 
     232{ 
     233#ifdef PTHREAD_EXT 
     234    pthread_mutex_lock(&manager->mutex); 
     235 
     236    manager->exit = true; 
     237 
     238    pthread_cond_signal(&manager->condition); 
     239    pthread_mutex_unlock(&manager->mutex); 
     240 
     241    pthread_join(manager->thread, NULL); 
     242#endif 
     243 
     244    delete manager; 
     245    delete keeper; 
     246} 
     247 
     248//------------------------------------------------------------------- 
     249 
    55250unsigned long 
    56 dodo::pc::execution::manager<T>::add(const T &job) 
     251scheduler::schedule(execution::job *job, 
     252                    unsigned long timeout, 
     253                    bool repeat) 
    57254{ 
    58255    pc::sync::stack tg(keeper); 
    59256 
    60     handles.insert(make_pair(counter, job)); 
     257    __job__ j = {job, timeout, tools::time::millinow(), repeat}; 
     258 
     259    handles.insert(std::make_pair(counter, j)); 
     260 
     261    pthread_mutex_lock(&manager->mutex); 
     262    pthread_cond_signal(&manager->condition); 
     263    pthread_mutex_unlock(&manager->mutex); 
    61264 
    62265    return counter++; 
     
    65268//------------------------------------------------------------------- 
    66269 
    67 template <typename T> 
    68270void 
    69 dodo::pc::execution::manager<T>::remove(unsigned long id, 
    70                                        bool          terminate) 
     271scheduler::remove(unsigned long id, 
     272                  bool          terminate) 
    71273{ 
    72274    pc::sync::stack tg(keeper); 
    73275 
    74     typename dodoMap<unsigned long, T>::iterator job = handles.find(id); 
     276    dodoMap<unsigned long, __job__>::iterator job = handles.find(id); 
    75277 
    76278    if (job == handles.end()) 
    77279        return; 
    78280 
    79     if (terminate && job->second.isRunning()) 
    80         job->second.stop(); 
     281    if (terminate && job->second.job->isRunning()) 
     282        job->second.job->stop(); 
    81283 
    82284    handles.erase(job); 
     
    84286 
    85287//------------------------------------------------------------------- 
    86  
    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); 
    94  
    95     if (job == handles.end()) 
    96         throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_RUN, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 
    97  
    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); 
    110  
    111     if (job == handles.end()) 
    112         throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_STOP, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 
    113  
    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> 
    134 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); 
    140  
    141     if (job == handles.end()) 
    142         throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_WAIT, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 
    143  
    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> 
    164 bool 
    165 dodo::pc::execution::manager<T>::isRunning(unsigned long id) const 
    166 { 
    167     pc::sync::stack tg(keeper); 
    168  
    169     typename dodoMap<unsigned long, T>::const_iterator job = handles.find(id); 
    170  
    171     if (job == handles.end()) 
    172         throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_ISRUNNING, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 
    173  
    174     return job->second.isRunning(); 
    175 } 
    176  
    177 //------------------------------------------------------------------- 
    178  
    179 template <typename T> 
    180 unsigned long 
    181 dodo::pc::execution::manager<T>::running() const 
    182 { 
    183     pc::sync::stack tg(keeper); 
    184  
    185     unsigned long jobs; 
    186  
    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()) 
    191             ++jobs; 
    192  
    193     return jobs; 
    194 } 
    195  
    196 //------------------------------------------------------------------- 
    197  
    198 template <typename T> 
    199 dodoList<unsigned long> 
    200 dodo::pc::execution::manager<T>::jobs() 
    201 { 
    202     pc::sync::stack tg(keeper); 
    203  
    204     dodoList<unsigned long> jobs; 
    205  
    206     typename dodoMap<unsigned long, T>::const_iterator i = handles.begin(), j = handles.end(); 
    207  
    208     for (; i != j; ++i) 
    209         jobs.push_back(i->first); 
    210  
    211     return jobs; 
    212 } 
    213  
    214 //------------------------------------------------------------------- 
    215  
    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); 
    223  
    224     if (job == handles.end()) 
    225         throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_JOB, exception::ERRNO_LIBDODO, MANAGEREX_NOTFOUND, PCEXECUTIONMANAGEREX_NOTFOUND_STR, __LINE__, __FILE__); 
    226  
    227     return (T *)&job->second; 
    228 } 
    229  
    230 //------------------------------------------------------------------- 
  • sources/src/pcExecutionThread.cc

    r1406 r1410  
    315315 
    316316#ifdef PTHREAD_EXT 
    317     errno = pthread_create(&(handle->thread), &handle->attr, __thread__::routine, handle); 
     317    errno = pthread_create(&handle->thread, &handle->attr, __thread__::routine, handle); 
    318318    if (errno != 0) 
    319319        throw exception::basic(exception::MODULE_PCEXECUTIONTHREAD, THREADEX_RUN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
  • sources/src/pcSyncThread.cc

    r1406 r1410  
    7171#ifdef PTHREAD_EXT 
    7272    pthread_mutexattr_t attr; 
     73 
    7374    errno = pthread_mutexattr_init(&attr); 
    7475    if (errno != 0) { 
Note: See TracChangeset for help on using the changeset viewer.