mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
modules/mpd: take lock in waitForEvent to prevent SIGABORT
+ replaced deprecated MPD_IDLE_PLAYLIST with MPD_IDLE_QUEUE + add mutex for periodic_updater
This commit is contained in:
parent
5ee4c54b13
commit
e6599d8ed5
@ -65,6 +65,9 @@ class MPD : public ALabel {
|
|||||||
unique_status status_;
|
unique_status status_;
|
||||||
mpd_state state_;
|
mpd_state state_;
|
||||||
unique_song song_;
|
unique_song song_;
|
||||||
|
|
||||||
|
// To make sure the previous periodic_updater stops before creating a new one
|
||||||
|
std::mutex periodic_lock_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
@ -41,6 +41,10 @@ auto waybar::modules::MPD::update() -> void {
|
|||||||
if (connection_ != nullptr) {
|
if (connection_ != nullptr) {
|
||||||
try {
|
try {
|
||||||
bool wasPlaying = playing();
|
bool wasPlaying = playing();
|
||||||
|
if(!wasPlaying) {
|
||||||
|
// Wait until the periodic_updater has stopped
|
||||||
|
std::lock_guard periodic_guard(periodic_lock_);
|
||||||
|
}
|
||||||
fetchState();
|
fetchState();
|
||||||
if (!wasPlaying && playing()) {
|
if (!wasPlaying && playing()) {
|
||||||
periodic_updater().detach();
|
periodic_updater().detach();
|
||||||
@ -75,6 +79,7 @@ std::thread waybar::modules::MPD::event_listener() {
|
|||||||
|
|
||||||
std::thread waybar::modules::MPD::periodic_updater() {
|
std::thread waybar::modules::MPD::periodic_updater() {
|
||||||
return std::thread([this] {
|
return std::thread([this] {
|
||||||
|
std::lock_guard guard(periodic_lock_);
|
||||||
while (connection_ != nullptr && playing()) {
|
while (connection_ != nullptr && playing()) {
|
||||||
dp.emit();
|
dp.emit();
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
@ -297,7 +302,7 @@ void waybar::modules::MPD::waitForEvent() {
|
|||||||
// Wait for a player (play/pause), option (random, shuffle, etc.), or playlist
|
// Wait for a player (play/pause), option (random, shuffle, etc.), or playlist
|
||||||
// change
|
// change
|
||||||
if (!mpd_send_idle_mask(
|
if (!mpd_send_idle_mask(
|
||||||
conn, static_cast<mpd_idle>(MPD_IDLE_PLAYER | MPD_IDLE_OPTIONS | MPD_IDLE_PLAYLIST))) {
|
conn, static_cast<mpd_idle>(MPD_IDLE_PLAYER | MPD_IDLE_OPTIONS | MPD_IDLE_QUEUE))) {
|
||||||
checkErrors(conn);
|
checkErrors(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -306,6 +311,10 @@ void waybar::modules::MPD::waitForEvent() {
|
|||||||
// See issue #277:
|
// See issue #277:
|
||||||
// https://github.com/Alexays/Waybar/issues/277
|
// https://github.com/Alexays/Waybar/issues/277
|
||||||
mpd_recv_idle(conn, /* disable_timeout = */ false);
|
mpd_recv_idle(conn, /* disable_timeout = */ false);
|
||||||
|
// See issue #281:
|
||||||
|
// https://github.com/Alexays/Waybar/issues/281
|
||||||
|
std::lock_guard guard(connection_lock_);
|
||||||
|
|
||||||
checkErrors(conn);
|
checkErrors(conn);
|
||||||
mpd_response_finish(conn);
|
mpd_response_finish(conn);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user