Worker* multask_createWorker(){ Worker* worker=newWorker(); if(worker!=NULL){ initWorker(worker); } return worker; }
void ExiftoolImageWritingWorker::process() { Helpers::AsyncCoordinatorUnlocker unlocker(m_AsyncCoordinator); Q_UNUSED(unlocker); bool success = false; initWorker(); QTemporaryFile jsonFile; if (jsonFile.open()) { LOG_INFO << "Serializing artworks to json" << jsonFile.fileName(); QJsonArray objectsToSave; artworksToJsonArray(m_ItemsToWriteSnapshot, objectsToSave); QJsonDocument document(objectsToSave); jsonFile.write(document.toJson()); jsonFile.flush(); jsonFile.close(); int numberOfItems = (int)m_ItemsToWriteSnapshot.size(); QTemporaryFile argumentsFile; if (argumentsFile.open()) { QStringList exiftoolArguments = createArgumentsList(jsonFile.fileName()); foreach (const QString &line, exiftoolArguments) { argumentsFile.write(line.toUtf8()); #ifdef Q_OS_WIN argumentsFile.write("\r\n"); #else argumentsFile.write("\n"); #endif }
void Initializer::initWorkerWatcher(const std::string& name) const { if (isWorker()) { initWorker(name); } else { // The watcher will forever monitor and spawn additional workers. initWatcher(); } }
Worker * createWorker(int id, Channel * order_channel){ Worker * wp; wp = ntmalloc(sizeof (Worker)); if (wp == NULL){ ntLogging(LOG_FATAL,"create worker failed"); return NULL; } if (WORKER_ERR == initWorker(wp, id, order_channel)){ ntLogging(LOG_FATAL,"create worker failed"); return NULL; } return wp; }
void MetadataReadingWorker::process() { bool success = false; initWorker(); QTemporaryFile argumentsFile; if (argumentsFile.open()) { LOG_INFO << "Created arguments file" << argumentsFile.fileName(); QStringList exiftoolArguments = createArgumentsList(); foreach (const QString &line, exiftoolArguments) { argumentsFile.write(line.toUtf8()); #ifdef Q_OS_WIN argumentsFile.write("\r\n"); #else argumentsFile.write("\n"); #endif }
void Process::run() { if (tnt::TntConfig::it().daemon) { log_debug("run daemon-mode"); // We receive the writing-end of the notify pipe. // After successful initialization we need to write a byte to this fd. cxxtools::posix::Pipe mainPipe; cxxtools::posix::Fork fork; if (fork.parent()) { log_debug("close write-fd of main-pipe"); mainPipe.closeWriteFd(); log_debug("wait for child to initialize"); mainPipe.read(); log_debug("child initialized"); fork.setNowait(); } else { log_debug("close read-fd of main-pipe"); mainPipe.closeReadFd(); runMonitor(mainPipe); } } else { log_debug("run"); initWorker(); log_debug("do work"); doWork(); } }
static EjsWorker *workerConstructor(Ejs *ejs, EjsWorker *worker, int argc, EjsObj **argv) { EjsArray *search; EjsObj *options, *value; cchar *name, *scriptFile; ejsBlockGC(ejs); scriptFile = (argc >= 1 && argv[0] != ESV(null)) ? ((EjsPath*) argv[0])->value : 0; options = (argc == 2 && argv[1] != ESV(null)) ? (EjsObj*) argv[1]: NULL; name = 0; search = 0; if (options) { search = ejsGetPropertyByName(ejs, options, EN("search")); value = ejsGetPropertyByName(ejs, options, EN("name")); if (ejsIs(ejs, value, String)) { name = ejsToMulti(ejs, value); } } worker->ejs = ejs; worker->state = EJS_WORKER_BEGIN; return initWorker(ejs, worker, 0, name, search, scriptFile); }
/* static function fork(): Worker */ static EjsWorker *workerFork(Ejs *ejs, EjsWorker *unused, int argc, EjsObj **argv) { return initWorker(ejs, 0, ejs, 0, 0, 0); }
/* function clone(deep: Boolean = null): Worker */ static EjsWorker *workerClone(Ejs *ejs, EjsWorker *baseWorker, int argc, EjsObj **argv) { return initWorker(ejs, 0, baseWorker->pair->ejs, 0, 0, 0); }
void Process::runMonitor(cxxtools::posix::Pipe& mainPipe) { log_debug("run monitor"); // setsid if (setsid() == -1) throw cxxtools::SystemError("setsid"); bool first = true; while (true) { cxxtools::posix::Pipe monitorPipe; cxxtools::posix::Fork fork; if (fork.child()) { // worker-process log_debug("close read-fd of monitor-pipe"); monitorPipe.closeReadFd(); initWorker(); if (first) { log_debug("signal initialization ready"); mainPipe.write('1'); log_debug("close write-fd of main-pipe"); mainPipe.closeWriteFd(); } log_debug("close standard-handles"); closeStdHandles(tnt::TntConfig::it().errorLog); _exitRestart = false; log_debug("do work"); doWork(); // normal shutdown if (_exitRestart) log_debug("restart"); else { log_debug("signal shutdown"); try { monitorPipe.write('s'); } catch (const std::exception& e) { log_debug("ingore exception from monitor pipe: " << e.what()); } } return; } // monitor-process log_debug("write pid " << fork.getPid() << " to \"" << tnt::TntConfig::it().pidfile << '"'); PidFile p(tnt::TntConfig::it().pidfile, fork.getPid()); if (first) { log_debug("close standard-handles"); closeStdHandles(); first = false; } monitorPipe.closeWriteFd(); try { log_debug("monitor child"); char dummy; size_t c = monitorPipe.read(&dummy, 1); if (c > 0) { log_debug("child terminated normally"); return; } log_debug("nothing read from monitor-pipe - restart child"); } catch (const cxxtools::SystemError&) { log_debug("child exited without notification"); } log_debug("wait for child-termination"); fork.wait(); ::sleep(1); } }