inline void Repeat<Func>::operator ( )(unsigned count) { for (unsigned i = 0; i < count; ++i) { function_( ); } }
bool rs::jsapi::Global::CallFunction(JSContext* cx, unsigned argc, JS::Value* vp) { JSAutoRequest ar(cx); auto args = JS::CallArgsFromVp(argc, vp); auto state = Global::GetFunctionState(&args.callee(), cx, privateFunctionStatePropertyName_); if (state) { try { static thread_local std::vector<Value> vArgs; VectorUtils::ScopedVectorCleaner<Value> clean(vArgs); for (int i = 0; i < argc; ++i) { vArgs.emplace_back(cx, args.get(i)); } Value result(cx); state->function_(vArgs, result); args.rval().set(result); return true; } catch (const std::exception& ex) { JS_ReportError(cx, ex.what()); return false; } } else { JS_ReportError(cx, "Unable to find function callback in libjsapi object"); return false; } }
void testfn_t::run() { if (before_) before_->run(); if (role_ == RTEST) { if (testrunner_t::current_->verbose_) fprintf(stderr, "Test %s:%s\n", suite(), name_); function_(); } else { int (*fixture)(void) = (int(*)(void))function_; if (testrunner_t::current_->verbose_) fprintf(stderr, "Fixture %s:%s\n", suite(), name_); if (fixture()) { fprintf(stderr, "%s:%s: fixture failed\n", suite(), name_); exit(1); } } if (after_) after_->run(); }
ReturnType operator()(Args... args) { if (!function_) { Load(); } return function_(args...); }
// Attempts to call the function. // If the function is locked, the call gets postponed. // NOTE: Only single call is made when the function becomes unlocked, // even if multiple call attempts were made while it was in the locked state. void operator ()() { if (locks_) { charged_ = true; return; } function_(); }
// Unlocks the function. // When the number of locks compensated with unlocks reaches zero, // a postponed call (if any was requested) is made. void unlock() { --locks_; assert(locks_ >= 0); if (locks_ > 0) return; // The function is still locked. if (!charged_) return; // There were no call requests. charged_ = false; function_(); }
result_type operator()( Index ) const { return function_( fcppt::tag< typename boost::mpl::at< Sequence, Index >::type >() ); }
void plotter::writedaten_() { double xwert = xmin_; double ywert; std::ofstream datei((pfad_ + name_ + ".dat").c_str()); for (int i = 0; i < schritte_; i++) { ywert = function_(xwert); datei << xwert << " " << ywert << std::endl; xwert += schrittweite_; } datei.close(); }
void GlobalExceptionHandler::terminate() throw() { // add cerr to the log stream // and write all available information on // the exception to the log stream (potentially with an assigned file!) // and cerr std::cout << std::endl; std::cout << "---------------------------------------------------" << std::endl; std::cout << "FATAL: uncaught exception!" << std::endl; std::cout << "---------------------------------------------------" << std::endl; if ((line_() != -1) && (name_() != "unknown")) { std::cout << "last entry in the exception handler: " << std::endl; std::cout << "exception of type " << name_().c_str() << " occured in line " << line_() << ", function " << function_() << " of " << file_().c_str() << std::endl; std::cout << "error message: " << what_().c_str() << std::endl; } std::cout << "---------------------------------------------------" << std::endl; #ifndef OPENMS_WINDOWSPLATFORM // if the environment variable declared in OPENMS_CORE_DUMP_ENVNAME // is set, provoke a core dump (this is helpful to get a stack traceback) if (getenv(OPENMS_CORE_DUMP_ENVNAME) != 0) { #ifdef OPENMS_HAS_KILL std::cout << "dumping core file.... (to avoid this, unset " << OPENMS_CORE_DUMP_ENVNAME << " in your environment)" << std::endl; // provoke a core dump kill(getpid(), SIGSEGV); #endif } #endif // otherwise exit as default terminate() would: abort(); }
void Work::run() { // do work in implementation function_( *this ); }
void operator()() { *pReturn_ = function_(); }
void WordOperandOperation::Run() { function_(s_, operand_); }
~log_instance() { function_( os_->str().c_str(), log_level ); delete os_; }
inline std::ostream &ManipulatorTwo<Function, ArgumentOne, ArgumentTwo>:: operator( )(std::ostream &stream) const { return function_(stream, argumentOne_, argumentTwo_); }
// implement AsyncUriHandlerFunction concept void operator()(boost::shared_ptr<AsyncConnection> pConnection) const { function_(pConnection); }
int FixedSet::Bucket::GetIndex(int element) const { return function_(element) % elements_.size(); }
void function(void) { int *tmp = (int *)pthread_getspecific(pkey); printf("%d is runing in %s\n", *tmp, __FUNCTION__); function_(*tmp); }
inline std::ostream & ManipulatorOne<Function, Argument>::operator( )(std::ostream &stream) const { return function_(stream, argument_); }
int Process::start() { logTrace("Process::start"); int childIn[2] = { -1, -1 }; int childOut[2] = { -1, -1 }; int childErr[2] = { -1, -1 }; // // We either have 2 parameters and this process // will exec() a new command, or we have one or // none and this process will yield control to // a function. // if (function_ == NULL && (parameters_[0] == NULL || parameters_[1] == NULL)) { logTest("Process::start", "Can't start the process " "without a command or function"); logError("Process::start", ESET(EPERM)); return -1; } #ifdef TEST if (function_ == NULL) { logTest("Process::start", "Executing command '%s'", parameters_[0]); for (int i = 1; i < parametersLimit_ && parameters_[i] != NULL; i++) { logTest("Process::start", "Parameter [%d] is '%s'", i, parameters_[i]); } } else { logTest("Process::start", "Executing function at %p", function_); logTest("Process::start", "Passing data as %p", parameters_[0]); } for (int i = 0; i < environmentLimit_ && environment_[i] != NULL; i++) { logTest("Process::start", "Environment [%d] is '%s'", i, environment_[i]); } #endif // // Create the pipes that will be used to replace // the standard descriptors. // if ((in_ == -1 && pipe(childIn) != 0) || (out_ == -1 && pipe(childOut) != 0) || (err_ == -1 && pipe(childErr) != 0)) { logError("Process::start::pipe", EGET()); return -1; } // // The fork() on Cygwin can show intermittent // failures. In this case we try again after // some time. // #ifdef __CYGWIN32__ switch (pid_ = waitFork()) #else switch (pid_ = fork()) #endif { case -1: { // // An error was encountered. // logError("Process::start::fork", EGET()); if (in_ == -1) { close(childIn[0]); close(childIn[1]); } if (out_ == -1) { close(childOut[0]); close(childOut[1]); } if (err_ == -1) { close(childErr[0]); close(childErr[1]); } return -1; } case 0: { // // We are the child process. // logTest("Process::start", "Child running with pid %d", getpid()); // // Drop the privileges. // if (privileged_ != 1) { logTest("Process::start", "Child dropping the permissions"); setgid(getgid()); setuid(getuid()); } // // Let the input descriptor inherited from the // parent replace the standard descriptors. The // descriptor can be either the one set by the // parent or our end of the pipe we created be- // fore forking. // // Handle the standard input. // if (in_ == -1) { logTest("Process::start", "Child replacing pipe " "%d and %d for input", childIn[0], childIn[1]); if (childIn[0] != 0) { dup2(childIn[0], 0); close(childIn[0]); } close(childIn[1]); } else if (in_ != 0) { logTest("Process::start", "Child replacing input %d", in_); dup2(in_, 0); if (in_ != out_ && in_ != err_) { close(in_); } } else { logTest("Process::start", "Child inherited input"); } in_ = 0; // // Handle the standard output. // if (out_ == -1) { logTest("Process::start", "Child replacing pipe " "%d and %d for output", childOut[0], childOut[1]); if (childOut[1] != 1) { dup2(childOut[1], 1); close(childOut[1]); } close(childOut[0]); } else if (out_ != 1) { logTest("Process::start", "Child replacing output %d", out_); dup2(out_, 1); if (out_ != err_) { close(out_); } } else { logTest("Process::start", "Child inherited output"); } out_ = 1; // // Handle the standard error. // if (err_ == -1) { logTest("Process::start", "Child replacing pipe " "%d and %d for error", childErr[0], childErr[1]); if (childErr[1] != 2) { dup2(childErr[1], 2); close(childErr[1]); } close(childErr[0]); } else if (err_ != 2) { logTest("Process::start", "Child replacing error %d", err_); dup2(err_, 2); close(err_); } else { logTest("Process::start", "Child inherited error"); } err_ = 2; // // Let the pid be our own pid. // pid_ = getpid(); logTest("Process::start", "Child has descriptors " "%d, %d, %d and pid %d", in_, out_, err_, pid_); // // Set the new environment for the process. // for (int i = 0; i < environmentLimit_ && environment_[i] != NULL; i++) { putenv(environment_[i]); } // // Either execute the requested command or // yield control to the function. // if (parameters_[1] != NULL) { if (execvp(parameters_[0], parameters_ + 1) == -1) { logTest("Process::start", "Child failed to execute the command"); logError("Process::start::execvp", EGET()); } exitStatus(-1); } else { int result = function_((void *) parameters_[0]); exitStatus(result); } } default: { // // We are the parent process. // logTest("Process::start", "Parent started child with pid %d", pid_); if (in_ == -1) { close(childIn[0]); in_ = childIn[1]; } if (out_ == -1) { close(childOut[1]); out_ = childOut[0]; } if (err_ == -1) { close(childErr[1]); err_ = childErr[0]; } logTest("Process::start", "Parent using descriptors %d, %d, %d", in_, out_, err_); return 1; } } }
ResultType get() { return function_(originalSource_->get()); }
void finish_vertex(const Vertex& u, const Graph& g) { const auto o(g[u]); if (o.id() != grapher::root_id()) function_(std::cref(o)); }
void RestartOperation::Run() { function_(s_); }
virtual void draw_cell( Fl_Table::TableContext ctx, int r, int c, int x, int y, int w, int h) { if (function_) { function_(ctx, r, c, x, y, w, h); } }