libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
dedicatedthreadmediaio.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
13#include <promeki/atomic.h>
15#include <promeki/list.h>
16#include <promeki/mutex.h>
17#include <promeki/thread.h>
18#include <promeki/timestamp.h>
20
21PROMEKI_NAMESPACE_BEGIN
22
55class DedicatedThreadMediaIO : public CommandMediaIO {
56 PROMEKI_OBJECT(DedicatedThreadMediaIO, CommandMediaIO)
57 public:
64 DedicatedThreadMediaIO(ObjectBase *parent = nullptr);
65
70 ~DedicatedThreadMediaIO() override;
71
73 bool isIdle() const override;
74
75 protected:
85 void submit(MediaIOCommand::Ptr cmd) override;
86
87 private:
88 struct QueueEntry {
89 MediaIOCommand::Ptr cmd;
90 TimeStamp submitTime;
91 };
92
93 // Private nested @ref Thread subclass so we get the
94 // library's OS-name / priority / affinity controls
95 // without dragging an EventLoop into the worker (the
96 // override of @c run drains the queue directly).
97 class Worker : public Thread {
98 public:
99 Worker(DedicatedThreadMediaIO *owner) : _owner(owner) {}
100
101 protected:
102 void run() override { _owner->workerMain(); }
103
104 private:
105 DedicatedThreadMediaIO *_owner;
106 };
107
108 void workerMain();
109
110 mutable Mutex _mutex;
111 WaitCondition _cond;
112 List<QueueEntry> _queue;
113 List<QueueEntry> _urgentQueue;
114 Atomic<bool> _shutdown{false};
115 Atomic<bool> _busy{false};
116 Worker _worker;
117};
118
119PROMEKI_NAMESPACE_END
120
121#endif // PROMEKI_ENABLE_PROAV