| 36 | } |
| 37 | |
| 38 | std::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 |
no test coverage detected