Coverage Report

Created: 2023-09-21 18:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Host/common/MainLoopBase.cpp
Line
Count
Source
1
//===-- MainLoopBase.cpp --------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/Host/MainLoopBase.h"
10
11
using namespace lldb;
12
using namespace lldb_private;
13
14
65.5k
void MainLoopBase::AddPendingCallback(const Callback &callback) {
15
65.5k
  {
16
65.5k
    std::lock_guard<std::mutex> lock{m_callback_mutex};
17
65.5k
    m_pending_callbacks.push_back(callback);
18
65.5k
  }
19
65.5k
  TriggerPendingCallbacks();
20
65.5k
}
21
22
63
void MainLoopBase::ProcessPendingCallbacks() {
23
  // Move the callbacks to a local vector to avoid keeping m_pending_callbacks
24
  // locked throughout the calls.
25
63
  std::vector<Callback> pending_callbacks;
26
63
  {
27
63
    std::lock_guard<std::mutex> lock{m_callback_mutex};
28
63
    pending_callbacks = std::move(m_pending_callbacks);
29
63
  }
30
31
63
  for (const Callback &callback : pending_callbacks)
32
5
    callback(*this);
33
63
}