From 2e629085885b652a10d775695e63bc4892aa2eca Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 16 Oct 2015 20:04:23 +0300 Subject: [PATCH] Protect some important parts with mutexes --- source/client.cpp | 1 + source/client.h | 1 + source/xinestream.cpp | 16 ++++++---------- source/xinestream.h | 2 ++ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/source/client.cpp b/source/client.cpp index 0e87e20..8d61f3f 100644 --- a/source/client.cpp +++ b/source/client.cpp @@ -89,6 +89,7 @@ void Client::process_command(const string &cmd) void Client::send_reply(const string &reply) { + Msp::MutexLock lock(mutex); socket->write(reply); socket->put('\n'); } diff --git a/source/client.h b/source/client.h index 2300fc2..f8aeb82 100644 --- a/source/client.h +++ b/source/client.h @@ -15,6 +15,7 @@ private: Xinema &xinema; Msp::Net::StreamSocket *socket; std::string buffer; + Msp::Mutex mutex; Msp::Time::TimeDelta last_position; bool stale; diff --git a/source/xinestream.cpp b/source/xinestream.cpp index 02fd316..43a7d98 100644 --- a/source/xinestream.cpp +++ b/source/xinestream.cpp @@ -68,6 +68,7 @@ void XineStream::set_state(State s) if(s==state) return; + MutexLock lock(mutex); state = s; signal_state_changed.emit(state); } @@ -86,17 +87,10 @@ void XineStream::tick() void XineStream::check_info() { const char *xt = xine_get_meta_info(stream, XINE_META_INFO_TITLE); - if(xt) + if((xt && title.compare(xt)) || (!xt && !title.empty())) { - if(title.compare(xt)) - { - title = xt; - signal_title_changed.emit(title); - } - } - else if(!title.empty()) - { - title.clear(); + MutexLock lock(mutex); + title = (xt ? xt : string()); signal_title_changed.emit(title); } @@ -106,11 +100,13 @@ void XineStream::check_info() Time::TimeDelta pos = pos_msec*Time::msec; if(dur!=duration) { + MutexLock lock(mutex); duration = dur; signal_duration_changed.emit(duration); } if(pos!=position) { + MutexLock lock(mutex); position = pos; signal_position_changed.emit(position); } diff --git a/source/xinestream.h b/source/xinestream.h index def7f01..832e3a7 100644 --- a/source/xinestream.h +++ b/source/xinestream.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -27,6 +28,7 @@ private: XineEngine &engine; xine_stream_t *stream; xine_event_queue_t *queue; + Msp::Mutex mutex; State state; std::string title; Msp::Time::TimeDelta duration; -- 2.43.0