diff options
author | David Robillard <d@drobilla.net> | 2006-07-12 06:34:30 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2006-07-12 06:34:30 +0000 |
commit | 7e013dc6986fa9d6dc8616d494d9de5d192c4c69 (patch) | |
tree | 89bc9d97375fafae33cf22f1020c788baa8d326c /src/libs/engine/QueuedEventSource.h | |
parent | 120757b8cb154266aae21472a49f0c00309a7dde (diff) | |
download | ingen-7e013dc6986fa9d6dc8616d494d9de5d192c4c69.tar.gz ingen-7e013dc6986fa9d6dc8616d494d9de5d192c4c69.tar.bz2 ingen-7e013dc6986fa9d6dc8616d494d9de5d192c4c69.zip |
Factored out Thread (and Slave, an explicitly signal-driven thread)
git-svn-id: http://svn.drobilla.net/lad/ingen@87 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs/engine/QueuedEventSource.h')
-rw-r--r-- | src/libs/engine/QueuedEventSource.h | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/src/libs/engine/QueuedEventSource.h b/src/libs/engine/QueuedEventSource.h index 15fb45f1..c3e6904a 100644 --- a/src/libs/engine/QueuedEventSource.h +++ b/src/libs/engine/QueuedEventSource.h @@ -21,6 +21,7 @@ #include <pthread.h> #include "types.h" #include "util/Semaphore.h" +#include "Slave.h" #include "EventSource.h" namespace Om { @@ -35,22 +36,27 @@ class QueuedEvent; * popping are threadsafe, as long as a single thread pushes and a single * thread pops (ie this data structure is threadsafe, but the push and pop * methods themselves are not). + * + * This class is it's own slave. :) */ -class QueuedEventSource : public EventSource +class QueuedEventSource : public EventSource, protected Slave { public: QueuedEventSource(size_t size); ~QueuedEventSource(); - Event* pop_earliest_event_before(const samplecount time); + void start() { Thread::start(); } + void stop() { Thread::stop(); } - void unblock(); + Event* pop_earliest_before(const samplecount time); - void start(); - void stop(); + void unblock(); protected: void push(QueuedEvent* const ev); + bool unprepared_events() { return (_prepared_back != _back); } + + virtual void _signalled(); ///< Prepare 1 event private: // Prevent copies (undefined) @@ -60,21 +66,12 @@ private: // Note that it's crucially important which functions access which of these // variables, to maintain threadsafeness. - size_t m_front; ///< Front of queue - size_t m_back; ///< Back of entire queue (1 past index of back element) - size_t m_prepared_back; ///< Back of prepared section (1 past index of back prepared element) - const size_t m_size; - QueuedEvent** m_events; - - bool m_thread_exists; - bool m_prepare_thread_exit_flag; - pthread_t m_prepare_thread; - Semaphore m_semaphore; ///< Counting semaphor for driving prepare thread - pthread_mutex_t m_blocking_mutex; - pthread_cond_t m_blocking_cond; - - static void* prepare_loop(void* q) { return ((QueuedEventSource*)q)->m_prepare_loop(); } - void* m_prepare_loop(); + size_t _front; ///< Front of queue + size_t _back; ///< Back of entire queue (1 past index of back element) + size_t _prepared_back; ///< Back of prepared section (1 past index of back prepared element) + const size_t _size; + QueuedEvent** _events; + Semaphore _blocking_semaphore; }; |