LLDB mainline
|
enables scheduling a callback function after a specified timeout. More...
#include <Alarm.h>
Classes | |
struct | Entry |
Alarm entry. More... | |
Public Types | |
using | Handle = uint64_t |
using | Callback = std::function< void()> |
using | TimePoint = llvm::sys::TimePoint<> |
using | Duration = std::chrono::milliseconds |
Public Member Functions | |
Alarm (Duration timeout, bool run_callback_on_exit=false) | |
~Alarm () | |
Handle | Create (Callback callback) |
Create an alarm for the given callback. | |
bool | Restart (Handle handle) |
Restart the alarm for the given Handle. | |
bool | Cancel (Handle handle) |
Cancel the alarm for the given Handle. | |
Static Public Attributes | |
static constexpr Handle | INVALID_HANDLE = 0 |
Private Member Functions | |
TimePoint | GetNextExpiration () const |
Helper to compute the next time the alarm thread needs to wake up. | |
void | StartAlarmThread () |
Helper functions to start, stop and check the status of the alarm thread. | |
void | StopAlarmThread () |
bool | AlarmThreadRunning () |
Static Private Member Functions | |
static Handle | GetNextUniqueHandle () |
Return an unique, monotonically increasing handle. | |
Private Attributes | |
std::vector< Entry > | m_entries |
List of alarm entries. | |
Duration | m_timeout |
Timeout between when an alarm is created and when it fires. | |
std::mutex | m_alarm_mutex |
Synchronize access between the alarm thread and the main thread. | |
std::condition_variable | m_alarm_cv |
Condition variable used to wake up the alarm thread. | |
bool | m_recompute_next_alarm = false |
Flag to signal the alarm thread that something changed and we need to recompute the next alarm. | |
bool | m_exit = false |
Flag to signal the alarm thread to exit. | |
bool | m_run_callbacks_on_exit = false |
Flag to signal we should run all callbacks on exit. | |
HostThread | m_alarm_thread |
The alarm thread. | |
lldb::thread_result_t | AlarmThread () |
enables scheduling a callback function after a specified timeout.
Creating an alarm for a callback returns a Handle that can be used to restart or cancel the alarm.
using lldb_private::Alarm::Callback = std::function<void()> |
using lldb_private::Alarm::Duration = std::chrono::milliseconds |
using lldb_private::Alarm::Handle = uint64_t |
using lldb_private::Alarm::TimePoint = llvm::sys::TimePoint<> |
Alarm::Alarm | ( | Duration | timeout, |
bool | run_callback_on_exit = false |
||
) |
Definition at line 17 of file Alarm.cpp.
References StartAlarmThread().
Alarm::~Alarm | ( | ) |
Definition at line 22 of file Alarm.cpp.
References StopAlarmThread().
|
private |
Definition at line 139 of file Alarm.cpp.
References m_alarm_cv, m_alarm_mutex, m_entries, m_exit, m_recompute_next_alarm, and m_run_callbacks_on_exit.
Referenced by StartAlarmThread().
|
private |
Definition at line 137 of file Alarm.cpp.
References lldb_private::HostThread::IsJoinable(), and m_alarm_thread.
bool Alarm::Cancel | ( | Handle | handle | ) |
Cancel the alarm for the given Handle.
The alarm and its handle will be removed.
Definition at line 82 of file Alarm.cpp.
References AlarmThreadRunning(), m_alarm_mutex, and m_entries.
Referenced by lldb_private::ProgressManager::Increment().
Alarm::Handle Alarm::Create | ( | Callback | callback | ) |
Create an alarm for the given callback.
The alarm will expire and the callback will be called after the timeout.
Definition at line 24 of file Alarm.cpp.
References AlarmThreadRunning(), GetNextExpiration(), INVALID_HANDLE, m_alarm_cv, m_alarm_mutex, m_entries, and m_recompute_next_alarm.
Referenced by lldb_private::ProgressManager::Decrement().
|
private |
|
staticprivate |
bool Alarm::Restart | ( | Handle | handle | ) |
Restart the alarm for the given Handle.
The alarm will expire and the callback will be called after the timeout.
Definition at line 51 of file Alarm.cpp.
References AlarmThreadRunning(), GetNextExpiration(), m_alarm_cv, m_alarm_mutex, m_entries, and m_recompute_next_alarm.
|
private |
Helper functions to start, stop and check the status of the alarm thread.
Definition at line 112 of file Alarm.cpp.
References AlarmThread(), lldb_private::GetLog(), lldb_private::Host, lldb_private::HostThread::IsJoinable(), lldb_private::ThreadLauncher::LaunchThread(), LLDB_LOG_ERROR, and m_alarm_thread.
Referenced by Alarm().
|
private |
Definition at line 126 of file Alarm.cpp.
References lldb_private::HostThread::IsJoinable(), lldb_private::HostThread::Join(), m_alarm_cv, m_alarm_mutex, m_alarm_thread, and m_exit.
Referenced by ~Alarm().
|
staticconstexpr |
Definition at line 58 of file Alarm.h.
Referenced by Create(), lldb_private::ProgressManager::Decrement(), and lldb_private::ProgressManager::Increment().
|
private |
Condition variable used to wake up the alarm thread.
Definition at line 100 of file Alarm.h.
Referenced by AlarmThread(), Create(), Restart(), and StopAlarmThread().
|
private |
Synchronize access between the alarm thread and the main thread.
Definition at line 97 of file Alarm.h.
Referenced by AlarmThread(), Cancel(), Create(), Restart(), and StopAlarmThread().
|
private |
The alarm thread.
Definition at line 92 of file Alarm.h.
Referenced by AlarmThreadRunning(), StartAlarmThread(), and StopAlarmThread().
|
private |
|
private |
Flag to signal the alarm thread to exit.
Definition at line 107 of file Alarm.h.
Referenced by AlarmThread(), and StopAlarmThread().
|
private |
Flag to signal the alarm thread that something changed and we need to recompute the next alarm.
Definition at line 104 of file Alarm.h.
Referenced by AlarmThread(), Create(), and Restart().
|
private |
Flag to signal we should run all callbacks on exit.
Definition at line 110 of file Alarm.h.
Referenced by AlarmThread().
|
private |
Timeout between when an alarm is created and when it fires.
Definition at line 88 of file Alarm.h.
Referenced by GetNextExpiration().