fix(pulseaudio): add mutex for queue

This commit is contained in:
NBonaparte 2018-03-24 00:37:01 -07:00 committed by Patrick Ziegler
parent 5f88cd44c7
commit d430174f0b
2 changed files with 8 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <pulse/pulseaudio.h>
#include <queue>
#include <mutex>
#include "common.hpp"
#include "settings.hpp"
@ -18,6 +19,8 @@ typedef struct pa_threaded_mainloop pa_threaded_mainloop;
POLYBAR_NS
class logger;
using mutex = std::mutex;
DEFINE_ERROR(pulseaudio_error);
class pulseaudio {
@ -69,6 +72,8 @@ class pulseaudio {
pa_threaded_mainloop* m_mainloop{nullptr};
queue m_events;
mutable mutex m_mutex;
// specified sink name
string spec_s_name;

View File

@ -112,6 +112,8 @@ bool pulseaudio::wait() {
* Process queued pulseaudio events
*/
int pulseaudio::process_events() {
std::lock_guard<mutex> lock(m_mutex);
int ret = m_events.size();
pa_threaded_mainloop_lock(m_mainloop);
pa_operation *o{nullptr};
@ -245,6 +247,7 @@ void pulseaudio::subscribe_callback(pa_context *, pa_subscription_event_type_t t
return;
switch(t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
case PA_SUBSCRIPTION_EVENT_SINK:
std::lock_guard<mutex> lock(This->m_mutex);
switch(t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) {
case PA_SUBSCRIPTION_EVENT_NEW:
This->m_events.emplace(evtype::NEW);