]> git.tdb.fi Git - xinema.git/commitdiff
Protect some important parts with mutexes
authorMikko Rasa <tdb@tdb.fi>
Fri, 16 Oct 2015 17:04:23 +0000 (20:04 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 16 Oct 2015 17:04:23 +0000 (20:04 +0300)
source/client.cpp
source/client.h
source/xinestream.cpp
source/xinestream.h

index 0e87e205055f6a5c796ce40f53a056fc4293ca01..8d61f3fa51e56c9a78d12a322e4ea973c9a479ba 100644 (file)
@@ -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');
 }
index 2300fc2d3d5d3c5ffa54ab6c3c41a8fc9c218a04..f8aeb8238a440f133e9ccfee357449f73edbfab5 100644 (file)
@@ -15,6 +15,7 @@ private:
        Xinema &xinema;
        Msp::Net::StreamSocket *socket;
        std::string buffer;
+       Msp::Mutex mutex;
        Msp::Time::TimeDelta last_position;
        bool stale;
 
index 02fd3165de392af3a305fcf4787485214bf256ff..43a7d980d8862310c50bc9cd89133a18621ef2aa 100644 (file)
@@ -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);
        }
index def7f01a5f9d2dbd6a5e0ee694670c8c597e0bf6..832e3a72b0bfd34470d0af2b4c06dd6438644762 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <string>
 #include <xine.h>
+#include <msp/core/mutex.h>
 #include <msp/strings/lexicalcast.h>
 #include <msp/time/timedelta.h>
 
@@ -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;