Changeset 1377:907b0a6f6889


Ignore:
Timestamp:
10/20/09 22:48:09 (2 years ago)
Author:
niam
Branch:
default
Message:

reworked pc::sync subsystem

Location:
trunk
Files:
18 deleted
67 edited
2 copied
8 moved

Legend:

Unmodified
Added
Removed
  • trunk/include/libdodo/cgiFastServer.h

    r1373 r1377  
    3434 
    3535#ifdef FASTCGI_EXT 
    36 #include <libdodo/pcSyncThreadSection.h> 
     36#include <libdodo/pcSyncThread.h> 
    3737 
    3838#include <libdodo/cgiServer.h> 
     
    9292 
    9393                                /** 
    94                                  * thread that holds one queue of CGI requests 
    95                                  * @param data defines the data that will be passed to the thread 
     94                                 * thread that processes one queue of CGI requests 
     95                                 * @param data defines the data passed to the thread 
    9696                                 */ 
    97                                 static void *fastCGIThread(void *data); 
     97                                static void *thread(void *data); 
    9898 
    99                                 static pc::sync::thread::section acceptLock;    ///< accept mutex 
    100                                 static pc::sync::thread::section requestLock;   ///< request mutex 
     99                                static pc::sync::thread accept;    ///< accept lock 
     100                                static pc::sync::thread request;   ///< request lock 
    101101 
    102102                                static handler handler;                   ///< function to be called on new request 
  • trunk/include/libdodo/exceptionBasic.h

    r1374 r1377  
    100100                        MODULE_PCEXECUTIONPROCESS, 
    101101                        MODULE_PCEXECUTIONTHREAD, 
    102                         MODULE_PCSYNCTHREADDATASINGLE, 
    103                         MODULE_PCSYNCPROCESSDATASINGLE, 
    104                         MODULE_PCSYNCTHREADDATACOLLECTION, 
    105                         MODULE_PCSYNCPROCESSDATACOLLECTION, 
    106                         MODULE_PCSYNCTHREADSECTION, 
    107                         MODULE_PCSYNCPROCESSSECTION, 
     102                        MODULE_PCSYNCTHREAD, 
     103                        MODULE_PCSYNCPROCESS, 
    108104                        MODULE_GRAPHICSIMAGE, 
    109105                        MODULE_GRAPHICSTRANSFORM, 
     
    300296#endif 
    301297 
    302                         /** 
    303                          * @class syncThreadSection 
    304                          * @brief performs atomic locks using mutexes 
    305                          */ 
    306                         class syncThreadSection { 
     298                        class sync { 
    307299                          public: 
    308300 
    309301                                /** 
    310                                  * consructor 
     302                                 * @class stack 
     303                                 * @brief provides thread safe behaviour 
     304                                 * @note locked in constructor and unlocked in destructor 
     305                                 * @note no exceptions thrown 
    311306                                 */ 
    312                                 syncThreadSection(); 
    313  
    314                                 /** 
    315                                  * destructor 
    316                                  */ 
    317                                 virtual ~syncThreadSection(); 
    318  
    319                                 /** 
    320                                  * lock critical section 
    321                                  */ 
    322                                 virtual void acquire(); 
    323  
    324                                 /** 
    325                                  * unlock critical section 
    326                                  */ 
    327                                 virtual void release(); 
    328  
    329                           protected: 
    330  
    331 #ifdef PTHREAD_EXT 
    332                                 static pthread_mutex_t keeper;  ///< mutex 
    333 #endif 
    334                         }; 
    335  
    336                         static syncThreadSection keeper;    ///< lock 
    337  
    338                         /** 
    339                          * @class syncThreadStack 
    340                          * @brief provides thread safe behaviour 
    341                          * @note it locks in constructor and unlocks in destructor 
    342                          */ 
    343                         class syncThreadStack { 
    344                           public: 
    345  
    346                                 /** 
    347                                  * contructor 
    348                                  */ 
    349                                 syncThreadStack(); 
    350  
    351                                 /** 
    352                                  * destructor 
    353                                  */ 
    354                                 virtual ~syncThreadStack(); 
     307                                class stack { 
     308                                  public: 
     309 
     310                                        /** 
     311                                         * contructor 
     312                                         */ 
     313                                        stack(); 
     314 
     315                                        /** 
     316                                         * destructor 
     317                                         */ 
     318                                        virtual ~stack(); 
     319 
     320                                        void *keeper; ///< section locker 
     321                                }; 
    355322                        }; 
    356323 
  • trunk/include/libdodo/ioChannel.h

    r1373 r1377  
    4040        namespace pc { 
    4141                namespace sync { 
    42                         class section; 
     42                        class protector; 
    4343                }; 
    4444        }; 
     
    182182                        virtual void _writeString(const char * const data) const = 0; 
    183183 
    184                         pc::sync::section *keeper;                                  ///< section locker 
     184                        pc::sync::protector *keeper;                                  ///< section locker 
    185185                        short protection;                                           ///< type of IO protection, @see io::channel::protectionEnum 
    186186 
  • trunk/include/libdodo/ioEventManager.h

    r1373 r1377  
    3838        namespace pc { 
    3939                namespace sync { 
    40                         class section; 
     40                        class protector; 
    4141                }; 
    4242        }; 
     
    136136                                int descs;                                      ///< descriptors counter 
    137137 
    138                                 pc::sync::section *keeper;                      ///< section locker 
     138                                pc::sync::protector *keeper;                      ///< section locker 
    139139                        }; 
    140140                }; 
  • trunk/include/libdodo/pc.h

    r1374 r1377  
    3737#include <libdodo/pcExecutionProcessEx.h> 
    3838#include <libdodo/pcExecutionManager.h> 
    39 #include <libdodo/pcSyncDataCollection.h> 
    40 #include <libdodo/pcSyncDataSingle.h> 
    41 #include <libdodo/pcSyncProcessDataCollection.h> 
    42 #include <libdodo/pcSyncProcessDataCollectionEx.h> 
    43 #include <libdodo/pcSyncProcessDataSingle.h> 
    44 #include <libdodo/pcSyncProcessDataSingleEx.h> 
    45 #include <libdodo/pcSyncProcessSection.h> 
    46 #include <libdodo/pcSyncProcessSectionEx.h> 
     39#include <libdodo/pcSyncDataObject.h> 
     40#include <libdodo/pcSyncProcess.h> 
     41#include <libdodo/pcSyncProcessEx.h> 
     42#include <libdodo/pcSyncThread.h> 
     43#include <libdodo/pcSyncThreadEx.h> 
    4744#include <libdodo/pcSyncProtector.h> 
    48 #include <libdodo/pcSyncSection.h> 
    49 #include <libdodo/pcSyncThreadDataCollection.h> 
    50 #include <libdodo/pcSyncThreadDataCollectionEx.h> 
    51 #include <libdodo/pcSyncThreadDataSingle.h> 
    52 #include <libdodo/pcSyncThreadDataSingleEx.h> 
    53 #include <libdodo/pcSyncThreadSection.h> 
    54 #include <libdodo/pcSyncThreadSectionEx.h> 
     45#include <libdodo/pcSyncStack.h> 
    5546#endif 
  • trunk/include/libdodo/pcExecutionManager.h

    r1374 r1377  
    3434 
    3535#include <libdodo/types.h> 
    36 #include <libdodo/pcSyncSection.h> 
     36#include <libdodo/pcSyncStack.h> 
    3737 
    3838namespace dodo { 
     
    124124                                unsigned long counter; ///< job id counter 
    125125 
    126                                 sync::section *keeper; ///< section locker 
     126                                sync::protector *keeper; ///< section locker 
    127127                        }; 
    128128                }; 
  • trunk/include/libdodo/pcExecutionManager.inline

    r1375 r1377  
    3333#include <libdodo/pcExecutionManagerEx.h> 
    3434#include <libdodo/types.h> 
    35 #include <libdodo/pcSyncSection.h> 
    36 #include <libdodo/pcSyncThreadSection.h> 
    37 #include <libdodo/pcSyncProtector.h> 
     35#include <libdodo/pcSyncThread.h> 
     36#include <libdodo/pcSyncStack.h> 
    3837 
    3938template <typename T> 
    4039dodo::pc::execution::manager<T>::manager() : counter(0), 
    41                                                                                          keeper(new pc::sync::thread::section) 
     40                                                                                         keeper(new pc::sync::thread) 
    4241{ 
    4342} 
     
    5756dodo::pc::execution::manager<T>::add(const T &job) 
    5857{ 
    59         pc::sync::protector tg(keeper); 
     58        pc::sync::stack tg(keeper); 
    6059 
    6160        handles.insert(make_pair(counter, job)); 
     
    7170                                   bool          terminate) 
    7271{ 
    73         pc::sync::protector tg(keeper); 
     72        pc::sync::stack tg(keeper); 
    7473 
    7574        typename dodoMap<unsigned long, T>::iterator job = handles.find(id); 
     
    9089dodo::pc::execution::manager<T>::run(unsigned long id) 
    9190{ 
    92         pc::sync::protector tg(keeper); 
     91        pc::sync::stack tg(keeper); 
    9392 
    9493        typename dodoMap<unsigned long, T>::iterator job = handles.find(id); 
     
    106105dodo::pc::execution::manager<T>::stop(unsigned long id) 
    107106{ 
    108         pc::sync::protector tg(keeper); 
     107        pc::sync::stack tg(keeper); 
    109108 
    110109        typename dodoMap<unsigned long, T>::iterator job = handles.find(id); 
     
    122121dodo::pc::execution::manager<T>::stop() 
    123122{ 
    124         pc::sync::protector tg(keeper); 
     123        pc::sync::stack tg(keeper); 
    125124 
    126125        typename dodoMap<unsigned long, T>::iterator i = handles.begin(), j = handles.end(); 
     
    136135dodo::pc::execution::manager<T>::wait(unsigned long id) 
    137136{ 
    138         pc::sync::protector tg(keeper); 
     137        pc::sync::stack tg(keeper); 
    139138 
    140139        typename dodoMap<unsigned long, T>::iterator job = handles.find(id); 
     
    152151dodo::pc::execution::manager<T>::wait() 
    153152{ 
    154         pc::sync::protector tg(keeper); 
     153        pc::sync::stack tg(keeper); 
    155154 
    156155        typename dodoMap<unsigned long, T>::iterator i = handles.begin(), j = handles.end(); 
     
    166165dodo::pc::execution::manager<T>::isRunning(unsigned long id) const 
    167166{ 
    168         pc::sync::protector tg(keeper); 
     167        pc::sync::stack tg(keeper); 
    169168 
    170169        typename dodoMap<unsigned long, T>::const_iterator job = handles.find(id); 
     
    182181dodo::pc::execution::manager<T>::running() const 
    183182{ 
    184         pc::sync::protector tg(keeper); 
     183        pc::sync::stack tg(keeper); 
    185184 
    186185        unsigned long jobs; 
     
    201200dodo::pc::execution::manager<T>::jobs() 
    202201{ 
    203         pc::sync::protector tg(keeper); 
     202        pc::sync::stack tg(keeper); 
    204203 
    205204        dodoList<unsigned long> jobs; 
  • trunk/include/libdodo/pcSyncDataObject.h

    r1373 r1377  
    11/*************************************************************************** 
    2  *            pcSyncDataSingle.h 
     2 *            pcSyncDataObject.h 
    33 * 
    44 *  Mon Oct 22 2007 
     
    2828 */ 
    2929 
    30 #ifndef _PCSYNCDATASINGLE_H_ 
    31 #define _PCSYNCDATASINGLE_H_ 1 
     30#ifndef _PCSYNCDATAOBJECT_H_ 
     31#define _PCSYNCDATAOBJECT_H_ 1 
    3232 
    3333#include <libdodo/directives.h> 
     
    3636        namespace pc { 
    3737                namespace sync { 
     38                        class protector; 
     39 
    3840                        namespace data { 
    3941                                /** 
    40                                  * @class single 
     42                                 * @class object 
    4143                                 * @brief provides shared data management functionality 
    4244                                 */ 
    43                                 class single { 
     45                                class object { 
    4446                                  public: 
     47 
     48                                        /** 
     49                                         * constructor 
     50                                         * @param lock defines syncing primitive for the object 
     51                                         */ 
     52                                        object(protector &lock); 
    4553 
    4654                                        /** 
    4755                                         * destructor 
    4856                                         */ 
    49                                         virtual ~single() = 0; 
     57                                        virtual ~object(); 
    5058 
    5159                                        /** 
     
    5361                                         * @param data defines shared data 
    5462                                         */ 
    55                                         virtual void set(void *data) = 0; 
     63                                        virtual void set(void *data); 
    5664 
    5765                                        /** 
    58                                          * set shared data to NULL 
     66                                         * get shared data 
     67                                         * @return shared data 
     68                                         * @note shared data is not locked after the function returns 
    5969                                         */ 
    60                                         virtual void remove() = 0; 
     70                                        virtual const void *get(); 
    6171 
    6272                                        /** 
    6373                                         * lock and return shared data 
    6474                                         * @return shared data 
    65                                          * @param microseconds defines wait timeout for unlock 
    66                                          * @note if microseconds is 0 it will wait infinitely 
     75                                         * @param timeout defines wait timeout for unlock in microseconds 
     76                                         * @note if timeout is 0 it will wait infinitely 
    6777                                         */ 
    68                                         virtual void *acquire(unsigned long microseconds) = 0; 
     78                                        virtual void *acquire(unsigned long timeout = 0); 
    6979 
    7080                                        /** 
    7181                                         * unlock shared data 
    7282                                         */ 
    73                                         virtual void release() = 0; 
     83                                        virtual void release(); 
     84 
     85                                  protected: 
     86 
     87                                        void *data; ///< object data 
     88 
     89                                        protector &lock; ///< object lock 
    7490                                }; 
    7591                        }; 
  • trunk/include/libdodo/pcSyncProcess.h

    r1373 r1377  
    11/*************************************************************************** 
    2  *            pcSyncProcessDataSingle.h 
     2 *            pcSyncProcess.h 
    33 * 
    44 *  Sun Jul 22 2007 
     
    2828 */ 
    2929 
    30 #ifndef _PCSYNCPROCESSDATASINGLE_H_ 
    31 #define _PCSYNCPROCESSDATASINGLE_H_ 1 
     30#ifndef _PCSYNCPROCESS_H_ 
     31#define _PCSYNCPROCESS_H_ 1 
    3232 
    3333#include <libdodo/directives.h> 
    3434 
    35 #include <libdodo/pcSyncDataSingle.h> 
     35#include <libdodo/pcSyncProtector.h> 
    3636 
    3737namespace dodo { 
    3838        namespace pc { 
    3939                namespace sync { 
    40                         namespace process { 
     40                        /** 
     41                         * @class process 
     42                         * @brief provides lock mechanism for processes 
     43                         * @note if the key was not autogenerated the semaphore is not removed from the system 
     44                         * you should call remove to remove it from the system 
     45                         */ 
     46                        class process : public sync::protector { 
     47                          private: 
     48 
     49                                /** 
     50                                 * copy constructor 
     51                                 * @note to prevent copying 
     52                                 */ 
     53                                process(process &); 
     54 
     55                          public: 
     56 
     57                                /** 
     58                                 * constructor 
     59                                 * @param key defines semaphore key 
     60                                 * @note if key is 0 - key will be autogenerated 
     61                                 * if you want to share semaphore between different instances of process - set own key, 
     62                                 * otherwise(like fork) - it may be autogenerated 
     63                                 */ 
     64                                process(int key); 
     65 
     66                                /** 
     67                                 * destructor 
     68                                 */ 
     69                                virtual ~process(); 
     70 
     71                                /** 
     72                                 * lock 
     73                                 * @param timeout defines wait timeout for unlock in microseconds 
     74                                 * @note if timeout is 0 it will wait infinitely 
     75                                 */ 
     76                                virtual void acquire(unsigned long timeout = 0); 
     77 
     78                                /** 
     79                                 * unlock 
     80                                 */ 
     81                                virtual void release(); 
     82 
     83                                /** 
     84                                 * remove the semaphore from the system 
     85                                 * @param key defines the key of the semaphore 
     86                                 */ 
     87                                static void remove(int key); 
     88 
     89                          protected: 
     90 
     91                                /** 
     92                                 * @return true if the lock is acquired 
     93                                 */ 
     94                                virtual bool acquired(); 
     95 
    4196                                struct __lock__; 
     97                                __lock__ *lock; 
    4298 
    43                                 namespace data { 
    44                                         /** 
    45                                          * @class single 
    46                                          * @brief provides shared data management functionality for processes 
    47                                          * @note you should use data::shared 
    48                                          * @note if the key was not autogenerated the semaphore is not removed from the system 
    49                                          * you should call remove to remove it from the system 
    50                                          */ 
    51                                         class single : public sync::data::single { 
    52                                           private: 
     99                                bool autogenerated;     ///< true if key was autogenerated 
    53100 
    54                                                 /** 
    55                                                  * copy constructor 
    56                                                  * @note to prevent copying 
    57                                                  */ 
    58                                                 single(single &); 
    59  
    60                                           public: 
    61  
    62                                                 /** 
    63                                                  * constructor 
    64                                                  * @param key defines semaphore key 
    65                                                  * @note if key is 0 - key will be autogenerated 
    66                                                  * if you want to share semaphore between different instances of process - set own key, 
    67                                                  * otherwise(like fork) - it may be autogenerated 
    68                                                  */ 
    69                                                 single(int key); 
    70  
    71                                                 /** 
    72                                                  * constructor 
    73                                                  */ 
    74                                                 single(); 
    75  
    76                                                 /** 
    77                                                  * destructor 
    78                                                  */ 
    79                                                 virtual ~single(); 
    80  
    81                                                 /** 
    82                                                  * open or create semaphore object 
    83                                                  * @param key defines semaphore key 
    84                                                  * @note if key is 0 - key will be autogenerated 
    85                                                  * if you want to share semaphore between different instances of process - set own key, 
    86                                                  * otherwise(like fork) - it may be autogenerated 
    87                                                  */ 
    88                                                 virtual void open(int key); 
    89  
    90                                                 /** 
    91                                                  * close opened semaphore 
    92                                                  */ 
    93                                                 virtual void close(); 
    94  
    95                                                 /** 
    96                                                  * set shared data 
    97                                                  * @param data defines shared data 
    98                                                  */ 
    99                                                 virtual void set(void *data); 
    100  
    101                                                 /** 
    102                                                  * set shared data to NULL 
    103                                                  */ 
    104                                                 virtual void remove(); 
    105  
    106                                                 /** 
    107                                                  * lock and return shared data 
    108                                                  * @return shared data 
    109                                                  * @param microseconds defines wait timeout for unlock 
    110                                                  * @note if microseconds is 0 it will wait infinitely 
    111                                                  */ 
    112                                                 virtual void *acquire(unsigned long microseconds = 0); 
    113  
    114                                                 /** 
    115                                                  * unlock shared data 
    116                                                  */ 
    117                                                 virtual void release(); 
    118  
    119                                                 /** 
    120                                                  * remove the semaphore from the system 
    121                                                  * @param key defines the key of the semaphore 
    122                                                  */ 
    123                                                 static void remove(int key); 
    124  
    125                                           protected: 
    126  
    127                                                 void *data;             ///< shared data 
    128  
    129                                                 __lock__ *semaphore; 
    130  
    131                                                 bool autogenerated;     ///< true if key was autogenerated 
    132                                                 bool acquired;          ///< true if the semaphore was aquired 
    133                                         }; 
    134                                 }; 
     101                                int current;                    ///< current process holding section 
     102                                int recursive;                  ///< depth of accuire recursion of current process 
    135103                        }; 
    136104                }; 
  • trunk/include/libdodo/pcSyncProcessEx.h

    r1373 r1377  
    11/*************************************************************************** 
    2  *            pcSyncProcessDataSingleEx.h 
     2 *            pcSyncProcessEx.h 
    33 * 
    44 *  Sun Jul 22 2007 
     
    2828 */ 
    2929 
    30 #ifndef _PCSYNCPROCESSDATASINGLEEX_H_ 
    31 #define _PCSYNCPROCESSDATASINGLEEX_H_ 1 
     30#ifndef _PCSYNCPROCESSEX_H_ 
     31#define _PCSYNCPROCESSEX_H_ 1 
    3232 
    3333#include <libdodo/directives.h> 
     
    3838        namespace pc { 
    3939                namespace sync { 
    40                         namespace process { 
    41                                 namespace data { 
    42                                         /** 
    43                                          * libdodo defined errors 
    44                                          */ 
    45                                         enum singleExR { 
    46                                                 SINGLEEX_CANNOTLOCK, 
    47                                                 SINGLEEX_NOTOPENED, 
    48                                         }; 
     40                        /** 
     41                         * libdodo defined errors 
     42                         */ 
     43                        enum processExR { 
     44                                PROCESSEX_CANNOTLOCK, 
     45                        }; 
    4946 
    50                                         /** 
    51                                          * explanations for libdodo defined errors 
    52                                          */ 
    53 #define PCSYNCPROCESSDATASINGLEEX_CANNOTLOCK_STR      "Item is currently locked, timeout exhousted" 
    54 #define PCSYNCPROCESSDATASINGLEEX_NOTOPENED_STR      "Semaphore not opened" 
     47                        /** 
     48                         * explanations for libdodo defined errors 
     49                         */ 
     50#define PCSYNCPROCESSEX_CANNOTLOCK_STR      "Item is currently locked, timeout exhousted" 
    5551 
    56                                         /** 
    57                                          * IDs of functions where exception might be thrown 
    58                                          */ 
    59                                         enum singleFunctionsID { 
    60                                                 SINGLEEX_SET, 
    61                                                 SINGLEEX_ACQUIRE, 
    62                                                 SINGLEEX_RELEASE, 
    63                                                 SINGLEEX_REMOVE, 
    64                                                 SINGLEEX_SINGLE, 
    65                                                 SINGLEEX_OPEN, 
    66                                                 SINGLEEX_CLOSE, 
    67                                         }; 
    68                                 }; 
     52                        /** 
     53                         * IDs of functions where exception might be thrown 
     54                         */ 
     55                        enum processFunctionsID { 
     56                                PROCESSEX_ACQUIRE, 
     57                                PROCESSEX_RELEASE, 
     58                                PROCESSEX_CONSTRUCTOR, 
     59                                PROCESSEX_REMOVE, 
     60                                PROCESSEX_ACQUIRED, 
    6961                        }; 
    7062                }; 
  • trunk/include/libdodo/pcSyncProtector.h

    r1373 r1377  
    22 *            pcSyncProtector.h 
    33 * 
    4  *  Sat Oct 20 2007 
     4 *  Mon Oct 22 2007 
    55 *  Copyright  2007  Ni@m 
    66 *  niam.niam@gmail.com 
     
    3636        namespace pc { 
    3737                namespace sync { 
    38                         class section; 
    39  
    4038                        /** 
    4139                         * @class protector 
    42                          * @brief provides thread/process safe behaviour 
    43                          * @note it locks in constructor and unlocks in destructor 
     40                         * @brief provides shared data management functionality 
    4441                         */ 
    4542                        class protector { 
     
    4744 
    4845                                /** 
    49                                  * contructor 
     46                                 * destructor 
    5047                                 */ 
    51                                 protector(section *parent); 
     48                                virtual ~protector() = 0; 
    5249 
    5350                                /** 
    54                                  * destructor 
     51                                 * lock 
     52                                 * @param timeout defines wait timeout for unlock in microseconds 
     53                                 * @note if timeout is 0 it will wait infinitely 
    5554                                 */ 
    56                                 virtual ~protector(); 
     55                                virtual void acquire(unsigned long timeout) = 0; 
    5756 
    58                           protected: 
    59  
    60                                 section *keeper; ///< lock 
     57                                /** 
     58                                 * unlock 
     59                                 */ 
     60                                virtual void release() = 0; 
    6161                        }; 
    6262                }; 
     
    6464}; 
    6565#endif 
     66 
  • trunk/include/libdodo/pcSyncStack.h

    r1373 r1377  
    11/*************************************************************************** 
    2  *            pcSyncProtector.h 
     2 *            pcSyncStack.h 
    33 * 
    44 *  Sat Oct 20 2007 
     
    2828 */ 
    2929 
    30 #ifndef _PCSYNCPROTECTOR_H_ 
    31 #define _PCSYNCPROTECTOR_H_ 1 
     30#ifndef _PCSYNCSTACK_H_ 
     31#define _PCSYNCSTACK_H_ 1 
    3232 
    3333#include <libdodo/directives.h> 
     
    3636        namespace pc { 
    3737                namespace sync { 
    38                         class section; 
     38                        class protector; 
    3939 
    4040                        /** 
    41                          * @class protector 
     41                         * @class stack 
    4242                         * @brief provides thread/process safe behaviour 
    43                          * @note it locks in constructor and unlocks in destructor 
     43                         * @note locked in constructor and unlocked in destructor 
    4444                         */ 
    45                         class protector { 
     45                        class stack { 
    4646                          public: 
    4747 
     
    4949                                 * contructor 
    5050                                 */ 
    51                                 protector(section *parent); 
     51                                stack(protector *); 
    5252 
    5353                                /** 
    5454                                 * destructor 
    5555                                 */ 
    56                                 virtual ~protector(); 
     56                                virtual ~stack(); 
    5757 
    5858                          protected: 
    5959 
    60                                 section *keeper; ///< lock 
     60                                protector *keeper; ///< lock 
    6161                        }; 
    6262                }; 
  • trunk/include/libdodo/pcSyncThread.h

    r1373 r1377  
    11/*************************************************************************** 
    2  *            pcSyncThreadDataSingle.h 
     2 *            pcSyncThread.h 
    33 * 
    44 *  Tue Nov 29 2005 
     
    2828 */ 
    2929 
    30 #ifndef _PCSYNCTHREADDATASINGLE_H_ 
    31 #define _PCSYNCTHREADDATASINGLE_H_ 1 
     30#ifndef _PCSYNCTHREAD_H_ 
     31#define _PCSYNCTHREAD_H_ 1 
    3232 
    3333#include <libdodo/directives.h> 
    3434 
    35 #include <libdodo/pcSyncDataSingle.h> 
     35#include <libdodo/pcSyncProtector.h> 
    3636 
    3737namespace dodo { 
    3838        namespace pc { 
    3939                namespace sync { 
    40                         namespace thread { 
     40                        /** 
     41                         * @class thread 
     42                         * @brief provides lock mechanism for threads 
     43                         */ 
     44                        class thread : public sync::protector { 
     45                          private: 
     46 
     47                                /** 
     48                                 * copy constructor 
     49                                 * @note to prevent copying 
     50                                 */ 
     51                                thread(thread &); 
     52 
     53                          public: 
     54 
     55                                /** 
     56                                 * constructor 
     57                                 */ 
     58                                thread(); 
     59 
     60                                /** 
     61                                 * destructor 
     62                                 */ 
     63                                virtual ~thread(); 
     64 
     65                                /** 
     66                                 * lock 
     67                                 * @param timeout defines wait timeout for unlock in microseconds 
     68                                 * @note if timeout is 0 it will wait infinitely 
     69                                 */ 
     70                                virtual void acquire(unsigned long timeout = 0); 
     71 
     72                                /** 
     73                                 * unlock 
     74                                 */ 
     75                                virtual void release(); 
     76 
     77                          protected: 
     78 
    4179                                struct __lock__; 
    42  
    43                                 namespace data { 
    44                                         /** 
    45                                          * @class single 
    46                                          * @brief provides shared data management functionality for threads 
    47                                          */ 
    48                                         class single : public sync::data::single { 
    49                                           private: 
    50  
    51                                                 /** 
    52                                                  * copy constructor 
    53                                                  * @note to prevent copying 
    54                                                  */ 
    55                                                 single(single &); 
    56  
    57                                           public: 
    58  
    59                                                 /** 
    60                                                  * constructor 
    61                                                  */ 
    62                                                 single(); 
    63  
    64                                                 /** 
    65                                                  * destructor 
    66                                                  */ 
    67                                                 virtual ~single(); 
    68  
    69                                                 /** 
    70                                                  * set shared data 
    71                                                  * @param data defines shared data 
    72                                                  */ 
    73                                                 virtual void set(void *data); 
    74  
    75                                                 /** 
    76                                                  * set shared data to NULL 
    77                                                  */ 
    78                                                 virtual void remove(); 
    79  
    80                                                 /** 
    81                                                  * lock and return shared data 
    82                                                  * @return shared data 
    83                                                  * @param microseconds defines wait timeout for unlock 
    84                                                  * @note if microseconds is 0 it will wait infinitely 
    85                                                  */ 
    86                                                 virtual void *acquire(unsigned long microseconds = 0); 
    87  
    88                                                 /** 
    89                                                  * unlock shared data 
    90                                                  */ 
    91                                                 virtual void release(); 
    92  
    93                                           protected: 
    94  
    95                                                 void *data;             ///< shared data 
    96  
    97                                                 __lock__ *lock;         ///< lock 
    98                                         }; 
    99                                 }; 
     80                                __lock__ *lock;         ///< lock 
    10081                        }; 
    10182                }; 
  • trunk/include/libdodo/pcSyncThreadEx.h

    r1373 r1377  
    11/*************************************************************************** 
    2  *            pcSyncThreadDataSingleEx.h 
     2 *            pcSyncThreadEx.h 
    33 * 
    44 *  Wed Oct 5 2005 
     
    2828 */ 
    2929 
    30 #ifndef _PCSYNCTHREADDATASINGLEEX_H_ 
    31 #define _PCSYNCTHREADDATASINGLEEX_H_ 1 
     30#ifndef _PCSYNCTHREADEX_H_ 
     31#define _PCSYNCTHREADEX_H_ 1 
    3232 
    3333#include <libdodo/directives.h> 
     
    3838        namespace pc { 
    3939                namespace sync { 
    40                         namespace thread { 
    41                                 namespace data { 
    42                                         /** 
    43                                          * libdodo defined errors 
    44                                          */ 
    45                                         enum singleExR { 
    46                                                 SINGLEEX_ISALREADYLOCKED, 
    47                                                 SINGLEEX_CANNOTLOCK 
    48                                         }; 
     40                        /** 
     41                         * libdodo defined errors 
     42                         */ 
     43                        enum threadExR { 
     44                                THREADEX_CANNOTLOCK 
     45                        }; 
    4946 
    50                                         /** 
    51                                          * explanations for libdodo defined errors 
    52                                          */ 
    53 #define PCSYNCTHREADDATASINGLEEX_ISALREADYLOCKED_STR "Item is currently locked" 
    54 #define PCSYNCTHREADDATASINGLEEX_CANNOTLOCK_STR      "Item is currently locked, timeout exhousted" 
     47                        /** 
     48                         * explanations for libdodo defined errors 
     49                         */ 
     50#define PCSYNCTHREADEX_CANNOTLOCK_STR      "Item is currently locked, timeout exhousted" 
    5551 
    56                                         /** 
    57                                          * IDs of functions where exception might be thrown 
    58                                          */ 
    59                                         enum singleFunctionsID { 
    60                                                 SINGLEEX_REMOVE, 
    61                                                 SINGLEEX_SET, 
    62                                                 SINGLEEX_LOCK, 
    63                                                 SINGLEEX_UNLOCK, 
    64                                                 SINGLEEX_SIGNLE, 
    65                                         }; 
    66                                 }; 
     52                        /** 
     53                         * IDs of functions where exception might be thrown 
     54                         */ 
     55                        enum threadFunctionsID { 
     56                                THREADEX_ACQUIRE, 
     57                                THREADEX_RELEASE, 
     58                                THREADEX_CONSTRUCTOR, 
    6759                        }; 
    6860                }; 
  • trunk/include/libdodo/toolsLogger.h

    r1373 r1377  
    4242        namespace pc { 
    4343                namespace sync { 
    44                         class section; 
     44                        class protector; 
    4545                }; 
    4646        }; 
     
    135135                        static const int syslogLevels[LOG_LEVEL_ENUMSIZE];       ///< syslog log levels 
    136136 
    137                         pc::sync::section *keeper;                          ///< section locker 
     137                        pc::sync::protector *keeper;                          ///< section locker 
    138138                }; 
    139139        }; 
  • trunk/include/libdodo/toolsOs.h

    r1373 r1377  
    3434 
    3535#include <libdodo/types.h> 
     36#include <libdodo/pcSyncThread.h> 
    3637 
    3738namespace dodo { 
    3839        namespace pc { 
    3940                namespace sync { 
    40                         namespace thread { 
    41                                 struct __lock__; 
    42                         }; 
    43                 }; 
    44  
    45                 namespace job { 
    46                         namespace thread { 
    47                                 class manager; 
    48                         }; 
     41                        class protector; 
    4942                }; 
    5043        }; 
     
    5649                 */ 
    5750                class os { 
    58                         friend class pc::job::thread::manager; 
    59  
    6051                  public: 
    6152 
     
    527518                        static bool handlesOpenedSig[SIGNAL_ENUMSIZE];   ///< map of opened modules 
    528519#endif 
    529                         /** 
    530                          * @class syncThreadSection 
    531                          * @brief performs atomic locks using mutexes 
    532                          */ 
    533                         class syncThreadSection { 
    534                           public: 
    535  
    536                                 /** 
    537                                  * consructor 
    538                                  */ 
    539                                 syncThreadSection(); 
    540  
    541                                 /** 
    542                                  * destructor 
    543                                  */ 
    544                                 virtual ~syncThreadSection(); 
    545  
    546                                 /** 
    547                                  * lock critical section 
    548                                  */ 
    549                                 virtual void acquire(); 
    550  
    551                                 /** 
    552                                  * unlock critical section 
    553                                  */ 
    554                                 virtual void release(); 
    555  
    556                           protected: 
    557  
    558                                 static pc::sync::thread::__lock__ keeper;   ///< mutex 
    559                         }; 
    560  
    561                         static syncThreadSection keeper;                ///< lock 
    562  
    563                         /** 
    564                          * @class syncThreadStack 
    565                          * @brief provides thread safe behaviour 
    566                          * @note it locks in constructor and unlocks in destructor 
    567                          */ 
    568                         class syncThreadStack { 
    569                           public: 
    570  
    571                                 /** 
    572                                  * contructor 
    573                                  */ 
    574                                 syncThreadStack(); 
    575  
    576                                 /** 
    577                                  * destructor 
    578                                  */ 
    579                                 virtual ~syncThreadStack(); 
    580                         }; 
     520 
     521                        static pc::sync::thread keeper;                     ///< section locker 
    581522                }; 
    582523        }; 
  • trunk/src/cgiFastServer.cc

    r1373 r1377  
    3939#include <libdodo/cgiFastServerEx.h> 
    4040#include <libdodo/cgiFastExchange.h> 
    41 #include <libdodo/pcSyncThreadSection.h> 
    42 #include <libdodo/pcSyncProtector.h> 
     41#include <libdodo/pcSyncThread.h> 
     42#include <libdodo/pcSyncStack.h> 
    4343 
    4444using namespace dodo::cgi::fast; 
    4545 
    46 dodo::pc::sync::thread::section server::acceptLock; 
     46dodo::pc::sync::thread server::accept; 
    4747 
    4848//------------------------------------------------------------------- 
    4949 
    50 dodo::pc::sync::thread::section server::requestLock; 
     50dodo::pc::sync::thread server::request; 
    5151 
    5252//------------------------------------------------------------------- 
     
    8989 
    9090void * 
    91 server::fastCGIThread(void *data) 
     91server::thread(void *data) 
    9292{ 
    9393        FCGX_Request req; 
    9494        __request__ request = &req; 
     95 
    9596        FCGX_InitRequest(request.request, 0, 0); 
    9697 
     
    104105        while (true) { 
    105106                if (limit != 0) { 
    106                         pc::sync::protector rp(&requestLock); 
     107                        pc::sync::stack p(&server::request); 
    107108 
    108109                        ++requests; 
     
    112113                } 
    113114 
    114                 acceptLock.acquire(); 
     115                accept.acquire(); 
    115116                res = FCGX_Accept_r(request.request); 
    116                 acceptLock.release(); 
     117                accept.release(); 
    117118 
    118119                if (res == -1) 
     
    143144 
    144145                for (; i < threadsNum; ++i) 
    145                         pthread_create(&id[i], NULL, fastCGIThread, &limit); 
     146                        pthread_create(&id[i], NULL, server::thread, &limit); 
    146147 
    147148                for (i = 0; i < threadsNum; ++i) 
  • trunk/src/exceptionBasic.cc

    r1374 r1377  
    9898        false, 
    9999        false, 
    100         false, 
    101         false, 
    102         false, 
    103         false, 
    104100        false 
    105101}; 
     
    153149        NULL, 
    154150        NULL, 
    155         NULL, 
    156         NULL, 
    157         NULL, 
    158         NULL, 
    159151        NULL 
    160152}; 
     
    208200        NULL, 
    209201        NULL, 
    210         NULL, 
    211         NULL, 
    212         NULL, 
    213         NULL, 
    214202        NULL 
    215203}; 
     
    263251        false, 
    264252        false, 
    265         false, 
    266         false, 
    267         false, 
    268         false, 
    269253        false 
    270254}; 
     
    318302        NULL, 
    319303        NULL, 
    320         NULL, 
    321         NULL, 
    322         NULL, 
    323         NULL, 
    324304        NULL 
    325305}; 
     
    328308//------------------------------------------------------------------- 
    329309 
     310basic::sync::stack::stack() 
     311{ 
    330312#ifdef PTHREAD_EXT 
    331 pthread_mutex_t basic::syncThreadSection::keeper; 
    332 #endif 
    333  
    334 //------------------------------------------------------------------- 
    335  
    336 basic::syncThreadSection basic::keeper; 
    337  
    338 //------------------------------------------------------------------- 
    339  
    340 basic::syncThreadSection::syncThreadSection() 
     313        static pthread_mutex_t mutex; 
     314        static unsigned char mutex_init = 0; 
     315        if (!mutex_init) { 
     316                pthread_mutexattr_t attr; 
     317                pthread_mutexattr_init(&attr); 
     318                pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); 
     319 
     320                pthread_mutex_init(&mutex, &attr); 
     321 
     322                pthread_mutexattr_destroy(&attr); 
     323 
     324                mutex_init = 1; 
     325        } 
     326 
     327        keeper = &mutex; 
     328 
     329        pthread_mutex_lock((pthread_mutex_t *)keeper); 
     330#endif 
     331} 
     332 
     333//------------------------------------------------------------------- 
     334 
     335basic::sync::stack::~stack() 
    341336{ 
    342337#ifdef PTHREAD_EXT 
    343         pthread_mutexattr_t attr; 
    344         pthread_mutexattr_init(&attr); 
    345         pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); 
    346  
    347         pthread_mutex_init(&keeper, &attr); 
    348  
    349         pthread_mutexattr_destroy(&attr); 
    350 #endif 
    351 } 
    352  
    353 //------------------------------------------------------------------- 
    354  
    355 basic::syncThreadSection::~syncThreadSection() 
    356 { 
    357 #ifdef PTHREAD_EXT 
    358         pthread_mutex_destroy(&keeper); 
    359 #endif 
    360 } 
    361  
    362 //------------------------------------------------------------------- 
    363  
    364 void 
    365 basic::syncThreadSection::acquire() 
    366 { 
    367 #ifdef PTHREAD_EXT 
    368         pthread_mutex_lock(&keeper); 
    369 #endif 
    370 } 
    371  
    372 //------------------------------------------------------------------- 
    373  
    374 void 
    375 basic::syncThreadSection::release() 
    376 { 
    377 #ifdef PTHREAD_EXT 
    378         pthread_mutex_unlock(&keeper); 
    379 #endif 
    380 } 
    381  
    382 //------------------------------------------------------------------- 
    383  
    384 basic::syncThreadStack::syncThreadStack() 
    385 { 
    386         keeper.acquire(); 
    387 } 
    388  
    389 //------------------------------------------------------------------- 
    390  
    391 basic::syncThreadStack::~syncThreadStack() 
    392 { 
    393         keeper.release(); 
     338        pthread_mutex_unlock((pthread_mutex_t *)keeper); 
     339#endif 
    394340} 
    395341 
     
    419365                                                                                                         message(a_message) 
    420366{ 
    421         syncThreadStack tg; 
     367        sync::stack tg; 
    422368 
    423369#ifdef __GNUC__ 
     
    791737basic::~basic() throw () 
    792738{ 
    793         syncThreadStack tg; 
     739        sync::stack tg; 
    794740 
    795741        --instances; 
     
    840786& () 
    841787{ 
    842         syncThreadStack tg; 
     788        sync::stack tg; 
    843789 
    844790        return errStr; 
     
    850796basic::what() const throw () 
    851797{ 
    852         syncThreadStack tg; 
     798        sync::stack tg; 
    853799 
    854800        return errStr.data(); 
     
    862808                                           void            *data) 
    863809{ 
    864         syncThreadStack tg; 
     810        sync::stack tg; 
    865811 
    866812        instance(); 
     
    894840                                                void         *data) 
    895841{ 
    896         syncThreadStack tg; 
     842        sync::stack tg; 
    897843 
    898844        instance(); 
     
    929875basic::removeHandler(moduleEnum module) 
    930876{ 
    931         syncThreadStack tg; 
     877        sync::stack tg; 
    932878 
    933879#ifdef DL_EXT 
     
    958904basic::removeHandlers() 
    959905{ 
    960         syncThreadStack tg; 
     906        sync::stack tg; 
    961907 
    962908#ifdef DL_EXT 
     
    994940                                           void             *toInit) 
    995941{ 
    996         syncThreadStack tg; 
     942        sync::stack tg; 
    997943 
    998944        instance(); 
     
    1052998                                         void             *toInit) 
    1053999{ 
    1054         syncThreadStack tg; 
     1000        sync::stack tg; 
    10551001 
    10561002#ifdef DL_FAST 
  • trunk/src/ioBlockChannel.cc

    r1373 r1377  
    3636#include <libdodo/xexec.h> 
    3737#include <libdodo/types.h> 
    38 #include <libdodo/pcSyncProtector.h> 
     38#include <libdodo/pcSyncStack.h> 
    3939 
    4040using namespace dodo::io::block; 
     
    5858channel::read() const 
    5959{ 
    60         pc::sync::protector pg(keeper); 
     60        pc::sync::stack pg(keeper); 
    6161 
    6262        dodoString a_str; 
     
    103103channel::readString() const 
    104104{ 
    105         pc::sync::protector pg(keeper); 
     105        pc::sync::stack pg(keeper); 
    106106 
    107107        dodoString a_str; 
     
    149149channel::write(const dodoString &a_data) const 
    150150{ 
    151         pc::sync::protector pg(keeper); 
     151        pc::sync::stack pg(keeper); 
    152152 
    153153#ifndef IO_WO_XEXEC 
     
    181181channel::writeString(const dodoString &a_data) const 
    182182{ 
    183         pc::sync::protector pg(keeper); 
     183        pc::sync::stack pg(keeper); 
    184184 
    185185#ifndef IO_WO_XEXEC 
  • trunk/src/ioChannel.cc

    r1373 r1377  
    3333#include <libdodo/xexec.h> 
    3434#include <libdodo/types.h> 
    35 #include <libdodo/pcSyncProcessSection.h> 
    36 #include <libdodo/pcSyncThreadSection.h> 
    37 #include <libdodo/pcSyncProtector.h> 
     35#include <libdodo/pcSyncProcess.h> 
     36#include <libdodo/pcSyncThread.h> 
     37#include <libdodo/pcSyncStack.h> 
    3838 
    3939using namespace dodo::io; 
     
    5757{ 
    5858        if (protection == channel::PROTECTION_THREAD) 
    59                 keeper = new pc::sync::thread::section; 
     59                keeper = new pc::sync::thread; 
    6060        else if (protection == channel::PROTECTION_PROCESS) 
    61                 keeper = new pc::sync::process::section(0); 
     61                keeper = new pc::sync::process(0); 
    6262} 
    6363 
  • trunk/src/ioEventManager.cc

    r1373 r1377  
    3939#include <libdodo/toolsMisc.h> 
    4040#include <libdodo/ioEventDescriptor.h> 
    41 #include <libdodo/pcSyncProcessSection.h> 
    42 #include <libdodo/pcSyncProtector.h> 
     41#include <libdodo/pcSyncProcess.h> 
     42#include <libdodo/pcSyncStack.h> 
    4343 
    4444using namespace dodo::io::event; 
     
    5151 
    5252manager::manager() : descs(0), 
    53                                  keeper(new pc::sync::process::section(0)) 
     53                                 keeper(new pc::sync::process(0)) 
    5454{ 
    5555} 
     
    6767manager::add(const descriptor &fl) 
    6868{ 
    69         pc::sync::protector pg(keeper); 
     69        pc::sync::stack pg(keeper); 
    7070 
    7171        __descriptors__ tempD; 
     
    8686                                  int                  timeout) const 
    8787{ 
    88         pc::sync::protector pg(keeper); 
     88        pc::sync::stack pg(keeper); 
    8989 
    9090        int count = -1; 
     
    153153                                  int                  timeout) const 
    154154{ 
    155         pc::sync::protector pg(keeper); 
     155        pc::sync::stack pg(keeper); 
    156156 
    157157        int count = -1; 
     
    220220                                  int timeout) const 
    221221{ 
    222         pc::sync::protector pg(keeper); 
     222        pc::sync::stack pg(keeper); 
    223223 
    224224        pollfd fd; 
     
    254254manager::remove(int pos) 
    255255{ 
    256         pc::sync::protector pg(keeper); 
     256        pc::sync::stack pg(keeper); 
    257257 
    258258        dodoArray<__descriptors__>::iterator i(desc.begin()), j(desc.end()); 
     
    272272                                  int timeout) const 
    273273{ 
    274         pc::sync::protector pg(keeper); 
     274        pc::sync::stack pg(keeper); 
    275275 
    276276        pollfd fd; 
  • trunk/src/ioFileFifo.cc

    r1373 r1377  
    4444#include <libdodo/types.h> 
    4545#include <libdodo/ioChannel.h> 
    46 #include <libdodo/pcSyncProtector.h> 
     46#include <libdodo/pcSyncStack.h> 
    4747 
    4848using namespace dodo::io::file; 
     
    216216fifo::inDescriptor() const 
    217217{ 
    218         pc::sync::protector pg(keeper); 
     218        pc::sync::stack pg(keeper); 
    219219 
    220220        if (handle->file == NULL) 
     
    229229fifo::outDescriptor() const 
    230230{ 
    231         pc::sync::protector pg(keeper); 
     231        pc::sync::stack pg(keeper); 
    232232 
    233233        if (handle->file == NULL) 
     
    242242fifo::clone(const fifo &fd) 
    243243{ 
    244         pc::sync::protector pg(keeper); 
     244        pc::sync::stack pg(keeper); 
    245245 
    246246        if (handle->file != NULL) { 
     
    290290fifo::close() 
    291291{ 
    292         pc::sync::protector pg(keeper); 
     292        pc::sync::stack pg(keeper); 
    293293 
    294294#ifndef IO_WO_XEXEC 
     
    314314                   short            a_mode) 
    315315{ 
    316         pc::sync::protector pg(keeper); 
     316        pc::sync::stack pg(keeper); 
    317317 
    318318#ifndef IO_WO_XEXEC 
     
    397397fifo::isBlocked() 
    398398{ 
    399         pc::sync::protector pg(keeper); 
     399        pc::sync::stack pg(keeper); 
    400400 
    401401        return blocked; 
     
    407407fifo::block(bool flag) 
    408408{ 
    409         pc::sync::protector pg(keeper); 
     409        pc::sync::stack pg(keeper); 
    410410 
    411411        if (handle->file == NULL) 
     
    507507fifo::flush() const 
    508508{ 
    509         pc::sync::protector pg(keeper); 
     509        pc::sync::stack pg(keeper); 
    510510 
    511511        if (handle->file == NULL) 
  • trunk/src/ioFileRegular.cc

    r1373 r1377  
    4242#include <libdodo/ioFileRegularEx.h> 
    4343#include <libdodo/types.h> 
    44 #include <libdodo/pcSyncProtector.h> 
     44#include <libdodo/pcSyncStack.h> 
    4545#include <libdodo/ioChannel.h> 
    4646#include <libdodo/ioBlockChannel.h> 
     
    203203regular::inDescriptor() const 
    204204{ 
    205         pc::sync::protector pg(keeper); 
     205        pc::sync::stack pg(keeper); 
    206206 
    207207        if (handle->file == NULL) 
     
    216216regular::outDescriptor() const 
    217217{ 
    218         pc::sync::protector pg(keeper); 
     218        pc::sync::stack pg(keeper); 
    219219 
    220220        if (handle->file == NULL) 
     
    229229regular::clone(const regular &fd) 
    230230{ 
    231         pc::sync::protector pg(keeper); 
     231        pc::sync::stack pg(keeper); 
    232232 
    233233        if (handle->file !=  NULL) { 
     
    280280regular::close() 
    281281{ 
    282         pc::sync::protector pg(keeper); 
     282        pc::sync::stack pg(keeper); 
    283283 
    284284#ifndef IO_WO_XEXEC 
     
    304304                          short            a_mode) 
    305305{ 
    306         pc::sync::protector pg(keeper); 
     306        pc::sync::stack pg(keeper); 
    307307 
    308308#ifndef IO_WO_XEXEC 
     
    437437regular::erase() 
    438438{ 
    439         pc::sync::protector pg(keeper); 
     439        pc::sync::stack pg(keeper); 
    440440 
    441441        char *empty = new char[blockSize]; 
     
    458458regular::flush() const 
    459459{ 
    460         pc::sync::protector pg(keeper); 
     460        pc::sync::stack pg(keeper); 
    461461 
    462462        if (handle->file == NULL) 
  • trunk/src/ioFileTemp.cc

    r1373 r1377  
    4343#include <libdodo/ioChannel.h> 
    4444#include <libdodo/ioBlockChannel.h> 
    45 #include <libdodo/pcSyncProtector.h> 
     45#include <libdodo/pcSyncStack.h> 
    4646 
    4747using namespace dodo::io::file; 
     
    126126temp::inDescriptor() const 
    127127{ 
    128         pc::sync::protector pg(keeper); 
     128        pc::sync::stack pg(keeper); 
    129129 
    130130        if (handle->file == NULL) 
     
    139139temp::outDescriptor() const 
    140140{ 
    141         pc::sync::protector pg(keeper); 
     141        pc::sync::stack pg(keeper); 
    142142 
    143143        if (handle->file == NULL) 
     
    152152temp::clone(const temp &fd) 
    153153{ 
    154         pc::sync::protector pg(keeper); 
     154        pc::sync::stack pg(keeper); 
    155155 
    156156        if (handle->file != NULL) { 
     
    190190temp::close() 
    191191{ 
    192         pc::sync::protector pg(keeper); 
     192        pc::sync::stack pg(keeper); 
    193193 
    194194#ifndef IO_WO_XEXEC 
     
    213213temp::open() 
    214214{ 
    215         pc::sync::protector pg(keeper); 
     215        pc::sync::stack pg(keeper); 
    216216 
    217217#ifndef IO_WO_XEXEC 
     
    316316temp::erase() 
    317317{ 
    318         pc::sync::protector pg(keeper); 
     318        pc::sync::stack pg(keeper); 
    319319 
    320320        char *empty = new char[blockSize]; 
     
    345345temp::flush() const 
    346346{ 
    347         pc::sync::protector pg(keeper); 
     347        pc::sync::stack pg(keeper); 
    348348 
    349349        if (handle->file == NULL) 
  • trunk/src/ioMemory.cc

    r1373 r1377  
    3737#include <libdodo/ioBlockChannel.h> 
    3838#include <libdodo/ioMemoryEx.h> 
    39 #include <libdodo/pcSyncProtector.h> 
     39#include <libdodo/pcSyncStack.h> 
    4040 
    4141using namespace dodo::io; 
     
    178178memory::clone(const memory &fd) 
    179179{ 
    180         pc::sync::protector pg(keeper); 
     180        pc::sync::stack pg(keeper); 
    181181 
    182182        pos = fd.pos; 
     
    251251memory::erase() 
    252252{ 
    253         pc::sync::protector pg(keeper); 
     253        pc::sync::stack pg(keeper); 
    254254 
    255255        unsigned long pos = block ? this->pos * blockSize : this->pos; 
  • trunk/src/ioNetworkExchange.cc

    r1373 r1377  
    4141#include <libdodo/ioNetworkExchangeEx.h> 
    4242#include <libdodo/types.h> 
    43 #include <libdodo/pcSyncProtector.h> 
     43#include <libdodo/pcSyncStack.h> 
    4444 
    4545using namespace dodo::io::network; 
     
    107107exchange::close() 
    108108{ 
    109         pc::sync::protector pg(keeper); 
     109        pc::sync::stack pg(keeper); 
    110110 
    111111#ifndef IO_WO_XEXEC 
     
    131131                           bool blockInherited) 
    132132{ 
    133         pc::sync::protector pg(keeper); 
     133        pc::sync::stack pg(keeper); 
    134134 
    135135        if (socket != -1) { 
     
    164164exchange::isAlive() 
    165165{ 
    166         pc::sync::protector pg(keeper); 
     166        pc::sync::stack pg(keeper); 
    167167 
    168168        if (socket == -1) 
     
    369369exchange::inDescriptor() const 
    370370{ 
    371         pc::sync::protector pg(keeper); 
     371        pc::sync::stack pg(keeper); 
    372372 
    373373        return socket; 
     
    379379exchange::outDescriptor() const 
    380380{ 
    381         pc::sync::protector pg(keeper); 
     381        pc::sync::stack pg(keeper); 
    382382 
    383383        return socket; 
  • trunk/src/ioNetworkSslExchange.cc

    r1373 r1377  
    4545#include <libdodo/types.h> 
    4646#include <libdodo/xexec.h> 
    47 #include <libdodo/pcSyncProtector.h> 
     47#include <libdodo/pcSyncStack.h> 
    4848 
    4949using namespace dodo::io::network::ssl; 
     
    144144exchange::close() 
    145145{ 
    146         pc::sync::protector pg(keeper); 
     146        pc::sync::stack pg(keeper); 
    147147 
    148148#ifndef IO_WO_XEXEC 
     
    170170                           bool                       blockInherited) 
    171171{ 
    172         pc::sync::protector pg(keeper); 
     172        pc::sync::stack pg(keeper); 
    173173 
    174174        if (socket != -1) { 
     
    206206exchange::isAlive() 
    207207{ 
    208         pc::sync::protector pg(keeper); 
     208        pc::sync::stack pg(keeper); 
    209209 
    210210        if (socket == -1) 
  • trunk/src/ioPipe.cc

    r1373 r1377  
    4545#include <libdodo/ioStreamChannel.h> 
    4646#include <libdodo/ioNetworkConnection.h> 
    47 #include <libdodo/pcSyncProtector.h> 
     47#include <libdodo/pcSyncStack.h> 
    4848 
    4949using namespace dodo; 
     
    136136io::pipe::clone(const pipe &fd) 
    137137{ 
    138         pc::sync::protector pg(keeper); 
     138        pc::sync::stack pg(keeper); 
    139139 
    140140        if (in->file != NULL) { 
     
    189189io::pipe::inDescriptor() const 
    190190{ 
    191         pc::sync::protector pg(keeper); 
     191        pc::sync::stack pg(keeper); 
    192192 
    193193        if (in->file == NULL) 
     
    202202io::pipe::outDescriptor() const 
    203203{ 
    204         pc::sync::protector pg(keeper); 
     204        pc::sync::stack pg(keeper); 
    205205 
    206206        if (out->file == NULL) 
     
    215215io::pipe::close() 
    216216{ 
    217         pc::sync::protector pg(keeper); 
     217        pc::sync::stack pg(keeper); 
    218218 
    219219#ifndef IO_WO_XEXEC 
     
    245245io::pipe::open() 
    246246{ 
    247         pc::sync::protector pg(keeper); 
     247        pc::sync::stack pg(keeper); 
    248248 
    249249#ifndef IO_WO_XEXEC 
     
    354354io::pipe::flush() const 
    355355{ 
    356         pc::sync::protector pg(keeper); 
     356        pc::sync::stack pg(keeper); 
    357357 
    358358        if (out->file == NULL) 
     
    368368io::pipe::peer() 
    369369{ 
    370         pc::sync::protector pg(keeper); 
     370        pc::sync::stack pg(keeper); 
    371371 
    372372        if (in->file == NULL) 
     
    428428io::pipe::isBlocked() 
    429429{ 
    430         pc::sync::protector pg(keeper); 
     430        pc::sync::stack pg(keeper); 
    431431 
    432432        return blocked; 
     
    438438io::pipe::block(bool flag) 
    439439{ 
    440         pc::sync::protector pg(keeper); 
     440        pc::sync::stack pg(keeper); 
    441441 
    442442        if (in->file == NULL && out->file == NULL) 
  • trunk/src/ioStreamChannel.cc

    r1373 r1377  
    3636#include <libdodo/xexec.h> 
    3737#include <libdodo/types.h> 
    38 #include <libdodo/pcSyncProtector.h> 
     38#include <libdodo/pcSyncStack.h> 
    3939 
    4040using namespace dodo::io::stream; 
     
    5555channel::read() const 
    5656{ 
    57         pc::sync::protector pg(keeper); 
     57        pc::sync::stack pg(keeper); 
    5858 
    5959        dodoString a_str; 
     
    9898channel::readString() const 
    9999{ 
    100         pc::sync::protector pg(keeper); 
     100        pc::sync::stack pg(keeper); 
    101101 
    102102        dodoString a_str; 
     
    142142channel::write(const dodoString &a_data) const 
    143143{ 
    144         pc::sync::protector pg(keeper); 
     144        pc::sync::stack pg(keeper); 
    145145 
    146146#ifndef IO_WO_XEXEC 
     
    172172channel::writeString(const dodoString &a_data) const 
    173173{ 
    174         pc::sync::protector pg(keeper); 
     174        pc::sync::stack pg(keeper); 
    175175 
    176176#ifndef IO_WO_XEXEC 
  • trunk/src/pcSyncDataObject.cc

    r1373 r1377  
    11/*************************************************************************** 
    2  *            pcSyncDataSingle.cc 
     2 *            pcSyncDataObject.cc 
    33 * 
    44 *  Sun Jul 22 2007 
     
    3030#include <libdodo/directives.h> 
    3131 
    32 #include <libdodo/pcSyncDataSingle.h> 
     32#include <libdodo/pcSyncDataObject.h> 
     33#include <libdodo/pcSyncProtector.h> 
     34#include <libdodo/pcSyncStack.h> 
     35#include <libdodo/types.h> 
    3336 
    3437using namespace dodo::pc::sync::data; 
    3538 
    36 single::~single() 
     39object::object(protector &lock) : data(NULL), 
     40                                                                  lock(lock) 
    3741{ 
    3842} 
    3943 
    4044//------------------------------------------------------------------- 
     45 
     46object::~object() 
     47{ 
     48} 
     49 
     50//------------------------------------------------------------------- 
     51 
     52void 
     53object::set(void *a_data) 
     54{ 
     55        sync::stack g(&lock); 
     56 
     57        data = a_data; 
     58} 
     59//------------------------------------------------------------------- 
     60 
     61const void * 
     62object::get() 
     63{ 
     64        sync::stack g(&lock); 
     65 
     66        return data; 
     67} 
     68 
     69//------------------------------------------------------------------- 
     70 
     71void * 
     72object::acquire(unsigned long timeout) 
     73{ 
     74        lock.acquire(timeout); 
     75        return data; 
     76} 
     77 
     78//------------------------------------------------------------------- 
     79 
     80void 
     81object::release() 
     82{ 
     83        lock.release(); 
     84} 
     85 
     86//------------------------------------------------------------------- 
  • trunk/src/pcSyncProcess.cc

    r1373 r1377  
    11/*************************************************************************** 
    2  *            pcSyncProcessDataSingle.cc 
     2 *            pcSyncProcess.cc 
    33 * 
    44 *  Sun Jul 22 2007 
     
    3333#include <sys/ipc.h> 
    3434#include <sys/sem.h> 
    35 #else /*POSIX_SEMAPHORES*/ 
     35#else /*POSIX_LOCKS*/ 
    3636#include <fcntl.h> 
    3737#include <semaphore.h> 
     
    4242#include <string.h> 
    4343 
    44 #include "pcSyncProcessLock.inline" 
    45  
    46 #include <libdodo/pcSyncProcessDataSingle.h> 
    47 #include <libdodo/pcSyncDataSingle.h> 
    48 #include <libdodo/pcSyncProcessDataSingleEx.h> 
     44#include <libdodo/pcSyncProcess.h> 
     45#include <libdodo/pcSyncProtector.h> 
     46#include <libdodo/pcSyncProcessEx.h> 
    4947#include <libdodo/types.h> 
    5048#include <libdodo/toolsMisc.h> 
    5149#include <libdodo/toolsCode.h> 
    5250 
    53 using namespace dodo::pc::sync::process::data; 
    54  
    55 single::single(single &sts) 
    56 { 
    57 } 
    58  
    59 //------------------------------------------------------------------- 
    60  
    61 single::single(int a_key) : data(NULL), 
    62                                                         semaphore(new pc::sync::process::__lock__), 
    63                                                         autogenerated(false), 
    64                                                         acquired(false) 
     51namespace dodo { 
     52        namespace pc { 
     53                namespace sync { 
     54                        /** 
     55                         * @struct process::__lock__ 
     56                         * @brief defines system lock 
     57                         */ 
     58                        struct process::__lock__ { 
     59                                /** 
     60                                 * constructor 
     61                                 */ 
     62                                __lock__() : 
     63#ifdef XSI_IPC 
     64                                        keeper(-1) 
     65#else 
     66                                        keeper(NULL) 
     67#endif 
     68                                { 
     69                                } 
     70 
     71#ifdef XSI_IPC 
     72                                int        keeper;              ///< lock 
     73                                int        key;                 ///< key for the lock 
     74                                union semun { 
     75                                        int             val; 
     76                                        struct semid_ds *buf; 
     77                                        ushort          *array; 
     78                                } control;                      ///< lock lock->control structure 
     79 
     80                                sembuf     operations[1];       ///< lock lock->operations 
     81#else 
     82                                sem_t      *keeper;             ///< lock 
     83                                dodoString key;                 ///< key for the lock 
     84#endif 
     85                        }; 
     86                }; 
     87        }; 
     88}; 
     89 
     90using namespace dodo::pc::sync; 
     91 
     92process::process(process &) 
     93{ 
     94} 
     95 
     96//------------------------------------------------------------------- 
     97 
     98process::process(int a_key) : lock(new process::__lock__), 
     99                                                          autogenerated(false), 
     100                                                          recursive(0) 
     101 
    65102{ 
    66103#ifdef XSI_IPC 
    67104        if (a_key == 0) { 
    68                 semaphore->key = tools::misc::iRandom(); 
     105                lock->key = tools::misc::iRandom(); 
    69106 
    70107                autogenerated = true; 
    71         } else 
    72                 semaphore->key = a_key; 
    73  
    74         semaphore->operations[0].sem_num = 0; 
    75         semaphore->operations[0].sem_flg = 0; 
    76  
    77         semaphore->keeper = semget(semaphore->key, 1, S_IRUSR | S_IWUSR | IPC_CREAT); 
    78         if (semaphore->keeper == -1) { 
    79                 delete semaphore; 
    80  
    81                 throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SINGLE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    82         } 
    83  
    84         semaphore->control.val = 1; 
    85  
    86         if (semctl(semaphore->keeper, 0, SETVAL, semaphore->control) == -1) { 
    87                 delete semaphore; 
    88  
    89                 throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SINGLE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    90         } 
    91 #else 
    92         semaphore->key = '/'; 
     108        } else { 
     109                lock->key = a_key; 
     110        } 
     111 
     112        lock->operations[0].sem_num = 0; 
     113        lock->operations[0].sem_flg = 0; 
     114 
     115        lock->keeper = semget(lock->key, 1, S_IRUSR | S_IWUSR | IPC_CREAT); 
     116        if (lock->keeper == -1) { 
     117                delete lock; 
     118 
     119                throw exception::basic(exception::MODULE_PCSYNCPROCESS, PROCESSEX_CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     120        } 
     121 
     122        lock->control.val = 1; 
     123 
     124        if (semctl(lock->keeper, 0, SETVAL, lock->control) == -1) { 
     125                delete lock; 
     126 
     127                throw exception::basic(exception::MODULE_PCSYNCPROCESS, PROCESSEX_CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     128        } 
     129#else 
     130        lock->key = '/'; 
    93131 
    94132        if (a_key == 0) { 
     
    96134                tools::misc::random(_key, SH_KEY_SIZE / 2 - 1); 
    97135 
    98                 semaphore->key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 
     136                lock->key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 
    99137 
    100138                autogenerated = true; 
     
    103141                memcpy(_key, &a_key, 4); 
    104142 
    105                 semaphore->key.append(tools::code::binToHex(dodoString(_key, 4))); 
    106         } 
    107  
    108         semaphore->keeper = sem_open(semaphore->key.data(), O_CREAT, S_IRUSR | S_IWUSR, 1); 
    109         if (semaphore->keeper == SEM_FAILED) { 
    110                 delete semaphore; 
    111  
    112                 throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SINGLE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    113         } 
    114 #endif 
    115 } 
    116  
    117 //------------------------------------------------------------------- 
    118  
    119 single::single() : data(NULL), 
    120                                    semaphore(new pc::sync::process::__lock__), 
    121                                    autogenerated(false), 
    122                                    acquired(false) 
    123 { 
    124 } 
    125  
    126 //------------------------------------------------------------------- 
    127  
    128 single::~single() 
    129 { 
    130 #ifdef XSI_IPC 
    131         if (semaphore->keeper != -1) { 
    132                 if (autogenerated) { 
    133                         semctl(semaphore->keeper, 0, IPC_RMID); 
    134                 } else { 
    135                         if (acquired) { 
    136                                 semaphore->operations[0].sem_op = 1; 
    137                                 semop(semaphore->keeper, semaphore->operations, 1); 
    138                         } 
     143                lock->key.append(tools::code::binToHex(dodoString(_key, 4))); 
     144        } 
     145 
     146        lock->keeper = sem_open(lock->key.data(), O_CREAT, S_IRUSR | S_IWUSR, 1); 
     147        if (lock->keeper == SEM_FAILED) { 
     148                delete lock; 
     149 
     150                throw exception::basic(exception::MODULE_PCSYNCPROCESS, PROCESSEX_CONSTRUCTOR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     151        } 
     152#endif 
     153} 
     154 
     155//------------------------------------------------------------------- 
     156 
     157process::~process() 
     158{ 
     159#ifdef XSI_IPC 
     160        try { 
     161                if (acquired() && getpid() == current) { 
     162                        lock->operations[0].sem_op = 1; 
     163 
     164                        semop(lock->keeper, lock->operations, 1); 
    139165                } 
    140         } 
    141 #else 
    142         if (semaphore->keeper != NULL) { 
    143                 if (acquired) 
    144                         sem_post(semaphore->keeper); 
    145  
    146                 sem_close(semaphore->keeper); 
    147  
    148                 if (autogenerated) 
    149                         sem_unlink(semaphore->key.data()); 
    150         } 
    151 #endif 
    152  
    153         delete semaphore; 
     166        } catch (...) { 
     167        } 
     168 
     169        if (autogenerated) 
     170                semctl(lock->keeper, 0, IPC_RMID); 
     171#else 
     172        try { 
     173                if (acquired() && getpid() == current) 
     174                        sem_post(lock->keeper); 
     175        } catch (...) { 
     176        } 
     177 
     178        sem_close(lock->keeper); 
     179 
     180        if (autogenerated) 
     181                sem_unlink(lock->key.data()); 
     182#endif 
     183 
     184        delete lock; 
    154185} 
    155186 
     
    157188 
    158189void 
    159 single::close() 
    160 { 
    161 #ifdef XSI_IPC 
    162         if (semaphore->keeper != -1) { 
    163                 if (autogenerated) { 
    164                         if (semctl(semaphore->keeper, 0, IPC_RMID) == -1) 
    165                                 throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    166                 } else if (acquired) { 
    167                         semaphore->operations[0].sem_op = 1; 
    168                         if (semop(semaphore->keeper, semaphore->operations, 1) == -1) 
    169                                 throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    170                 } 
    171         } 
    172  
    173         semaphore->keeper = -1; 
    174 #else 
    175         if (semaphore->keeper != NULL) { 
    176                 if (acquired) 
    177                         if (sem_post(semaphore->keeper) == -1) 
    178                                 throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    179  
    180                 if (sem_close(semaphore->keeper) == -1) 
    181                         throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    182  
    183                 if (autogenerated) 
    184                         if (sem_unlink(semaphore->key.data())) 
    185                                 throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    186         } 
    187  
    188         semaphore->keeper = NULL; 
    189 #endif 
    190 } 
    191  
    192 //------------------------------------------------------------------- 
    193  
    194 void 
    195 single::open(int a_key) 
    196 { 
    197         close(); 
    198  
    199 #ifdef XSI_IPC 
    200         if (a_key == 0) { 
    201                 semaphore->key = tools::misc::iRandom(); 
    202  
    203                 autogenerated = true; 
    204         } else { 
    205                 semaphore->key = a_key; 
    206         } 
    207  
    208         semaphore->operations[0].sem_num = 0; 
    209         semaphore->operations[0].sem_flg = 0; 
    210         semaphore->keeper = semget(semaphore->key, 1, S_IRUSR | S_IWUSR | IPC_CREAT); 
    211         if (semaphore->keeper == -1) 
    212                 throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    213  
    214         semaphore->control.val = 1; 
    215         if (semctl(semaphore->keeper, 0, SETVAL, semaphore->control) == -1) 
    216                 throw exception::basic(exception::MODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    217  
    218 #else 
    219         semaphore->key = '/'; 
    220  
    221         if (a_key == 0) { 
    222                 char _key[SH_KEY_SIZE / 2 - 1]; 
    223                 tools::misc::random(_key, SH_KEY_SIZE / 2 - 1); 
    224  
    225                 semaphore->key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1)));