MCPcopy Create free account
hub / github.com/chronoxor/CppBenchmark / StartPhaseThreadSafe

Method StartPhaseThreadSafe

source/benchmark/phase_core.cpp:38–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38std::shared_ptr<Phase> PhaseCore::StartPhaseThreadSafe(const std::string& phase)
39{
40 std::shared_ptr<PhaseCore> result;
41
42 // Update phase collection under lock guard...
43 {
44 std::scoped_lock lock(_mutex);
45
46 // Find or create a sub phase with the given name
47 auto it = std::find_if(_child.begin(), _child.end(), [&phase](const std::shared_ptr<PhaseCore>& item)
48 {
49 return ((item->name() == phase) && (item->_thread == System::CurrentThreadId()));
50 });
51 if (it == _child.end())
52 {
53 result = std::make_shared<PhaseCore>(phase);
54 _child.emplace_back(result);
55 }
56 else
57 result = *it;
58 }
59
60 // Start new operation for the child phase
61 result->StartCollectingMetrics();
62
63 // Add new metrics operation
64 result->_metrics_current.AddOperations(1);
65
66 return result;
67}
68
69} // namespace CppBenchmark

Callers 2

LaunchMethod · 0.45
LaunchMethod · 0.45

Calls 2

AddOperationsMethod · 0.80

Tested by

no test coverage detected