mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-28 22:21:35 +02:00
Changed: Reverted thread mutex lock to atomic bool with wait and timeout
This commit is contained in:
parent
804fe60ca9
commit
79a030ca82
28
src/btop.cpp
28
src/btop.cpp
@ -303,7 +303,7 @@ namespace Runner {
|
||||
sigset_t mask;
|
||||
pthread_t runner_id;
|
||||
pthread_mutex_t mtx;
|
||||
pthread_mutex_t active_mtx;
|
||||
// pthread_mutex_t active_mtx;
|
||||
|
||||
const unordered_flat_map<string, uint_fast8_t> box_bits = {
|
||||
{"proc", 0b0000'0001},
|
||||
@ -389,8 +389,15 @@ namespace Runner {
|
||||
//* ----------------------------------------------- THREAD LOOP -----------------------------------------------
|
||||
while (not Global::quitting) {
|
||||
thread_wait();
|
||||
thread_lock lock(active_mtx);
|
||||
atomic_wait_for(active, true, 5000);
|
||||
if (active) {
|
||||
Global::exit_error_msg = "Runner thread failed to get active lock!";
|
||||
Global::thread_exception = true;
|
||||
Input::interrupt = true;
|
||||
stopping = true;
|
||||
}
|
||||
if (stopping or Global::resized) {
|
||||
sleep_ms(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -592,9 +599,12 @@ namespace Runner {
|
||||
|
||||
//* Runs collect and draw in a secondary thread, unlocks and locks config to update cached values
|
||||
void run(const string& box, const bool no_update, const bool force_redraw) {
|
||||
bool trigger = false;
|
||||
{
|
||||
thread_lock lock(active_mtx);
|
||||
atomic_wait_for(active, true, 5000);
|
||||
if (active) {
|
||||
Global::exit_error_msg = "Stall in Runner thread, quitting!";
|
||||
active = false;
|
||||
exit(1);
|
||||
}
|
||||
if (stopping or Global::resized) return;
|
||||
|
||||
if (box == "overlay") {
|
||||
@ -617,15 +627,11 @@ namespace Runner {
|
||||
|
||||
if (Menu::active and not current_conf.background_update) Global::overlay.clear();
|
||||
|
||||
trigger = true;
|
||||
}
|
||||
}
|
||||
//? Trigger thread start and wait for it to be active before returning
|
||||
if (trigger) {
|
||||
thread_trigger();
|
||||
atomic_wait_for(active, false, 10);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//* Stops any work being done in runner thread and checks for thread errors
|
||||
@ -638,7 +644,7 @@ namespace Runner {
|
||||
exit(1);
|
||||
}
|
||||
else if (ret == EBUSY) {
|
||||
atomic_wait_for(active, true, 1000);
|
||||
atomic_wait_for(active, true, 5000);
|
||||
if (active) {
|
||||
Global::exit_error_msg = "No response from Runner thread, quitting!";
|
||||
active = false;
|
||||
|
Loading…
Reference in New Issue
Block a user