Przeglądaj źródła

Merge remote-tracking branch 'origin/dev' into dev

dmuratshin 9 lat temu
rodzic
commit
06a2975740

+ 17 - 4
oxygine/src/core/ThreadDispatcher.cpp

@@ -278,7 +278,7 @@ namespace oxygine
         return _result;
     }
 
-    void ThreadDispatcher::sendCallback(void* arg1, void* arg2, callback cb, void* cbData)
+    void ThreadDispatcher::sendCallback(void* arg1, void* arg2, callback cb, void* cbData, bool highPriority)
     {
         message ev;
         ev.arg1 = arg1;
@@ -289,17 +289,20 @@ namespace oxygine
 #ifndef OX_NO_MT
         MutexPthreadLock lock(_mutex);
 #endif
-        _pushMessageWaitReply(ev);
+        _pushMessageWaitReply(ev, highPriority);
     }
 
-    void ThreadDispatcher::_pushMessageWaitReply(message& msg)
+    void ThreadDispatcher::_pushMessageWaitReply(message& msg, bool highPriority)
     {
         msg._id = ++_id;
         msg.need_reply = true;
         LOGDN("_pushMessageWaitReply id=%d msgid=%d", msg._id, msg.msgid);
 
+        if (highPriority)
+            _events.insert(_events.begin(), msg);
+        else
+            _events.push_back(msg);
 
-        _events.push_back(msg);
         _waitReply(msg._id);
         LOGDN("waiting reply  %d - done", msg._id);
     }
@@ -392,4 +395,14 @@ namespace oxygine
         _pushMessageWaitReply(ev);
     }
 #endif
+
+    std::vector<ThreadDispatcher::message>& ThreadDispatcher::lockMessages()
+    {
+        pthread_mutex_lock(&_mutex);
+        return _events;
+    }
+    void ThreadDispatcher::unlockMessages()
+    {
+        pthread_mutex_unlock(&_mutex);
+    }
 }

+ 33 - 2
oxygine/src/core/ThreadDispatcher.h

@@ -22,6 +22,24 @@ namespace oxygine
         pthread_mutex_t& _mutex;
         bool _locked;
     };
+	/*
+    class TDMessage
+    {
+    public:
+        TDMessage& withMSGID(int id) { msgid = id; return *this; }
+        TDMessage& withArgs(void* Arg1, void* Arg2 = 0) { arg1 = Arg1; arg2 = Arg2; return *this; }
+        TDMessage& withHighPriority() { hp = true; return *this; }
+        TDMessage& withReply() { reply = true; return *this; }
+
+        int msgid;
+        void* arg1;
+        void* arg2;
+        bool hp;
+        bool reply;
+
+    protected:
+    };*/
+
 
     /**Messages Queue used for communication between threads*/
     class ThreadDispatcher
@@ -73,7 +91,7 @@ namespace oxygine
         //blocking, sends message and waiting reply from other thread
         void* send(int msgid, void* arg1, void* arg2);
         //blocking, sends callback and waiting until it is done
-        void sendCallback(void* arg1, void* arg2, callback cb, void* cbData);
+        void sendCallback(void* arg1, void* arg2, callback cb, void* cbData, bool highPriority = false);
 #ifndef __S3E__
         //blocking, sends callback and waiting until it is done
         void sendCallback(const std::function<void()>&);
@@ -95,6 +113,12 @@ namespace oxygine
 
         void reply(void* val);
 
+        //void post(TDMessage&);
+        //void send(TDMessage&);
+
+        std::vector<message>& lockMessages();
+        void unlockMessages();
+
     private:
         void _waitMessage();
         void _waitReply(int id);
@@ -102,7 +126,7 @@ namespace oxygine
         void _runCallbacks();
 
         void _pushMessage(message&);
-        void _pushMessageWaitReply(message&);
+        void _pushMessageWaitReply(message&, bool highPriority = false);
         void _popMessage(message&);
         void _popMessageNoCB(message&);
         void _replyLast(void* val);
@@ -121,4 +145,11 @@ namespace oxygine
     };
 
     typedef  ThreadDispatcher ThreadMessages;
+
+    class ThreadDispatcher2
+    {
+    public:
+
+    protected:
+    };
 }