add AudioBackendNativeThread to serve the same role as jack_native_thread_t
[ardour.git] / libs / ardour / ardour / worker.h
index eca5aa21ca6e43a056ad0cc01ffcaac55523c7e4..4f3ff54bc10782898d32a711e7826f246732cc29 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <stdint.h>
 
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
 
 #include "pbd/ringbuffer.h"
 #include "pbd/semaphore.h"
@@ -39,12 +39,12 @@ public:
        /**
           Do some work in the worker thread.
        */
-       virtual void work(uint32_t size, const void* data) = 0;
+       virtual int work(uint32_t size, const void* data) = 0;
 
        /**
           Handle a response from the worker thread in the audio thread.
        */
-       virtual void work_response(uint32_t size, const void* data) = 0;
+       virtual int work_response(uint32_t size, const void* data) = 0;
 };
 
 /**
@@ -75,14 +75,25 @@ public:
 
 private:
        void run();
+       /**
+          Peek in RB, get size and check if a block of 'size' is available.
+
+          Handle the unlikley edge-case, if we're called in between the
+          responder writing 'size' and 'data'.
+
+                @param rb the ringbuffer to check
+                @return true if the message is complete, false otherwise
+        */
+       bool verify_message_completeness(RingBuffer<uint8_t>* rb);
+
+       Workee*                _workee;
+       RingBuffer<uint8_t>*   _requests;
+       RingBuffer<uint8_t>*   _responses;
+       uint8_t*               _response;
+       PBD::Semaphore         _sem;
+       bool                   _exit;
+       Glib::Threads::Thread* _thread;
 
-       Workee*              _workee;
-       Glib::Thread*        _thread;
-       RingBuffer<uint8_t>* _requests;
-       RingBuffer<uint8_t>* _responses;
-       uint8_t*             _response;
-       PBD::Semaphore       _sem;
-       bool                 _exit;
 };
 
 } // namespace ARDOUR