MCPcopy Create free account
hub / github.com/apple/foundationdb / run

Method run

flow/Net2.actor.cpp:1431–1649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1429#endif
1430
1431void Net2::run() {
1432 TraceEvent::setNetworkThread();
1433 TraceEvent("Net2Running").log();
1434
1435 thread_network = this;
1436
1437 unsigned int tasksSinceReact = 0;
1438
1439#ifdef WIN32
1440 if (timeBeginPeriod(1) != TIMERR_NOERROR)
1441 TraceEvent(SevError, "TimeBeginPeriodError").log();
1442#endif
1443
1444 timeOffsetLogger = logTimeOffset();
1445 const char* flow_profiler_enabled = getenv("FLOW_PROFILER_ENABLED");
1446 if (flow_profiler_enabled != nullptr && *flow_profiler_enabled != '\0') {
1447 // The empty string check is to allow running `FLOW_PROFILER_ENABLED= ./fdbserver` to force disabling flow
1448 // profiling at startup.
1449 startProfiling(this);
1450 }
1451
1452 // Get the address to the launch function
1453 typedef void (*runCycleFuncPtr)();
1454 runCycleFuncPtr runFunc = reinterpret_cast<runCycleFuncPtr>(
1455 reinterpret_cast<flowGlobalType>(g_network->global(INetwork::enRunCycleFunc)));
1456
1457 started.store(true);
1458 double nnow = timer_monotonic();
1459
1460 while (!stopped) {
1461 FDB_TRACE_PROBE(run_loop_begin);
1462 ++countRunLoop;
1463
1464 if (runFunc) {
1465 tscBegin = timestampCounter();
1466 taskBegin = nnow;
1467 trackAtPriority(TaskPriority::RunCycleFunction, taskBegin);
1468 runFunc();
1469 double taskEnd = timer_monotonic();
1470 trackAtPriority(TaskPriority::RunLoop, taskEnd);
1471 countLaunchTime += taskEnd - taskBegin;
1472 checkForSlowTask(tscBegin, timestampCounter(), taskEnd - taskBegin, TaskPriority::RunCycleFunction);
1473 }
1474
1475 double sleepTime = 0;
1476 bool b = ready.empty();
1477 if (b) {
1478 b = threadReady.canSleep();
1479 if (!b)
1480 ++countCantSleep;
1481 } else
1482 ++countWontSleep;
1483 if (b) {
1484 sleepTime = 1e99;
1485 double sleepStart = timer_monotonic();
1486 if (!timers.empty()) {
1487 sleepTime = timers.top().at - sleepStart; // + 500e-6?
1488 }

Callers

nothing calls this directly

Calls 15

TraceEventClass · 0.85
startProfilingFunction · 0.85
timer_monotonicFunction · 0.85
timestampCounterFunction · 0.85
nondeterministicRandomFunction · 0.85
check_yieldFunction · 0.85
format_backtraceFunction · 0.85
fnFunction · 0.85
canSleepMethod · 0.80
sleepMethod · 0.80
reactMethod · 0.80
random01Method · 0.80

Tested by

no test coverage detected