Changeset 1377:907b0a6f6889
- Timestamp:
- 10/20/09 22:48:09 (2 years ago)
- Branch:
- default
- Location:
- trunk
- Files:
-
- 18 deleted
- 67 edited
- 2 copied
- 8 moved
-
include/libdodo/cgiFastServer.h (modified) (2 diffs)
-
include/libdodo/exceptionBasic.h (modified) (2 diffs)
-
include/libdodo/ioChannel.h (modified) (2 diffs)
-
include/libdodo/ioEventManager.h (modified) (2 diffs)
-
include/libdodo/pc.h (modified) (1 diff)
-
include/libdodo/pcExecutionManager.h (modified) (2 diffs)
-
include/libdodo/pcExecutionManager.inline (modified) (11 diffs)
-
include/libdodo/pcSyncDataCollection.h (deleted)
-
include/libdodo/pcSyncDataObject.h (moved) (moved from trunk/include/libdodo/pcSyncDataSingle.h) (4 diffs)
-
include/libdodo/pcSyncProcess.h (moved) (moved from trunk/include/libdodo/pcSyncProcessDataSingle.h) (2 diffs)
-
include/libdodo/pcSyncProcessDataCollection.h (deleted)
-
include/libdodo/pcSyncProcessDataCollectionEx.h (deleted)
-
include/libdodo/pcSyncProcessEx.h (moved) (moved from trunk/include/libdodo/pcSyncProcessDataSingleEx.h) (3 diffs)
-
include/libdodo/pcSyncProcessSection.h (deleted)
-
include/libdodo/pcSyncProcessSectionEx.h (deleted)
-
include/libdodo/pcSyncProtector.h (modified) (4 diffs)
-
include/libdodo/pcSyncSection.h (deleted)
-
include/libdodo/pcSyncStack.h (copied) (copied from trunk/include/libdodo/pcSyncProtector.h) (4 diffs)
-
include/libdodo/pcSyncThread.h (moved) (moved from trunk/include/libdodo/pcSyncThreadDataSingle.h) (2 diffs)
-
include/libdodo/pcSyncThreadDataCollection.h (deleted)
-
include/libdodo/pcSyncThreadDataCollectionEx.h (deleted)
-
include/libdodo/pcSyncThreadEx.h (moved) (moved from trunk/include/libdodo/pcSyncThreadDataSingleEx.h) (3 diffs)
-
include/libdodo/pcSyncThreadSection.h (deleted)
-
include/libdodo/pcSyncThreadSectionEx.h (deleted)
-
include/libdodo/toolsLogger.h (modified) (2 diffs)
-
include/libdodo/toolsOs.h (modified) (3 diffs)
-
src/cgiFastServer.cc (modified) (5 diffs)
-
src/exceptionBasic.cc (modified) (16 diffs)
-
src/ioBlockChannel.cc (modified) (5 diffs)
-
src/ioChannel.cc (modified) (2 diffs)
-
src/ioEventManager.cc (modified) (8 diffs)
-
src/ioFileFifo.cc (modified) (9 diffs)
-
src/ioFileRegular.cc (modified) (8 diffs)
-
src/ioFileTemp.cc (modified) (8 diffs)
-
src/ioMemory.cc (modified) (3 diffs)
-
src/ioNetworkExchange.cc (modified) (6 diffs)
-
src/ioNetworkSslExchange.cc (modified) (4 diffs)
-
src/ioPipe.cc (modified) (10 diffs)
-
src/ioStreamChannel.cc (modified) (5 diffs)
-
src/pcSyncDataCollection.cc (deleted)
-
src/pcSyncDataObject.cc (moved) (moved from trunk/src/pcSyncDataSingle.cc) (2 diffs)
-
src/pcSyncProcess.cc (moved) (moved from trunk/src/pcSyncProcessDataSingle.cc) (10 diffs)
-
src/pcSyncProcessDataCollection.cc (deleted)
-
src/pcSyncProcessLock.inline (deleted)
-
src/pcSyncProcessSection.cc (deleted)
-
src/pcSyncProtector.cc (modified) (2 diffs)
-
src/pcSyncSection.cc (deleted)
-
src/pcSyncStack.cc (copied) (copied from trunk/src/pcSyncProtector.cc) (2 diffs)
-
src/pcSyncThread.cc (moved) (moved from trunk/src/pcSyncThreadDataSingle.cc) (10 diffs)
-
src/pcSyncThreadDataCollection.cc (deleted)
-
src/pcSyncThreadLock.inline (deleted)
-
src/pcSyncThreadSection.cc (deleted)
-
src/toolsLogger.cc (modified) (5 diffs)
-
src/toolsOs.cc (modified) (7 diffs)
-
tests/cgi_test/Makefile.in (modified) (1 diff)
-
tests/cgifast_test/Makefile.in (modified) (1 diff)
-
tests/cgifast_test/test.cc (modified) (4 diffs)
-
tests/dataformatjson_test/Makefile.in (modified) (1 diff)
-
tests/dataformatxml_test/Makefile.in (modified) (1 diff)
-
tests/db_test/Makefile.in (modified) (1 diff)
-
tests/dbmysql_test/Makefile.in (modified) (1 diff)
-
tests/dbpostgresql_test/Makefile.in (modified) (1 diff)
-
tests/dbsqlite_test/Makefile.in (modified) (1 diff)
-
tests/image_test/Makefile.in (modified) (1 diff)
-
tests/iofile_toolsfilesystem_test/Makefile.in (modified) (1 diff)
-
tests/iomemory_test/Makefile.in (modified) (1 diff)
-
tests/ionetwork_pcthreads_test/Makefile.in (modified) (1 diff)
-
tests/ionetwork_pcthreads_test/test.cc (modified) (3 diffs)
-
tests/ionetworkclient_test/Makefile.in (modified) (1 diff)
-
tests/ionetworkhttp_test/Makefile.in (modified) (1 diff)
-
tests/ionetworkserver_test/Makefile.in (modified) (1 diff)
-
tests/ionetworksslclient_test/Makefile.in (modified) (1 diff)
-
tests/ionetworksslserver_test/Makefile.in (modified) (1 diff)
-
tests/iononblocked_ionetwork_test/Makefile.in (modified) (1 diff)
-
tests/iononblocked_ionetworkssl_test/Makefile.in (modified) (1 diff)
-
tests/iopipe_iofilefifo_pcthreadcollection_test/Makefile.in (modified) (1 diff)
-
tests/iostdio_test/Makefile.in (modified) (1 diff)
-
tests/pcjobcollection_test/Makefile.in (modified) (1 diff)
-
tests/pcprocesscollection_test/Makefile.in (modified) (1 diff)
-
tests/pcprocesscollection_test/test.cc (modified) (9 diffs)
-
tests/pcthreadcollection_test/Makefile.in (modified) (1 diff)
-
tests/pcthreadcollection_test/test.cc (modified) (3 diffs)
-
tests/rpcjsoncgiserver_test/Makefile.in (modified) (1 diff)
-
tests/rpcjsonhttpclient_test/Makefile.in (modified) (1 diff)
-
tests/rpcxmlcgiserver_test/Makefile.in (modified) (1 diff)
-
tests/rpcxmlhttpclient_test/Makefile.in (modified) (1 diff)
-
tests/toolscode_test/Makefile.in (modified) (1 diff)
-
tests/toolslibrary_test/Makefile.in (modified) (1 diff)
-
tests/toolslogger_test/Makefile.in (modified) (1 diff)
-
tests/toolsmisc_test/Makefile.in (modified) (1 diff)
-
tests/toolsnetwork_test/Makefile.in (modified) (1 diff)
-
tests/toolsos_test/Makefile.in (modified) (1 diff)
-
tests/toolsregexp_test/Makefile.in (modified) (1 diff)
-
tests/toolstime_test/Makefile.in (modified) (1 diff)
-
tests/xexec_test/Makefile.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/libdodo/cgiFastServer.h
r1373 r1377 34 34 35 35 #ifdef FASTCGI_EXT 36 #include <libdodo/pcSyncThread Section.h>36 #include <libdodo/pcSyncThread.h> 37 37 38 38 #include <libdodo/cgiServer.h> … … 92 92 93 93 /** 94 * thread that holds one queue of CGI requests95 * @param data defines the data that will bepassed to the thread94 * thread that processes one queue of CGI requests 95 * @param data defines the data passed to the thread 96 96 */ 97 static void * fastCGIThread(void *data);97 static void *thread(void *data); 98 98 99 static pc::sync::thread ::section acceptLock; ///< accept mutex100 static pc::sync::thread ::section requestLock; ///< request mutex99 static pc::sync::thread accept; ///< accept lock 100 static pc::sync::thread request; ///< request lock 101 101 102 102 static handler handler; ///< function to be called on new request -
trunk/include/libdodo/exceptionBasic.h
r1374 r1377 100 100 MODULE_PCEXECUTIONPROCESS, 101 101 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, 108 104 MODULE_GRAPHICSIMAGE, 109 105 MODULE_GRAPHICSTRANSFORM, … … 300 296 #endif 301 297 302 /** 303 * @class syncThreadSection 304 * @brief performs atomic locks using mutexes 305 */ 306 class syncThreadSection { 298 class sync { 307 299 public: 308 300 309 301 /** 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 311 306 */ 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 }; 355 322 }; 356 323 -
trunk/include/libdodo/ioChannel.h
r1373 r1377 40 40 namespace pc { 41 41 namespace sync { 42 class section;42 class protector; 43 43 }; 44 44 }; … … 182 182 virtual void _writeString(const char * const data) const = 0; 183 183 184 pc::sync:: section*keeper; ///< section locker184 pc::sync::protector *keeper; ///< section locker 185 185 short protection; ///< type of IO protection, @see io::channel::protectionEnum 186 186 -
trunk/include/libdodo/ioEventManager.h
r1373 r1377 38 38 namespace pc { 39 39 namespace sync { 40 class section;40 class protector; 41 41 }; 42 42 }; … … 136 136 int descs; ///< descriptors counter 137 137 138 pc::sync:: section*keeper; ///< section locker138 pc::sync::protector *keeper; ///< section locker 139 139 }; 140 140 }; -
trunk/include/libdodo/pc.h
r1374 r1377 37 37 #include <libdodo/pcExecutionProcessEx.h> 38 38 #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> 47 44 #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> 55 46 #endif -
trunk/include/libdodo/pcExecutionManager.h
r1374 r1377 34 34 35 35 #include <libdodo/types.h> 36 #include <libdodo/pcSyncS ection.h>36 #include <libdodo/pcSyncStack.h> 37 37 38 38 namespace dodo { … … 124 124 unsigned long counter; ///< job id counter 125 125 126 sync:: section*keeper; ///< section locker126 sync::protector *keeper; ///< section locker 127 127 }; 128 128 }; -
trunk/include/libdodo/pcExecutionManager.inline
r1375 r1377 33 33 #include <libdodo/pcExecutionManagerEx.h> 34 34 #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> 38 37 39 38 template <typename T> 40 39 dodo::pc::execution::manager<T>::manager() : counter(0), 41 keeper(new pc::sync::thread ::section)40 keeper(new pc::sync::thread) 42 41 { 43 42 } … … 57 56 dodo::pc::execution::manager<T>::add(const T &job) 58 57 { 59 pc::sync:: protectortg(keeper);58 pc::sync::stack tg(keeper); 60 59 61 60 handles.insert(make_pair(counter, job)); … … 71 70 bool terminate) 72 71 { 73 pc::sync:: protectortg(keeper);72 pc::sync::stack tg(keeper); 74 73 75 74 typename dodoMap<unsigned long, T>::iterator job = handles.find(id); … … 90 89 dodo::pc::execution::manager<T>::run(unsigned long id) 91 90 { 92 pc::sync:: protectortg(keeper);91 pc::sync::stack tg(keeper); 93 92 94 93 typename dodoMap<unsigned long, T>::iterator job = handles.find(id); … … 106 105 dodo::pc::execution::manager<T>::stop(unsigned long id) 107 106 { 108 pc::sync:: protectortg(keeper);107 pc::sync::stack tg(keeper); 109 108 110 109 typename dodoMap<unsigned long, T>::iterator job = handles.find(id); … … 122 121 dodo::pc::execution::manager<T>::stop() 123 122 { 124 pc::sync:: protectortg(keeper);123 pc::sync::stack tg(keeper); 125 124 126 125 typename dodoMap<unsigned long, T>::iterator i = handles.begin(), j = handles.end(); … … 136 135 dodo::pc::execution::manager<T>::wait(unsigned long id) 137 136 { 138 pc::sync:: protectortg(keeper);137 pc::sync::stack tg(keeper); 139 138 140 139 typename dodoMap<unsigned long, T>::iterator job = handles.find(id); … … 152 151 dodo::pc::execution::manager<T>::wait() 153 152 { 154 pc::sync:: protectortg(keeper);153 pc::sync::stack tg(keeper); 155 154 156 155 typename dodoMap<unsigned long, T>::iterator i = handles.begin(), j = handles.end(); … … 166 165 dodo::pc::execution::manager<T>::isRunning(unsigned long id) const 167 166 { 168 pc::sync:: protectortg(keeper);167 pc::sync::stack tg(keeper); 169 168 170 169 typename dodoMap<unsigned long, T>::const_iterator job = handles.find(id); … … 182 181 dodo::pc::execution::manager<T>::running() const 183 182 { 184 pc::sync:: protectortg(keeper);183 pc::sync::stack tg(keeper); 185 184 186 185 unsigned long jobs; … … 201 200 dodo::pc::execution::manager<T>::jobs() 202 201 { 203 pc::sync:: protectortg(keeper);202 pc::sync::stack tg(keeper); 204 203 205 204 dodoList<unsigned long> jobs; -
trunk/include/libdodo/pcSyncDataObject.h
r1373 r1377 1 1 /*************************************************************************** 2 * pcSyncData Single.h2 * pcSyncDataObject.h 3 3 * 4 4 * Mon Oct 22 2007 … … 28 28 */ 29 29 30 #ifndef _PCSYNCDATA SINGLE_H_31 #define _PCSYNCDATA SINGLE_H_ 130 #ifndef _PCSYNCDATAOBJECT_H_ 31 #define _PCSYNCDATAOBJECT_H_ 1 32 32 33 33 #include <libdodo/directives.h> … … 36 36 namespace pc { 37 37 namespace sync { 38 class protector; 39 38 40 namespace data { 39 41 /** 40 * @class single42 * @class object 41 43 * @brief provides shared data management functionality 42 44 */ 43 class single{45 class object { 44 46 public: 47 48 /** 49 * constructor 50 * @param lock defines syncing primitive for the object 51 */ 52 object(protector &lock); 45 53 46 54 /** 47 55 * destructor 48 56 */ 49 virtual ~ single() = 0;57 virtual ~object(); 50 58 51 59 /** … … 53 61 * @param data defines shared data 54 62 */ 55 virtual void set(void *data) = 0;63 virtual void set(void *data); 56 64 57 65 /** 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 59 69 */ 60 virtual void remove() = 0;70 virtual const void *get(); 61 71 62 72 /** 63 73 * lock and return shared data 64 74 * @return shared data 65 * @param microseconds defines wait timeout for unlock66 * @note if microsecondsis 0 it will wait infinitely75 * @param timeout defines wait timeout for unlock in microseconds 76 * @note if timeout is 0 it will wait infinitely 67 77 */ 68 virtual void *acquire(unsigned long microseconds) = 0;78 virtual void *acquire(unsigned long timeout = 0); 69 79 70 80 /** 71 81 * unlock shared data 72 82 */ 73 virtual void release() = 0; 83 virtual void release(); 84 85 protected: 86 87 void *data; ///< object data 88 89 protector &lock; ///< object lock 74 90 }; 75 91 }; -
trunk/include/libdodo/pcSyncProcess.h
r1373 r1377 1 1 /*************************************************************************** 2 * pcSyncProcess DataSingle.h2 * pcSyncProcess.h 3 3 * 4 4 * Sun Jul 22 2007 … … 28 28 */ 29 29 30 #ifndef _PCSYNCPROCESS DATASINGLE_H_31 #define _PCSYNCPROCESS DATASINGLE_H_ 130 #ifndef _PCSYNCPROCESS_H_ 31 #define _PCSYNCPROCESS_H_ 1 32 32 33 33 #include <libdodo/directives.h> 34 34 35 #include <libdodo/pcSync DataSingle.h>35 #include <libdodo/pcSyncProtector.h> 36 36 37 37 namespace dodo { 38 38 namespace pc { 39 39 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 41 96 struct __lock__; 97 __lock__ *lock; 42 98 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 53 100 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 135 103 }; 136 104 }; -
trunk/include/libdodo/pcSyncProcessEx.h
r1373 r1377 1 1 /*************************************************************************** 2 * pcSyncProcess DataSingleEx.h2 * pcSyncProcessEx.h 3 3 * 4 4 * Sun Jul 22 2007 … … 28 28 */ 29 29 30 #ifndef _PCSYNCPROCESS DATASINGLEEX_H_31 #define _PCSYNCPROCESS DATASINGLEEX_H_ 130 #ifndef _PCSYNCPROCESSEX_H_ 31 #define _PCSYNCPROCESSEX_H_ 1 32 32 33 33 #include <libdodo/directives.h> … … 38 38 namespace pc { 39 39 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 }; 49 46 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" 55 51 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, 69 61 }; 70 62 }; -
trunk/include/libdodo/pcSyncProtector.h
r1373 r1377 2 2 * pcSyncProtector.h 3 3 * 4 * Sat Oct 2020074 * Mon Oct 22 2007 5 5 * Copyright 2007 Ni@m 6 6 * niam.niam@gmail.com … … 36 36 namespace pc { 37 37 namespace sync { 38 class section;39 40 38 /** 41 39 * @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 44 41 */ 45 42 class protector { … … 47 44 48 45 /** 49 * contructor46 * destructor 50 47 */ 51 protector(section *parent);48 virtual ~protector() = 0; 52 49 53 50 /** 54 * destructor 51 * lock 52 * @param timeout defines wait timeout for unlock in microseconds 53 * @note if timeout is 0 it will wait infinitely 55 54 */ 56 virtual ~protector();55 virtual void acquire(unsigned long timeout) = 0; 57 56 58 protected: 59 60 section *keeper; ///< lock 57 /** 58 * unlock 59 */ 60 virtual void release() = 0; 61 61 }; 62 62 }; … … 64 64 }; 65 65 #endif 66 -
trunk/include/libdodo/pcSyncStack.h
r1373 r1377 1 1 /*************************************************************************** 2 * pcSync Protector.h2 * pcSyncStack.h 3 3 * 4 4 * Sat Oct 20 2007 … … 28 28 */ 29 29 30 #ifndef _PCSYNC PROTECTOR_H_31 #define _PCSYNC PROTECTOR_H_ 130 #ifndef _PCSYNCSTACK_H_ 31 #define _PCSYNCSTACK_H_ 1 32 32 33 33 #include <libdodo/directives.h> … … 36 36 namespace pc { 37 37 namespace sync { 38 class section;38 class protector; 39 39 40 40 /** 41 * @class protector41 * @class stack 42 42 * @brief provides thread/process safe behaviour 43 * @note it locks in constructor and unlocksin destructor43 * @note locked in constructor and unlocked in destructor 44 44 */ 45 class protector{45 class stack { 46 46 public: 47 47 … … 49 49 * contructor 50 50 */ 51 protector(section *parent);51 stack(protector *); 52 52 53 53 /** 54 54 * destructor 55 55 */ 56 virtual ~ protector();56 virtual ~stack(); 57 57 58 58 protected: 59 59 60 section*keeper; ///< lock60 protector *keeper; ///< lock 61 61 }; 62 62 }; -
trunk/include/libdodo/pcSyncThread.h
r1373 r1377 1 1 /*************************************************************************** 2 * pcSyncThread DataSingle.h2 * pcSyncThread.h 3 3 * 4 4 * Tue Nov 29 2005 … … 28 28 */ 29 29 30 #ifndef _PCSYNCTHREAD DATASINGLE_H_31 #define _PCSYNCTHREAD DATASINGLE_H_ 130 #ifndef _PCSYNCTHREAD_H_ 31 #define _PCSYNCTHREAD_H_ 1 32 32 33 33 #include <libdodo/directives.h> 34 34 35 #include <libdodo/pcSync DataSingle.h>35 #include <libdodo/pcSyncProtector.h> 36 36 37 37 namespace dodo { 38 38 namespace pc { 39 39 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 41 79 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 100 81 }; 101 82 }; -
trunk/include/libdodo/pcSyncThreadEx.h
r1373 r1377 1 1 /*************************************************************************** 2 * pcSyncThread DataSingleEx.h2 * pcSyncThreadEx.h 3 3 * 4 4 * Wed Oct 5 2005 … … 28 28 */ 29 29 30 #ifndef _PCSYNCTHREAD DATASINGLEEX_H_31 #define _PCSYNCTHREAD DATASINGLEEX_H_ 130 #ifndef _PCSYNCTHREADEX_H_ 31 #define _PCSYNCTHREADEX_H_ 1 32 32 33 33 #include <libdodo/directives.h> … … 38 38 namespace pc { 39 39 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 }; 49 46 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" 55 51 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, 67 59 }; 68 60 }; -
trunk/include/libdodo/toolsLogger.h
r1373 r1377 42 42 namespace pc { 43 43 namespace sync { 44 class section;44 class protector; 45 45 }; 46 46 }; … … 135 135 static const int syslogLevels[LOG_LEVEL_ENUMSIZE]; ///< syslog log levels 136 136 137 pc::sync:: section*keeper; ///< section locker137 pc::sync::protector *keeper; ///< section locker 138 138 }; 139 139 }; -
trunk/include/libdodo/toolsOs.h
r1373 r1377 34 34 35 35 #include <libdodo/types.h> 36 #include <libdodo/pcSyncThread.h> 36 37 37 38 namespace dodo { 38 39 namespace pc { 39 40 namespace sync { 40 namespace thread { 41 struct __lock__; 42 }; 43 }; 44 45 namespace job { 46 namespace thread { 47 class manager; 48 }; 41 class protector; 49 42 }; 50 43 }; … … 56 49 */ 57 50 class os { 58 friend class pc::job::thread::manager;59 60 51 public: 61 52 … … 527 518 static bool handlesOpenedSig[SIGNAL_ENUMSIZE]; ///< map of opened modules 528 519 #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 581 522 }; 582 523 }; -
trunk/src/cgiFastServer.cc
r1373 r1377 39 39 #include <libdodo/cgiFastServerEx.h> 40 40 #include <libdodo/cgiFastExchange.h> 41 #include <libdodo/pcSyncThread Section.h>42 #include <libdodo/pcSync Protector.h>41 #include <libdodo/pcSyncThread.h> 42 #include <libdodo/pcSyncStack.h> 43 43 44 44 using namespace dodo::cgi::fast; 45 45 46 dodo::pc::sync::thread ::section server::acceptLock;46 dodo::pc::sync::thread server::accept; 47 47 48 48 //------------------------------------------------------------------- 49 49 50 dodo::pc::sync::thread ::section server::requestLock;50 dodo::pc::sync::thread server::request; 51 51 52 52 //------------------------------------------------------------------- … … 89 89 90 90 void * 91 server:: fastCGIThread(void *data)91 server::thread(void *data) 92 92 { 93 93 FCGX_Request req; 94 94 __request__ request = &req; 95 95 96 FCGX_InitRequest(request.request, 0, 0); 96 97 … … 104 105 while (true) { 105 106 if (limit != 0) { 106 pc::sync:: protector rp(&requestLock);107 pc::sync::stack p(&server::request); 107 108 108 109 ++requests; … … 112 113 } 113 114 114 accept Lock.acquire();115 accept.acquire(); 115 116 res = FCGX_Accept_r(request.request); 116 accept Lock.release();117 accept.release(); 117 118 118 119 if (res == -1) … … 143 144 144 145 for (; i < threadsNum; ++i) 145 pthread_create(&id[i], NULL, fastCGIThread, &limit);146 pthread_create(&id[i], NULL, server::thread, &limit); 146 147 147 148 for (i = 0; i < threadsNum; ++i) -
trunk/src/exceptionBasic.cc
r1374 r1377 98 98 false, 99 99 false, 100 false,101 false,102 false,103 false,104 100 false 105 101 }; … … 153 149 NULL, 154 150 NULL, 155 NULL,156 NULL,157 NULL,158 NULL,159 151 NULL 160 152 }; … … 208 200 NULL, 209 201 NULL, 210 NULL,211 NULL,212 NULL,213 NULL,214 202 NULL 215 203 }; … … 263 251 false, 264 252 false, 265 false,266 false,267 false,268 false,269 253 false 270 254 }; … … 318 302 NULL, 319 303 NULL, 320 NULL,321 NULL,322 NULL,323 NULL,324 304 NULL 325 305 }; … … 328 308 //------------------------------------------------------------------- 329 309 310 basic::sync::stack::stack() 311 { 330 312 #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 335 basic::sync::stack::~stack() 341 336 { 342 337 #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 394 340 } 395 341 … … 419 365 message(a_message) 420 366 { 421 sync ThreadStack tg;367 sync::stack tg; 422 368 423 369 #ifdef __GNUC__ … … 791 737 basic::~basic() throw () 792 738 { 793 sync ThreadStack tg;739 sync::stack tg; 794 740 795 741 --instances; … … 840 786 & () 841 787 { 842 sync ThreadStack tg;788 sync::stack tg; 843 789 844 790 return errStr; … … 850 796 basic::what() const throw () 851 797 { 852 sync ThreadStack tg;798 sync::stack tg; 853 799 854 800 return errStr.data(); … … 862 808 void *data) 863 809 { 864 sync ThreadStack tg;810 sync::stack tg; 865 811 866 812 instance(); … … 894 840 void *data) 895 841 { 896 sync ThreadStack tg;842 sync::stack tg; 897 843 898 844 instance(); … … 929 875 basic::removeHandler(moduleEnum module) 930 876 { 931 sync ThreadStack tg;877 sync::stack tg; 932 878 933 879 #ifdef DL_EXT … … 958 904 basic::removeHandlers() 959 905 { 960 sync ThreadStack tg;906 sync::stack tg; 961 907 962 908 #ifdef DL_EXT … … 994 940 void *toInit) 995 941 { 996 sync ThreadStack tg;942 sync::stack tg; 997 943 998 944 instance(); … … 1052 998 void *toInit) 1053 999 { 1054 sync ThreadStack tg;1000 sync::stack tg; 1055 1001 1056 1002 #ifdef DL_FAST -
trunk/src/ioBlockChannel.cc
r1373 r1377 36 36 #include <libdodo/xexec.h> 37 37 #include <libdodo/types.h> 38 #include <libdodo/pcSync Protector.h>38 #include <libdodo/pcSyncStack.h> 39 39 40 40 using namespace dodo::io::block; … … 58 58 channel::read() const 59 59 { 60 pc::sync:: protectorpg(keeper);60 pc::sync::stack pg(keeper); 61 61 62 62 dodoString a_str; … … 103 103 channel::readString() const 104 104 { 105 pc::sync:: protectorpg(keeper);105 pc::sync::stack pg(keeper); 106 106 107 107 dodoString a_str; … … 149 149 channel::write(const dodoString &a_data) const 150 150 { 151 pc::sync:: protectorpg(keeper);151 pc::sync::stack pg(keeper); 152 152 153 153 #ifndef IO_WO_XEXEC … … 181 181 channel::writeString(const dodoString &a_data) const 182 182 { 183 pc::sync:: protectorpg(keeper);183 pc::sync::stack pg(keeper); 184 184 185 185 #ifndef IO_WO_XEXEC -
trunk/src/ioChannel.cc
r1373 r1377 33 33 #include <libdodo/xexec.h> 34 34 #include <libdodo/types.h> 35 #include <libdodo/pcSyncProcess Section.h>36 #include <libdodo/pcSyncThread Section.h>37 #include <libdodo/pcSync Protector.h>35 #include <libdodo/pcSyncProcess.h> 36 #include <libdodo/pcSyncThread.h> 37 #include <libdodo/pcSyncStack.h> 38 38 39 39 using namespace dodo::io; … … 57 57 { 58 58 if (protection == channel::PROTECTION_THREAD) 59 keeper = new pc::sync::thread ::section;59 keeper = new pc::sync::thread; 60 60 else if (protection == channel::PROTECTION_PROCESS) 61 keeper = new pc::sync::process ::section(0);61 keeper = new pc::sync::process(0); 62 62 } 63 63 -
trunk/src/ioEventManager.cc
r1373 r1377 39 39 #include <libdodo/toolsMisc.h> 40 40 #include <libdodo/ioEventDescriptor.h> 41 #include <libdodo/pcSyncProcess Section.h>42 #include <libdodo/pcSync Protector.h>41 #include <libdodo/pcSyncProcess.h> 42 #include <libdodo/pcSyncStack.h> 43 43 44 44 using namespace dodo::io::event; … … 51 51 52 52 manager::manager() : descs(0), 53 keeper(new pc::sync::process ::section(0))53 keeper(new pc::sync::process(0)) 54 54 { 55 55 } … … 67 67 manager::add(const descriptor &fl) 68 68 { 69 pc::sync:: protectorpg(keeper);69 pc::sync::stack pg(keeper); 70 70 71 71 __descriptors__ tempD; … … 86 86 int timeout) const 87 87 { 88 pc::sync:: protectorpg(keeper);88 pc::sync::stack pg(keeper); 89 89 90 90 int count = -1; … … 153 153 int timeout) const 154 154 { 155 pc::sync:: protectorpg(keeper);155 pc::sync::stack pg(keeper); 156 156 157 157 int count = -1; … … 220 220 int timeout) const 221 221 { 222 pc::sync:: protectorpg(keeper);222 pc::sync::stack pg(keeper); 223 223 224 224 pollfd fd; … … 254 254 manager::remove(int pos) 255 255 { 256 pc::sync:: protectorpg(keeper);256 pc::sync::stack pg(keeper); 257 257 258 258 dodoArray<__descriptors__>::iterator i(desc.begin()), j(desc.end()); … … 272 272 int timeout) const 273 273 { 274 pc::sync:: protectorpg(keeper);274 pc::sync::stack pg(keeper); 275 275 276 276 pollfd fd; -
trunk/src/ioFileFifo.cc
r1373 r1377 44 44 #include <libdodo/types.h> 45 45 #include <libdodo/ioChannel.h> 46 #include <libdodo/pcSync Protector.h>46 #include <libdodo/pcSyncStack.h> 47 47 48 48 using namespace dodo::io::file; … … 216 216 fifo::inDescriptor() const 217 217 { 218 pc::sync:: protectorpg(keeper);218 pc::sync::stack pg(keeper); 219 219 220 220 if (handle->file == NULL) … … 229 229 fifo::outDescriptor() const 230 230 { 231 pc::sync:: protectorpg(keeper);231 pc::sync::stack pg(keeper); 232 232 233 233 if (handle->file == NULL) … … 242 242 fifo::clone(const fifo &fd) 243 243 { 244 pc::sync:: protectorpg(keeper);244 pc::sync::stack pg(keeper); 245 245 246 246 if (handle->file != NULL) { … … 290 290 fifo::close() 291 291 { 292 pc::sync:: protectorpg(keeper);292 pc::sync::stack pg(keeper); 293 293 294 294 #ifndef IO_WO_XEXEC … … 314 314 short a_mode) 315 315 { 316 pc::sync:: protectorpg(keeper);316 pc::sync::stack pg(keeper); 317 317 318 318 #ifndef IO_WO_XEXEC … … 397 397 fifo::isBlocked() 398 398 { 399 pc::sync:: protectorpg(keeper);399 pc::sync::stack pg(keeper); 400 400 401 401 return blocked; … … 407 407 fifo::block(bool flag) 408 408 { 409 pc::sync:: protectorpg(keeper);409 pc::sync::stack pg(keeper); 410 410 411 411 if (handle->file == NULL) … … 507 507 fifo::flush() const 508 508 { 509 pc::sync:: protectorpg(keeper);509 pc::sync::stack pg(keeper); 510 510 511 511 if (handle->file == NULL) -
trunk/src/ioFileRegular.cc
r1373 r1377 42 42 #include <libdodo/ioFileRegularEx.h> 43 43 #include <libdodo/types.h> 44 #include <libdodo/pcSync Protector.h>44 #include <libdodo/pcSyncStack.h> 45 45 #include <libdodo/ioChannel.h> 46 46 #include <libdodo/ioBlockChannel.h> … … 203 203 regular::inDescriptor() const 204 204 { 205 pc::sync:: protectorpg(keeper);205 pc::sync::stack pg(keeper); 206 206 207 207 if (handle->file == NULL) … … 216 216 regular::outDescriptor() const 217 217 { 218 pc::sync:: protectorpg(keeper);218 pc::sync::stack pg(keeper); 219 219 220 220 if (handle->file == NULL) … … 229 229 regular::clone(const regular &fd) 230 230 { 231 pc::sync:: protectorpg(keeper);231 pc::sync::stack pg(keeper); 232 232 233 233 if (handle->file != NULL) { … … 280 280 regular::close() 281 281 { 282 pc::sync:: protectorpg(keeper);282 pc::sync::stack pg(keeper); 283 283 284 284 #ifndef IO_WO_XEXEC … … 304 304 short a_mode) 305 305 { 306 pc::sync:: protectorpg(keeper);306 pc::sync::stack pg(keeper); 307 307 308 308 #ifndef IO_WO_XEXEC … … 437 437 regular::erase() 438 438 { 439 pc::sync:: protectorpg(keeper);439 pc::sync::stack pg(keeper); 440 440 441 441 char *empty = new char[blockSize]; … … 458 458 regular::flush() const 459 459 { 460 pc::sync:: protectorpg(keeper);460 pc::sync::stack pg(keeper); 461 461 462 462 if (handle->file == NULL) -
trunk/src/ioFileTemp.cc
r1373 r1377 43 43 #include <libdodo/ioChannel.h> 44 44 #include <libdodo/ioBlockChannel.h> 45 #include <libdodo/pcSync Protector.h>45 #include <libdodo/pcSyncStack.h> 46 46 47 47 using namespace dodo::io::file; … … 126 126 temp::inDescriptor() const 127 127 { 128 pc::sync:: protectorpg(keeper);128 pc::sync::stack pg(keeper); 129 129 130 130 if (handle->file == NULL) … … 139 139 temp::outDescriptor() const 140 140 { 141 pc::sync:: protectorpg(keeper);141 pc::sync::stack pg(keeper); 142 142 143 143 if (handle->file == NULL) … … 152 152 temp::clone(const temp &fd) 153 153 { 154 pc::sync:: protectorpg(keeper);154 pc::sync::stack pg(keeper); 155 155 156 156 if (handle->file != NULL) { … … 190 190 temp::close() 191 191 { 192 pc::sync:: protectorpg(keeper);192 pc::sync::stack pg(keeper); 193 193 194 194 #ifndef IO_WO_XEXEC … … 213 213 temp::open() 214 214 { 215 pc::sync:: protectorpg(keeper);215 pc::sync::stack pg(keeper); 216 216 217 217 #ifndef IO_WO_XEXEC … … 316 316 temp::erase() 317 317 { 318 pc::sync:: protectorpg(keeper);318 pc::sync::stack pg(keeper); 319 319 320 320 char *empty = new char[blockSize]; … … 345 345 temp::flush() const 346 346 { 347 pc::sync:: protectorpg(keeper);347 pc::sync::stack pg(keeper); 348 348 349 349 if (handle->file == NULL) -
trunk/src/ioMemory.cc
r1373 r1377 37 37 #include <libdodo/ioBlockChannel.h> 38 38 #include <libdodo/ioMemoryEx.h> 39 #include <libdodo/pcSync Protector.h>39 #include <libdodo/pcSyncStack.h> 40 40 41 41 using namespace dodo::io; … … 178 178 memory::clone(const memory &fd) 179 179 { 180 pc::sync:: protectorpg(keeper);180 pc::sync::stack pg(keeper); 181 181 182 182 pos = fd.pos; … … 251 251 memory::erase() 252 252 { 253 pc::sync:: protectorpg(keeper);253 pc::sync::stack pg(keeper); 254 254 255 255 unsigned long pos = block ? this->pos * blockSize : this->pos; -
trunk/src/ioNetworkExchange.cc
r1373 r1377 41 41 #include <libdodo/ioNetworkExchangeEx.h> 42 42 #include <libdodo/types.h> 43 #include <libdodo/pcSync Protector.h>43 #include <libdodo/pcSyncStack.h> 44 44 45 45 using namespace dodo::io::network; … … 107 107 exchange::close() 108 108 { 109 pc::sync:: protectorpg(keeper);109 pc::sync::stack pg(keeper); 110 110 111 111 #ifndef IO_WO_XEXEC … … 131 131 bool blockInherited) 132 132 { 133 pc::sync:: protectorpg(keeper);133 pc::sync::stack pg(keeper); 134 134 135 135 if (socket != -1) { … … 164 164 exchange::isAlive() 165 165 { 166 pc::sync:: protectorpg(keeper);166 pc::sync::stack pg(keeper); 167 167 168 168 if (socket == -1) … … 369 369 exchange::inDescriptor() const 370 370 { 371 pc::sync:: protectorpg(keeper);371 pc::sync::stack pg(keeper); 372 372 373 373 return socket; … … 379 379 exchange::outDescriptor() const 380 380 { 381 pc::sync:: protectorpg(keeper);381 pc::sync::stack pg(keeper); 382 382 383 383 return socket; -
trunk/src/ioNetworkSslExchange.cc
r1373 r1377 45 45 #include <libdodo/types.h> 46 46 #include <libdodo/xexec.h> 47 #include <libdodo/pcSync Protector.h>47 #include <libdodo/pcSyncStack.h> 48 48 49 49 using namespace dodo::io::network::ssl; … … 144 144 exchange::close() 145 145 { 146 pc::sync:: protectorpg(keeper);146 pc::sync::stack pg(keeper); 147 147 148 148 #ifndef IO_WO_XEXEC … … 170 170 bool blockInherited) 171 171 { 172 pc::sync:: protectorpg(keeper);172 pc::sync::stack pg(keeper); 173 173 174 174 if (socket != -1) { … … 206 206 exchange::isAlive() 207 207 { 208 pc::sync:: protectorpg(keeper);208 pc::sync::stack pg(keeper); 209 209 210 210 if (socket == -1) -
trunk/src/ioPipe.cc
r1373 r1377 45 45 #include <libdodo/ioStreamChannel.h> 46 46 #include <libdodo/ioNetworkConnection.h> 47 #include <libdodo/pcSync Protector.h>47 #include <libdodo/pcSyncStack.h> 48 48 49 49 using namespace dodo; … … 136 136 io::pipe::clone(const pipe &fd) 137 137 { 138 pc::sync:: protectorpg(keeper);138 pc::sync::stack pg(keeper); 139 139 140 140 if (in->file != NULL) { … … 189 189 io::pipe::inDescriptor() const 190 190 { 191 pc::sync:: protectorpg(keeper);191 pc::sync::stack pg(keeper); 192 192 193 193 if (in->file == NULL) … … 202 202 io::pipe::outDescriptor() const 203 203 { 204 pc::sync:: protectorpg(keeper);204 pc::sync::stack pg(keeper); 205 205 206 206 if (out->file == NULL) … … 215 215 io::pipe::close() 216 216 { 217 pc::sync:: protectorpg(keeper);217 pc::sync::stack pg(keeper); 218 218 219 219 #ifndef IO_WO_XEXEC … … 245 245 io::pipe::open() 246 246 { 247 pc::sync:: protectorpg(keeper);247 pc::sync::stack pg(keeper); 248 248 249 249 #ifndef IO_WO_XEXEC … … 354 354 io::pipe::flush() const 355 355 { 356 pc::sync:: protectorpg(keeper);356 pc::sync::stack pg(keeper); 357 357 358 358 if (out->file == NULL) … … 368 368 io::pipe::peer() 369 369 { 370 pc::sync:: protectorpg(keeper);370 pc::sync::stack pg(keeper); 371 371 372 372 if (in->file == NULL) … … 428 428 io::pipe::isBlocked() 429 429 { 430 pc::sync:: protectorpg(keeper);430 pc::sync::stack pg(keeper); 431 431 432 432 return blocked; … … 438 438 io::pipe::block(bool flag) 439 439 { 440 pc::sync:: protectorpg(keeper);440 pc::sync::stack pg(keeper); 441 441 442 442 if (in->file == NULL && out->file == NULL) -
trunk/src/ioStreamChannel.cc
r1373 r1377 36 36 #include <libdodo/xexec.h> 37 37 #include <libdodo/types.h> 38 #include <libdodo/pcSync Protector.h>38 #include <libdodo/pcSyncStack.h> 39 39 40 40 using namespace dodo::io::stream; … … 55 55 channel::read() const 56 56 { 57 pc::sync:: protectorpg(keeper);57 pc::sync::stack pg(keeper); 58 58 59 59 dodoString a_str; … … 98 98 channel::readString() const 99 99 { 100 pc::sync:: protectorpg(keeper);100 pc::sync::stack pg(keeper); 101 101 102 102 dodoString a_str; … … 142 142 channel::write(const dodoString &a_data) const 143 143 { 144 pc::sync:: protectorpg(keeper);144 pc::sync::stack pg(keeper); 145 145 146 146 #ifndef IO_WO_XEXEC … … 172 172 channel::writeString(const dodoString &a_data) const 173 173 { 174 pc::sync:: protectorpg(keeper);174 pc::sync::stack pg(keeper); 175 175 176 176 #ifndef IO_WO_XEXEC -
trunk/src/pcSyncDataObject.cc
r1373 r1377 1 1 /*************************************************************************** 2 * pcSyncData Single.cc2 * pcSyncDataObject.cc 3 3 * 4 4 * Sun Jul 22 2007 … … 30 30 #include <libdodo/directives.h> 31 31 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> 33 36 34 37 using namespace dodo::pc::sync::data; 35 38 36 single::~single() 39 object::object(protector &lock) : data(NULL), 40 lock(lock) 37 41 { 38 42 } 39 43 40 44 //------------------------------------------------------------------- 45 46 object::~object() 47 { 48 } 49 50 //------------------------------------------------------------------- 51 52 void 53 object::set(void *a_data) 54 { 55 sync::stack g(&lock); 56 57 data = a_data; 58 } 59 //------------------------------------------------------------------- 60 61 const void * 62 object::get() 63 { 64 sync::stack g(&lock); 65 66 return data; 67 } 68 69 //------------------------------------------------------------------- 70 71 void * 72 object::acquire(unsigned long timeout) 73 { 74 lock.acquire(timeout); 75 return data; 76 } 77 78 //------------------------------------------------------------------- 79 80 void 81 object::release() 82 { 83 lock.release(); 84 } 85 86 //------------------------------------------------------------------- -
trunk/src/pcSyncProcess.cc
r1373 r1377 1 1 /*************************************************************************** 2 * pcSyncProcess DataSingle.cc2 * pcSyncProcess.cc 3 3 * 4 4 * Sun Jul 22 2007 … … 33 33 #include <sys/ipc.h> 34 34 #include <sys/sem.h> 35 #else /*POSIX_ SEMAPHORES*/35 #else /*POSIX_LOCKS*/ 36 36 #include <fcntl.h> 37 37 #include <semaphore.h> … … 42 42 #include <string.h> 43 43 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> 49 47 #include <libdodo/types.h> 50 48 #include <libdodo/toolsMisc.h> 51 49 #include <libdodo/toolsCode.h> 52 50 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) 51 namespace 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 90 using namespace dodo::pc::sync; 91 92 process::process(process &) 93 { 94 } 95 96 //------------------------------------------------------------------- 97 98 process::process(int a_key) : lock(new process::__lock__), 99 autogenerated(false), 100 recursive(0) 101 65 102 { 66 103 #ifdef XSI_IPC 67 104 if (a_key == 0) { 68 semaphore->key = tools::misc::iRandom();105 lock->key = tools::misc::iRandom(); 69 106 70 107 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 = '/'; 93 131 94 132 if (a_key == 0) { … … 96 134 tools::misc::random(_key, SH_KEY_SIZE / 2 - 1); 97 135 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))); 99 137 100 138 autogenerated = true; … … 103 141 memcpy(_key, &a_key, 4); 104 142 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 157 process::~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); 139 165 } 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; 154 185 } 155 186 … … 157 188 158 189 void 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)));
