Changeset 1187:01c8a109ae49
- Timestamp:
- 03/21/09 08:41:39 (3 years ago)
- Branch:
- default
- Location:
- trunk
- Files:
-
- 14 edited
-
include/libdodo/pcJobCollection.h (modified) (3 diffs)
-
include/libdodo/pcProcessCollection.h (modified) (5 diffs)
-
include/libdodo/pcProcessCollectionEx.h (modified) (1 diff)
-
include/libdodo/pcSyncProcessDataCollection.h (modified) (2 diffs)
-
include/libdodo/pcSyncProcessDataSingle.h (modified) (3 diffs)
-
include/libdodo/pcSyncProcessSection.h (modified) (3 diffs)
-
src/pcJobCollection.cc (modified) (1 diff)
-
src/pcProcessCollection.cc (modified) (9 diffs)
-
src/pcSyncDataCollection.cc (modified) (1 diff)
-
src/pcSyncDataSingle.cc (modified) (1 diff)
-
src/pcSyncProcessDataCollection.cc (modified) (1 diff)
-
src/pcSyncProcessDataSingle.cc (modified) (34 diffs)
-
src/pcSyncProcessSection.cc (modified) (23 diffs)
-
tests/pcprocesscollection_test/test.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/libdodo/pcJobCollection.h
r1160 r1187 32 32 33 33 #include <libdodo/directives.h> 34 34 35 #include <libdodo/types.h> 35 36 … … 148 149 149 150 #ifdef DL_EXT 150 151 151 /** 152 152 * add function as a job from library … … 159 159 void *data, 160 160 void *toInit = NULL) = 0; 161 162 161 #endif 163 162 }; -
trunk/include/libdodo/pcProcessCollection.h
r1185 r1187 33 33 #include <libdodo/directives.h> 34 34 35 #ifdef DL_EXT36 37 #include <dlfcn.h>38 39 #endif40 41 #include <sys/types.h>42 #include <signal.h>43 #include <unistd.h>44 #include <sys/wait.h>45 46 35 #include <libdodo/types.h> 47 36 #include <libdodo/pcJobCollection.h> 48 #include <libdodo/pcProcessCollectionEx.h>49 37 50 38 namespace dodo … … 92 80 93 81 #ifdef DL_EXT 94 95 82 /** 96 83 * @struct __processMod … … 118 105 */ 119 106 typedef void (*deinitIpcProcessCollectionModule)(); 120 121 107 #endif 122 108 … … 281 267 282 268 #ifdef DL_EXT 283 284 269 /** 285 270 * add function as a process from library … … 300 285 static __processMod getModuleInfo(const dodoString &module, 301 286 void *toInit = NULL); 302 303 287 #endif 304 288 -
trunk/include/libdodo/pcProcessCollectionEx.h
r1111 r1187 74 74 75 75 #ifdef DL_EXT 76 77 76 COLLECTIONEX_GETMODULEINFO, 78 77 COLLECTIONEX_ADD, 79 80 78 #endif 81 79 }; -
trunk/include/libdodo/pcSyncProcessDataCollection.h
r1166 r1187 35 35 #include <libdodo/types.h> 36 36 #include <libdodo/pcSyncDataCollection.h> 37 #include <libdodo/pcSyncProcessDataCollectionEx.h>38 #include <libdodo/pcSyncProcessSection.h>39 #include <libdodo/pcSyncProtector.h>40 37 41 38 namespace dodo … … 45 42 namespace sync 46 43 { 44 class section; 45 47 46 namespace process 48 47 { -
trunk/include/libdodo/pcSyncProcessDataSingle.h
r1160 r1187 33 33 #include <libdodo/directives.h> 34 34 35 #ifdef XSI_IPC36 37 #include <sys/ipc.h>38 #include <sys/sem.h>39 40 #else /*POSIX_SEMAPHORES*/41 42 #include <fcntl.h>43 #include <semaphore.h>44 45 #endif46 47 #include <time.h>48 49 #include <libdodo/pcSyncProcessDataSingleEx.h>50 35 #include <libdodo/pcSyncDataSingle.h> 51 #include <libdodo/types.h>52 #include <libdodo/toolsMisc.h>53 #include <libdodo/toolsCode.h>54 36 55 37 namespace dodo … … 63 45 namespace data 64 46 { 47 /** 48 * @struct __semaphore 49 * @brief defines system semaphore 50 */ 51 struct __semaphore; 52 65 53 /** 66 54 * @class single … … 149 137 void *data; ///< shared data 150 138 151 #ifdef XSI_IPC 152 int keeper; ///< semaphore 153 int key; ///< key for the semaphore 154 union semun 155 { 156 int val; 157 struct semid_ds *buf; 158 ushort * array; 159 } control; ///< semaphore control structure 160 161 sembuf operations[1]; ///< semaphore operations 162 #else 163 sem_t *keeper; ///< semaphore 164 dodoString key; ///< key for the semaphore 165 #endif 139 __semaphore *semaphore; 166 140 167 141 bool autogenerated; ///< true if key was autogenerated 168 142 bool acquired; ///< true if the semaphore was aquired 169 170 timespec timeout; ///< lock timeout171 143 }; 172 144 }; -
trunk/include/libdodo/pcSyncProcessSection.h
r1160 r1187 33 33 #include <libdodo/directives.h> 34 34 35 #ifdef XSI_IPC36 37 #include <sys/ipc.h>38 #include <sys/sem.h>39 40 #else /*POSIX_SEMAPHORES*/41 42 #include <fcntl.h>43 #include <semaphore.h>44 45 #endif46 47 35 #include <libdodo/pcSyncSection.h> 48 #include <libdodo/toolsMisc.h>49 #include <libdodo/toolsCode.h>50 #include <libdodo/pcSyncProcessSectionEx.h>51 #include <libdodo/types.h>52 36 53 37 namespace dodo … … 59 43 namespace process 60 44 { 45 namespace data 46 { 47 struct __semaphore; 48 }; 49 61 50 /** 62 51 * @class section … … 128 117 protected: 129 118 130 #ifdef XSI_IPC 131 int keeper; ///< semaphore 132 int key; ///< key for the semaphore 133 union semun 134 { 135 int val; 136 struct semid_ds *buf; 137 ushort * array; 138 } control; ///< semaphore control structure 139 140 sembuf operations[1]; ///< semaphore operations 141 #else 142 sem_t * keeper; ///< semaphore 143 dodoString key; ///< key for the semaphore 144 #endif 119 data::__semaphore *semaphore; 145 120 146 121 bool autogenerated; ///< true if key was autogenerated -
trunk/src/pcJobCollection.cc
r978 r1187 28 28 */ 29 29 30 #include <libdodo/directives.h> 31 30 32 #include <libdodo/pcJobCollection.h> 31 33 -
trunk/src/pcProcessCollection.cc
r1166 r1187 28 28 */ 29 29 30 #include <libdodo/directives.h> 31 32 #ifdef DL_EXT 33 #include <dlfcn.h> 34 #endif 35 36 #include <sys/types.h> 37 #include <signal.h> 38 #include <unistd.h> 39 #include <sys/wait.h> 30 40 31 41 #include <libdodo/pcProcessCollection.h> 42 #include <libdodo/types.h> 43 #include <libdodo/pcJobCollection.h> 44 #include <libdodo/pcProcessCollectionEx.h> 32 45 33 46 using namespace dodo::pc::process; … … 91 104 92 105 #ifdef DL_EXT 93 94 106 if (i->handle != NULL) 95 107 { … … 104 116 #endif 105 117 } 106 107 118 #endif 108 119 } … … 221 232 222 233 #ifdef DL_EXT 223 224 234 if (current->handle != NULL) 225 235 { … … 239 249 #endif 240 250 } 241 242 251 #endif 243 252 … … 323 332 324 333 #ifdef DL_EXT 325 326 334 if (current->handle != NULL) 327 335 { … … 341 349 #endif 342 350 } 343 344 351 #endif 345 352 … … 586 593 587 594 #ifdef DL_EXT 588 589 595 __processMod 590 596 collection::getModuleInfo(const dodoString &module, … … 663 669 return process.position; 664 670 } 665 666 671 #endif 667 672 -
trunk/src/pcSyncDataCollection.cc
r979 r1187 28 28 */ 29 29 30 #include <libdodo/directives.h> 30 31 31 32 #include <libdodo/pcSyncDataCollection.h> -
trunk/src/pcSyncDataSingle.cc
r979 r1187 28 28 */ 29 29 30 #include <libdodo/directives.h> 30 31 31 32 #include <libdodo/pcSyncDataSingle.h> -
trunk/src/pcSyncProcessDataCollection.cc
r1162 r1187 28 28 */ 29 29 30 #include <libdodo/directives.h> 30 31 31 32 #include <libdodo/pcSyncProcessDataCollection.h> 33 #include <libdodo/types.h> 34 #include <libdodo/pcSyncDataCollection.h> 35 #include <libdodo/pcSyncProcessDataCollectionEx.h> 36 #include <libdodo/pcSyncProcessSection.h> 37 #include <libdodo/pcSyncProtector.h> 32 38 33 39 using namespace dodo::pc::sync::process::data; -
trunk/src/pcSyncProcessDataSingle.cc
r1186 r1187 28 28 */ 29 29 30 #include <libdodo/directives.h> 31 32 #ifdef XSI_IPC 33 #include <sys/ipc.h> 34 #include <sys/sem.h> 35 #else /*POSIX_SEMAPHORES*/ 36 #include <fcntl.h> 37 #include <semaphore.h> 38 #endif 39 40 #include <time.h> 41 42 #include "pcSyncProcessDataSingle.inline" 30 43 31 44 #include <libdodo/pcSyncProcessDataSingle.h> 45 #include <libdodo/pcSyncDataSingle.h> 46 #include <libdodo/pcSyncProcessDataSingleEx.h> 47 #include <libdodo/types.h> 48 #include <libdodo/toolsMisc.h> 49 #include <libdodo/toolsCode.h>; 32 50 33 51 using namespace dodo::pc::sync::process::data; 52 53 __semaphore::__semaphore() : 54 #ifdef XSI_IPC 55 keeper(-1) 56 #else 57 keeper(NULL) 58 #endif 59 { 60 } 61 62 //------------------------------------------------------------------- 34 63 35 64 single::single(single &sts) … … 42 71 autogenerated(false), 43 72 acquired(false), 44 #ifdef XSI_IPC 45 46 keeper(-1) 47 48 #else 49 50 keeper(NULL) 51 52 #endif 53 { 54 #ifdef XSI_IPC 55 73 semaphore(new __semaphore) 74 { 75 #ifdef XSI_IPC 56 76 if (a_key == 0) 57 77 { 58 key = tools::misc::iRandom();78 semaphore->key = tools::misc::iRandom(); 59 79 60 80 autogenerated = true; … … 62 82 else 63 83 { 64 key = a_key;65 } 66 67 operations[0].sem_num = 0;68 operations[0].sem_flg = 0;69 70 keeper = semget(key, 1, S_IRUSR | S_IWUSR | IPC_CREAT);71 if ( keeper == -1)84 semaphore->key = a_key; 85 } 86 87 semaphore->operations[0].sem_num = 0; 88 semaphore->operations[0].sem_flg = 0; 89 90 semaphore->keeper = semget(semaphore->key, 1, S_IRUSR | S_IWUSR | IPC_CREAT); 91 if (semaphore->keeper == -1) 72 92 { 73 93 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SINGLE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 74 94 } 75 95 76 control.val = 1;77 78 if (semctl( keeper, 0, SETVAL,control) == -1)96 semaphore->control.val = 1; 97 98 if (semctl(semaphore->keeper, 0, SETVAL, semaphore->control) == -1) 79 99 { 80 100 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SINGLE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 81 101 } 82 83 #else 84 85 key = '/'; 102 #else 103 semaphore->key = '/'; 86 104 87 105 if (a_key == 0) … … 90 108 tools::misc::random(_key, SH_KEY_SIZE / 2 - 1); 91 109 92 key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1)));110 semaphore->key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 93 111 94 112 autogenerated = true; … … 99 117 memcpy(_key, &a_key, 4); 100 118 101 key.append(tools::code::binToHex(dodoString(_key, 4)));102 } 103 104 keeper = sem_open(key.c_str(), O_CREAT, S_IRUSR | S_IWUSR, 1);105 if ( keeper == SEM_FAILED)119 semaphore->key.append(tools::code::binToHex(dodoString(_key, 4))); 120 } 121 122 semaphore->keeper = sem_open(semaphore->key.c_str(), O_CREAT, S_IRUSR | S_IWUSR, 1); 123 if (semaphore->keeper == SEM_FAILED) 106 124 { 107 125 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SINGLE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 108 126 } 109 110 127 #endif 111 128 } … … 116 133 autogenerated(false), 117 134 acquired(false), 118 #ifdef XSI_IPC 119 120 keeper(-1) 121 122 #else 123 124 keeper(NULL) 125 126 #endif 135 semaphore(new __semaphore) 127 136 { 128 137 } … … 133 142 { 134 143 #ifdef XSI_IPC 135 136 if (keeper != -1) 144 if (semaphore->keeper != -1) 137 145 { 138 146 if (autogenerated) 139 147 { 140 semctl( keeper, 0, IPC_RMID);148 semctl(semaphore->keeper, 0, IPC_RMID); 141 149 } 142 150 else … … 144 152 if (acquired) 145 153 { 146 operations[0].sem_op = 1; 147 148 semop(keeper, operations, 1); 149 } 150 } 151 } 152 #else 153 154 if (keeper != NULL) 154 semaphore->operations[0].sem_op = 1; 155 156 semop(semaphore->keeper, semaphore->operations, 1); 157 } 158 } 159 } 160 #else 161 if (semaphore->keeper != NULL) 155 162 { 156 163 if (acquired) 157 164 { 158 sem_post( keeper);159 } 160 161 sem_close( keeper);165 sem_post(semaphore->keeper); 166 } 167 168 sem_close(semaphore->keeper); 162 169 163 170 if (autogenerated) 164 171 { 165 sem_unlink(key.c_str()); 166 } 167 } 168 #endif 172 sem_unlink(semaphore->key.c_str()); 173 } 174 } 175 #endif 176 177 delete semaphore; 169 178 } 170 179 … … 175 184 { 176 185 #ifdef XSI_IPC 177 178 if (keeper != -1) 186 if (semaphore->keeper != -1) 179 187 { 180 188 if (autogenerated) 181 189 { 182 if (semctl( keeper, 0, IPC_RMID) == -1)190 if (semctl(semaphore->keeper, 0, IPC_RMID) == -1) 183 191 { 184 192 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 189 197 if (acquired) 190 198 { 191 operations[0].sem_op = 1;192 193 if (semop( keeper,operations, 1) == -1)199 semaphore->operations[0].sem_op = 1; 200 201 if (semop(semaphore->keeper, semaphore->operations, 1) == -1) 194 202 { 195 203 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 199 207 } 200 208 201 keeper = -1; 202 203 #else 204 205 if (keeper != NULL) 209 semaphore->keeper = -1; 210 #else 211 if (semaphore->keeper != NULL) 206 212 { 207 213 if (acquired) 208 214 { 209 if (sem_post( keeper) == -1)215 if (sem_post(semaphore->keeper) == -1) 210 216 { 211 217 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 213 219 } 214 220 215 if (sem_close( keeper) == -1)221 if (sem_close(semaphore->keeper) == -1) 216 222 { 217 223 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 220 226 if (autogenerated) 221 227 { 222 if (sem_unlink( key.c_str()))228 if (sem_unlink(semaphore->key.c_str())) 223 229 { 224 230 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 227 233 } 228 234 229 keeper = NULL; 230 235 semaphore->keeper = NULL; 231 236 #endif 232 237 } … … 240 245 241 246 #ifdef XSI_IPC 242 243 247 if (a_key == 0) 244 248 { 245 key = tools::misc::iRandom();249 semaphore->key = tools::misc::iRandom(); 246 250 247 251 autogenerated = true; … … 249 253 else 250 254 { 251 key = a_key;252 } 253 254 operations[0].sem_num = 0;255 operations[0].sem_flg = 0;256 257 keeper = semget(key, 1, S_IRUSR | S_IWUSR | IPC_CREAT);258 if ( keeper == -1)255 semaphore->key = a_key; 256 } 257 258 semaphore->operations[0].sem_num = 0; 259 semaphore->operations[0].sem_flg = 0; 260 261 semaphore->keeper = semget(semaphore->key, 1, S_IRUSR | S_IWUSR | IPC_CREAT); 262 if (semaphore->keeper == -1) 259 263 { 260 264 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 261 265 } 262 266 263 control.val = 1;264 265 if (semctl( keeper, 0, SETVAL,control) == -1)267 semaphore->control.val = 1; 268 269 if (semctl(semaphore->keeper, 0, SETVAL, semaphore->control) == -1) 266 270 { 267 271 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 268 272 } 269 270 #else 271 272 key = '/'; 273 #else 274 semaphore->key = '/'; 273 275 274 276 if (a_key == 0) … … 277 279 tools::misc::random(_key, SH_KEY_SIZE / 2 - 1); 278 280 279 key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1)));281 semaphore->key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 280 282 281 283 autogenerated = true; … … 286 288 memcpy(_key, &a_key, 4); 287 289 288 key.append(tools::code::binToHex(dodoString(_key, 4)));289 } 290 291 keeper = sem_open(key.c_str(), O_CREAT, S_IRUSR | S_IWUSR, 1);292 if ( keeper == SEM_FAILED)290 semaphore->key.append(tools::code::binToHex(dodoString(_key, 4))); 291 } 292 293 semaphore->keeper = sem_open(semaphore->key.c_str(), O_CREAT, S_IRUSR | S_IWUSR, 1); 294 if (semaphore->keeper == SEM_FAILED) 293 295 { 294 296 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 295 297 } 296 297 298 #endif 298 299 } … … 304 305 { 305 306 #ifdef XSI_IPC 306 307 307 int keeper = semget(a_key, 1, S_IRUSR | S_IWUSR); 308 308 if (keeper == -1) … … 315 315 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_REMOVE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 316 316 } 317 318 #else 319 317 #else 320 318 dodoString key = "/"; 321 319 … … 329 327 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_REMOVE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 330 328 } 331 332 329 #endif 333 330 } … … 339 336 { 340 337 #ifdef XSI_IPC 341 342 if (keeper == -1) 338 if (semaphore->keeper == -1) 343 339 { 344 340 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SET, exception::ERRNO_LIBDODO, SINGLEEX_NOTOPENED, PCSYNCPROCESSDATASINGLEEX_NOTOPENED_STR, __LINE__, __FILE__); 345 341 } 346 342 347 operations[0].sem_op = -1;348 349 if (semop( keeper,operations, 1) != 0)343 semaphore->operations[0].sem_op = -1; 344 345 if (semop(semaphore->keeper, semaphore->operations, 1) != 0) 350 346 { 351 347 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SET, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 354 350 data = a_data; 355 351 356 operations[0].sem_op = 1;357 358 if (semop( keeper,operations, 1) != 0)352 semaphore->operations[0].sem_op = 1; 353 354 if (semop(semaphore->keeper, semaphore->operations, 1) != 0) 359 355 { 360 356 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SET, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 361 357 } 362 363 #else 364 365 if (keeper == NULL) 358 #else 359 if (semaphore->keeper == NULL) 366 360 { 367 361 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SET, exception::ERRNO_LIBDODO, SINGLEEX_NOTOPENED, PCSYNCPROCESSDATASINGLEEX_NOTOPENED_STR, __LINE__, __FILE__); 368 362 } 369 363 370 if (sem_wait( keeper) != 0)364 if (sem_wait(semaphore->keeper) != 0) 371 365 { 372 366 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SET, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 375 369 data = a_data; 376 370 377 if (sem_post( keeper) != 0)371 if (sem_post(semaphore->keeper) != 0) 378 372 { 379 373 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_SET, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 380 374 } 381 382 375 #endif 383 376 } … … 397 390 { 398 391 #ifdef XSI_IPC 399 400 if (keeper == -1) 392 if (semaphore->keeper == -1) 401 393 { 402 394 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_ACQUIRE, exception::ERRNO_LIBDODO, SINGLEEX_NOTOPENED, PCSYNCPROCESSDATASINGLEEX_NOTOPENED_STR, __LINE__, __FILE__); … … 405 397 if (microseconds == 0) 406 398 { 407 operations[0].sem_op = -1;408 409 if (semop( keeper,operations, 1) != 0)399 semaphore->operations[0].sem_op = -1; 400 401 if (semop(semaphore->keeper, semaphore->operations, 1) != 0) 410 402 { 411 403 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_ACQUIRE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 416 408 bool locked = true; 417 409 unsigned long slept = 0; 418 419 operations[0].sem_op = -1; 420 operations[0].sem_flg = IPC_NOWAIT; 410 timespec timeout = {0, 10}; 411 412 semaphore->operations[0].sem_op = -1; 413 semaphore->operations[0].sem_flg = IPC_NOWAIT; 421 414 422 415 while (locked) 423 416 { 424 if (semop( keeper,operations, 1) != 0)417 if (semop(semaphore->keeper, semaphore->operations, 1) != 0) 425 418 { 426 419 if (errno != EAGAIN) 427 420 { 428 operations[0].sem_flg = 0;421 semaphore->operations[0].sem_flg = 0; 429 422 430 423 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_ACQUIRE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 433 426 if (nanosleep(&timeout, NULL) == -1) 434 427 { 435 operations[0].sem_flg = 0;428 semaphore->operations[0].sem_flg = 0; 436 429 437 430 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_ACQUIRE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 442 435 if (slept > microseconds) 443 436 { 444 operations[0].sem_flg = 0;437 semaphore->operations[0].sem_flg = 0; 445 438 446 439 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_ACQUIRE, exception::ERRNO_LIBDODO, SINGLEEX_CANNOTLOCK, PCSYNCPROCESSDATASINGLEEX_CANNOTLOCK_STR, __LINE__, __FILE__); … … 453 446 } 454 447 } 455 456 #else 457 458 if (keeper == NULL) 448 #else 449 if (semaphore->keeper == NULL) 459 450 { 460 451 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_ACQUIRE, exception::ERRNO_LIBDODO, SINGLEEX_NOTOPENED, PCSYNCPROCESSDATASINGLEEX_NOTOPENED_STR, __LINE__, __FILE__); … … 463 454 if (microseconds == 0) 464 455 { 465 if (sem_wait( keeper) != 0)456 if (sem_wait(semaphore->keeper) != 0) 466 457 { 467 458 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_ACQUIRE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 472 463 bool locked = true; 473 464 unsigned long slept = 0; 465 timespec timeout = {0, 10}; 474 466 475 467 while (locked) 476 468 { 477 if (sem_trywait( keeper) != 0)469 if (sem_trywait(semaphore->keeper) != 0) 478 470 { 479 471 if (errno != EAGAIN) … … 500 492 } 501 493 } 502 503 504 494 #endif 505 495 … … 515 505 { 516 506 #ifdef XSI_IPC 517 518 if (keeper == -1) 507 if (semaphore->keeper == -1) 519 508 { 520 509 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_RELEASE, exception::ERRNO_LIBDODO, SINGLEEX_NOTOPENED, PCSYNCPROCESSDATASINGLEEX_NOTOPENED_STR, __LINE__, __FILE__); 521 510 } 522 511 523 operations[0].sem_op = 1;524 525 if (semop( keeper,operations, 1) != 0)512 semaphore->operations[0].sem_op = 1; 513 514 if (semop(semaphore->keeper, semaphore->operations, 1) != 0) 526 515 { 527 516 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_RELEASE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 528 517 } 529 530 #else 531 532 if (keeper == NULL) 518 #else 519 if (semaphore->keeper == NULL) 533 520 { 534 521 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_RELEASE, exception::ERRNO_LIBDODO, SINGLEEX_NOTOPENED, PCSYNCPROCESSDATASINGLEEX_NOTOPENED_STR, __LINE__, __FILE__); 535 522 } 536 523 537 if (sem_post( keeper) != 0)524 if (sem_post(semaphore->keeper) != 0) 538 525 { 539 526 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSDATASINGLE, SINGLEEX_RELEASE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 540 527 } 541 542 528 #endif 543 529 -
trunk/src/pcSyncProcessSection.cc
r1186 r1187 28 28 */ 29 29 30 #include <libdodo/directives.h> 31 32 #ifdef XSI_IPC 33 #include <sys/ipc.h> 34 #include <sys/sem.h> 35 #else /*POSIX_SEMAPHORES*/ 36 #include <fcntl.h> 37 #include <semaphore.h> 38 #endif 39 40 #include "pcSyncProcessDataSingle.inline" 41 30 42 #include <libdodo/pcSyncProcessSection.h> 43 #include <libdodo/pcSyncSection.h> 44 #include <libdodo/toolsMisc.h> 45 #include <libdodo/toolsCode.h> 46 #include <libdodo/pcSyncProcessSectionEx.h> 47 #include <libdodo/types.h> 31 48 32 49 using namespace dodo::pc::sync::process; … … 40 57 section::section(int a_key) : autogenerated(false), 41 58 acquired(false), 42 #ifdef XSI_IPC 43 44 keeper(-1) 45 46 #else 47 48 keeper(NULL) 49 50 #endif 51 { 52 #ifdef XSI_IPC 53 59 semaphore(new pc::sync::process::data::__semaphore) 60 { 61 #ifdef XSI_IPC 54 62 if (a_key == 0) 55 63 { 56 key = tools::misc::iRandom();64 semaphore->key = tools::misc::iRandom(); 57 65 58 66 autogenerated = true; … … 63 71 } 64 72 65 operations[0].sem_num = 0;66 67 operations[0].sem_flg = 0;68 69 keeper = semget(key, 1, S_IRUSR | S_IWUSR | IPC_CREAT);70 if ( keeper == -1)73 semaphore->operations[0].sem_num = 0; 74 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) 71 79 { 72 80 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_SECTION, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 73 81 } 74 82 75 control.val = 1;76 77 if (semctl( keeper, 0, SETVAL,control) == -1)83 semaphore->control.val = 1; 84 85 if (semctl(semaphore->keeper, 0, SETVAL, semaphore->control) == -1) 78 86 { 79 87 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_SECTION, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 80 88 } 81 82 #else 83 84 key = '/'; 89 #else 90 semaphore->key = '/'; 85 91 86 92 if (a_key == 0) … … 89 95 tools::misc::random(_key, SH_KEY_SIZE / 2 - 1); 90 96 91 key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1)));97 semaphore->key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 92 98 93 99 autogenerated = true; … … 98 104 memcpy(_key, &a_key, 4); 99 105 100 key.append(tools::code::binToHex(dodoString(_key, 4)));101 } 102 103 keeper = sem_open(key.c_str(), O_CREAT, S_IRUSR | S_IWUSR, 1);104 if ( keeper == SEM_FAILED)106 semaphore->key.append(tools::code::binToHex(dodoString(_key, 4))); 107 } 108 109 semaphore->keeper = sem_open(semaphore->key.c_str(), O_CREAT, S_IRUSR | S_IWUSR, 1); 110 if (semaphore->keeper == SEM_FAILED) 105 111 { 106 112 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_SECTION, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 107 113 } 108 109 114 #endif 110 115 } … … 114 119 section::section() : autogenerated(false), 115 120 acquired(false), 116 #ifdef XSI_IPC 117 118 keeper(-1) 119 120 #else 121 122 keeper(NULL) 123 124 #endif 121 semaphore(new pc::sync::process::data::__semaphore) 125 122 { 126 123 } … … 131 128 { 132 129 #ifdef XSI_IPC 133 134 if (keeper != -1) 130 if (semaphore->keeper != -1) 135 131 { 136 132 if (autogenerated) 137 133 { 138 semctl( keeper, 0, IPC_RMID);134 semctl(semaphore->keeper, 0, IPC_RMID); 139 135 } 140 136 else … … 142 138 if (acquired) 143 139 { 144 operations[0].sem_op = 1; 145 146 semop(keeper, operations, 1); 147 } 148 } 149 } 150 151 #else 152 153 if (keeper != NULL) 140 semaphore->operations[0].sem_op = 1; 141 142 semop(semaphore->keeper, semaphore->operations, 1); 143 } 144 } 145 } 146 #else 147 if (semaphore->keeper != NULL) 154 148 { 155 149 if (acquired) 156 150 { 157 sem_post( keeper);158 } 159 160 sem_close( keeper);151 sem_post(semaphore->keeper); 152 } 153 154 sem_close(semaphore->keeper); 161 155 162 156 if (autogenerated) 163 157 { 164 sem_unlink(key.c_str()); 165 } 166 } 167 168 #endif 158 sem_unlink(semaphore->key.c_str()); 159 } 160 } 161 #endif 162 163 delete semaphore; 169 164 } 170 165 … … 175 170 { 176 171 #ifdef XSI_IPC 177 178 if (keeper != -1) 172 if (semaphore->keeper != -1) 179 173 { 180 174 if (autogenerated) 181 175 { 182 if (semctl( keeper, 0, IPC_RMID) == -1)176 if (semctl(semaphore->keeper, 0, IPC_RMID) == -1) 183 177 { 184 178 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 188 182 if (acquired) 189 183 { 190 operations[0].sem_op = 1;191 192 if (semop( keeper,operations, 1) == -1)184 semaphore->operations[0].sem_op = 1; 185 186 if (semop(semaphore->keeper, semaphore->operations, 1) == -1) 193 187 { 194 188 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 199 193 } 200 194 201 keeper = -1; 202 203 #else 204 205 if (keeper != NULL) 195 semaphore->keeper = -1; 196 #else 197 if (semaphore->keeper != NULL) 206 198 { 207 199 if (acquired) 208 200 { 209 if (sem_post( keeper) == -1)201 if (sem_post(semaphore->keeper) == -1) 210 202 { 211 203 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 213 205 } 214 206 215 if (sem_close( keeper) == -1)207 if (sem_close(semaphore->keeper) == -1) 216 208 { 217 209 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 220 212 if (autogenerated) 221 213 { 222 if (sem_unlink( key.c_str()) == -1)214 if (sem_unlink(semaphore->key.c_str()) == -1) 223 215 { 224 216 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 227 219 } 228 220 229 keeper = NULL; 230 221 semaphore->keeper = NULL; 231 222 #endif 232 223 } … … 240 231 241 232 #ifdef XSI_IPC 242 243 233 if (a_key == 0) 244 234 { 245 key = tools::misc::iRandom();235 semaphore->key = tools::misc::iRandom(); 246 236 247 237 autogenerated = true; … … 249 239 else 250 240 { 251 key = a_key;252 } 253 254 operations[0].sem_num = 0;255 operations[0].sem_flg = 0;256 257 keeper = semget(key, 1, S_IRUSR | S_IWUSR | IPC_CREAT);258 if ( keeper == -1)241 semaphore->key = a_key; 242 } 243 244 semaphore->operations[0].sem_num = 0; 245 semaphore->operations[0].sem_flg = 0; 246 247 semaphore->keeper = semget(semaphore->key, 1, S_IRUSR | S_IWUSR | IPC_CREAT); 248 if (semaphore->keeper == -1) 259 249 { 260 250 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 261 251 } 262 252 263 control.val = 1;264 265 if (semctl( keeper, 0, SETVAL,control) == -1)253 semaphore->control.val = 1; 254 255 if (semctl(semaphore->keeper, 0, SETVAL, semaphore->control) == -1) 266 256 { 267 257 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 268 258 } 269 270 #else 271 272 key = '/'; 259 #else 260 semaphore->key = '/'; 273 261 274 262 if (a_key == 0) … … 277 265 tools::misc::random(_key, SH_KEY_SIZE / 2 - 1); 278 266 279 key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1)));267 semaphore->key.append(tools::code::binToHex(dodoString(_key, SH_KEY_SIZE / 2 - 1))); 280 268 281 269 autogenerated = true; … … 286 274 memcpy(_key, &a_key, 4); 287 275 288 key.append(tools::code::binToHex(dodoString(_key, 4)));289 } 290 291 keeper = sem_open(key.c_str(), O_CREAT, S_IRUSR | S_IWUSR, 1);292 if ( keeper == SEM_FAILED)276 semaphore->key.append(tools::code::binToHex(dodoString(_key, 4))); 277 } 278 279 semaphore->keeper = sem_open(semaphore->key.c_str(), O_CREAT, S_IRUSR | S_IWUSR, 1); 280 if (semaphore->keeper == SEM_FAILED) 293 281 { 294 282 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 295 283 } 296 297 284 #endif 298 285 } … … 304 291 { 305 292 #ifdef XSI_IPC 306 307 293 int keeper = semget(a_key, 1, S_IRUSR | S_IWUSR); 308 294 if (keeper == -1) … … 315 301 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_REMOVE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 316 302 } 317 318 #else 319 303 #else 320 304 dodoString key = "/"; 321 305 … … 329 313 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_REMOVE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 330 314 } 331 332 315 #endif 333 316 } … … 339 322 { 340 323 #ifdef XSI_IPC 341 342 if (keeper == -1) 324 if (semaphore->keeper == -1) 343 325 { 344 326 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_ACQUIRE, exception::ERRNO_LIBDODO, SECTIONEX_NOTOPENED, PCSYNCPROCESSSECTIONEX_NOTOPENED_STR, __LINE__, __FILE__); 345 327 } 346 328 347 operations[0].sem_op = -1;348 349 if (semop( keeper,operations, 1) != 0)329 semaphore->operations[0].sem_op = -1; 330 331 if (semop(semaphore->keeper, semaphore->operations, 1) != 0) 350 332 { 351 333 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_ACQUIRE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 352 334 } 353 354 #else 355 356 if (keeper == NULL) 335 #else 336 if (semaphore->keeper == NULL) 357 337 { 358 338 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_ACQUIRE, exception::ERRNO_LIBDODO, SECTIONEX_NOTOPENED, PCSYNCPROCESSSECTIONEX_NOTOPENED_STR, __LINE__, __FILE__); 359 339 } 360 340 361 if (sem_wait( keeper) != 0)341 if (sem_wait(semaphore->keeper) != 0) 362 342 { 363 343 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_ACQUIRE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 364 344 } 365 366 345 #endif 367 346 … … 375 354 { 376 355 #ifdef XSI_IPC 377 378 if (keeper == -1) 356 if (semaphore->keeper == -1) 379 357 { 380 358 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_RELEASE, exception::ERRNO_LIBDODO, SECTIONEX_NOTOPENED, PCSYNCPROCESSSECTIONEX_NOTOPENED_STR, __LINE__, __FILE__); 381 359 } 382 360 383 operations[0].sem_op = 1;384 385 if (semop( keeper,operations, 1) != 0)361 semaphore->operations[0].sem_op = 1; 362 363 if (semop(semaphore->keeper, semaphore->operations, 1) != 0) 386 364 { 387 365 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_RELEASE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 388 366 } 389 390 #else 391 392 if (keeper == NULL) 367 #else 368 369 if (semaphore->keeper == NULL) 393 370 { 394 371 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_RELEASE, exception::ERRNO_LIBDODO, SECTIONEX_NOTOPENED, PCSYNCPROCESSSECTIONEX_NOTOPENED_STR, __LINE__, __FILE__); 395 372 } 396 373 397 if (sem_post( keeper) != 0)374 if (sem_post(semaphore->keeper) != 0) 398 375 { 399 376 throw exception::basic(exception::ERRMODULE_PCSYNCPROCESSSECTION, SECTIONEX_RELEASE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 400 377 } 401 402 378 #endif 403 379 -
trunk/tests/pcprocesscollection_test/test.cc
r1161 r1187 12 12 #include <libdodo/dataMemoryShared.h> 13 13 #include <libdodo/pcSyncProcessDataSingle.h> 14 #include <libdodo/pcSyncProcessSection.h> 14 15 #include <libdodo/pcSyncProcessDataCollection.h> 15 16 #include <libdodo/pcSyncProtector.h>
Note: See TracChangeset
for help on using the changeset viewer.
