[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / lldb / source / Core / Progress.cpp
blob08be73f1470f3498cc5186735750798dc326bd3a
1 //===-- Progress.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 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/Progress.h"
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Utility/StreamString.h"
14 using namespace lldb;
15 using namespace lldb_private;
17 std::atomic<uint64_t> Progress::g_id(0);
19 Progress::Progress(std::string title, uint64_t total,
20 lldb_private::Debugger *debugger)
21 : m_title(title), m_id(++g_id), m_completed(0), m_total(total) {
22 assert(total > 0);
23 if (debugger)
24 m_debugger_id = debugger->GetID();
25 std::lock_guard<std::mutex> guard(m_mutex);
26 ReportProgress();
29 Progress::~Progress() {
30 // Make sure to always report progress completed when this object is
31 // destructed so it indicates the progress dialog/activity should go away.
32 std::lock_guard<std::mutex> guard(m_mutex);
33 if (!m_completed) {
34 m_completed = m_total;
35 ReportProgress();
39 void Progress::Increment(uint64_t amount, std::string update) {
40 if (amount > 0) {
41 std::lock_guard<std::mutex> guard(m_mutex);
42 // Watch out for unsigned overflow and make sure we don't increment too
43 // much and exceed m_total.
44 if (amount > (m_total - m_completed))
45 m_completed = m_total;
46 else
47 m_completed += amount;
48 ReportProgress(update);
52 void Progress::ReportProgress(std::string update) {
53 if (!m_complete) {
54 // Make sure we only send one notification that indicates the progress is
55 // complete.
56 m_complete = m_completed == m_total;
57 Debugger::ReportProgress(m_id, m_title, std::move(update), m_completed,
58 m_total, m_debugger_id);