Battery event (#18)

This commit is contained in:
Alex
2018-08-13 14:05:13 +02:00
committed by GitHub
parent 01894f18cd
commit a423f7032d
9 changed files with 88 additions and 72 deletions

View File

@ -39,7 +39,9 @@ namespace waybar::util {
func();
} while (do_run);
}}
{}
{
defined = true;
}
SleeperThread& operator=(std::function<void()> func)
{
@ -48,6 +50,7 @@ namespace waybar::util {
func();
} while (do_run);
});
defined = true;
return *this;
}
@ -72,14 +75,17 @@ namespace waybar::util {
~SleeperThread()
{
do_run = false;
condvar.notify_all();
thread.join();
if (defined) {
condvar.notify_all();
thread.join();
}
}
private:
std::thread thread;
std::condition_variable condvar;
std::mutex mutex;
bool defined = false;
bool do_run = true;
};