Changeset 1539
- Timestamp:
- 07/20/05 05:48:14 (3 years ago)
- Files:
-
- hydranode/hncore/plugins/ed2k/src/downloadlist.cpp (modified) (2 diffs)
- hydranode/hncore/src/fileslist.cpp (modified) (4 diffs)
- hydranode/hncore/src/hydranode.cpp (modified) (3 diffs)
- hydranode/include/hncore/workthread.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
hydranode/hncore/plugins/ed2k/src/downloadlist.cpp
r1501 r1539 304 304 using namespace boost::filesystem; 305 305 306 WorkThread:: instance().pause();306 WorkThread::Pauser pauser; 307 307 308 308 for (directory_iterator it(p); it != directory_iterator(); ++it) { … … 319 319 } 320 320 } 321 322 WorkThread::instance().resume();323 321 } 324 322 hydranode/hncore/src/fileslist.cpp
r1501 r1539 94 94 CHECK_THROW(!path.empty()); 95 95 verifyPath(path); 96 97 WorkThread::Pauser pauser; // pause WorkThread while scanning 98 96 99 scanSharedDir(path, recurse); 100 97 101 } catch (std::exception &e) { 98 102 logError(boost::format("Error scanning shared directory: %s")%e.what()); … … 106 110 107 111 if (scan) { 112 WorkThread::Pauser pauser; // pause while scanning 108 113 scanTempDir(p.native_directory_string()); 109 114 } … … 191 196 192 197 if (recursion == 1) { 193 WorkThread::instance().pause();194 198 logMsg( 195 199 boost::format("Scanning shared directory %s %s") … … 236 240 } 237 241 recursion--; 238 if (recursion == 0) {239 WorkThread::instance().resume();240 }241 242 } catch (std::exception &er) { 242 243 logError(boost::format("Scanning shared directories: %s") % er.what()); 243 244 recursion--; 244 if (recursion == 0) {245 WorkThread::instance().resume();246 }247 245 } 248 246 MSVC_ONLY(;) hydranode/hncore/src/hydranode.cpp
r1532 r1539 90 90 initSockets(); 91 91 Log::instance().remPreStr(" "); 92 93 // starting from here, we get to resource-intensive parts, so make sure 94 // workthread doesn't start IO things before we'r finished with startup 95 WorkThread::Pauser p; 92 96 93 97 logMsg(" * Initializing Shared Files List..."); … … 475 479 return false; 476 480 } 477 #ifndef WIN32478 if (vm.count("background")) {479 init(s_argc, s_argv);480 logMsg("Backgrounding...");481 482 // redirect stdout/stderr etc to /dev/null483 close(0); close(1); close(2);484 SchedBase::instance().disableStatus();485 Log::instance().disableOutput();486 int fd = open("/dev/null", O_RDWR);487 dup(fd); dup(fd); dup(fd);488 489 int pid = fork();490 if (pid < 0) {491 perror("fork() failed: ");492 ::exit(1);493 } else if (pid == 0) {494 setsid();495 mainLoop();496 cleanUp();497 }498 499 return false;500 }501 #endif502 481 if (vm.count("disable-status")) { 503 482 SchedBase::instance().disableStatus(); … … 560 539 #endif 561 540 541 // do backgrounding stuff after all other args have been processed 542 #ifndef WIN32 543 if (vm.count("background")) { 544 545 int pid = fork(); 546 if (pid < 0) { 547 perror("fork() failed: "); 548 ::exit(1); 549 } else if (pid == 0) { 550 setsid(); 551 init(s_argc, s_argv); 552 553 logMsg("Backgrounding..."); 554 555 // redirect stdout/stderr etc to /dev/null 556 close(0); close(1); close(2); 557 SchedBase::instance().disableStatus(); 558 Log::instance().disableOutput(); 559 int fd = open("/dev/null", O_RDWR); 560 dup(fd); dup(fd); dup(fd); 561 562 mainLoop(); 563 cleanUp(); 564 } 565 566 return false; 567 } 568 #endif 569 562 570 return true; 563 571 } catch (std::exception &e) { hydranode/include/hncore/workthread.h
r1501 r1539 94 94 95 95 /** 96 * Pause the thread execution97 */98 void pause();99 100 /**101 * Resume the thread execution102 */103 void resume();104 105 /**106 96 * Check whether the thread is running or paused 107 97 * … … 109 99 */ 110 100 bool isRunning(); 101 102 /** 103 * Exception-safe wrapper object for pausing/resuming WorkThread 104 */ 105 struct Pauser { 106 Pauser() { 107 instance().pause(); 108 } 109 ~Pauser() { 110 instance().resume(); 111 } 112 }; 113 111 114 private: 112 115 /** … … 122 125 //! Main work thread loop function 123 126 void threadLoop(); 127 124 128 //! Used by secondary thread, this is used to check whether the thread 125 129 //! should exit 126 130 bool checkExit(); 131 127 132 //! Used by main thread, this signals work thread to exit ASAP 128 133 void exit(); 134 135 //! Pause the thread execution 136 void pause(); 137 138 //! Resume the thread execution 139 void resume(); 140 129 141 130 142 //! Pending jobs queue, filled by postWork() and processed by
