1 //===-- Progress.cpp ------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/Progress.h"
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Utility/StreamString.h"
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
) {
24 m_debugger_id
= debugger
->GetID();
25 std::lock_guard
<std::mutex
> guard(m_mutex
);
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
);
34 m_completed
= m_total
;
39 void Progress::Increment(uint64_t amount
, std::string update
) {
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
;
47 m_completed
+= amount
;
48 ReportProgress(update
);
52 void Progress::ReportProgress(std::string update
) {
54 // Make sure we only send one notification that indicates the progress is
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
);