summaryrefslogtreecommitdiffstats
path: root/src/server/RunContext.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/RunContext.hpp')
-rw-r--r--src/server/RunContext.hpp55
1 files changed, 45 insertions, 10 deletions
diff --git a/src/server/RunContext.hpp b/src/server/RunContext.hpp
index 803d7829..eba30545 100644
--- a/src/server/RunContext.hpp
+++ b/src/server/RunContext.hpp
@@ -17,6 +17,8 @@
#ifndef INGEN_ENGINE_RUNCONTEXT_HPP
#define INGEN_ENGINE_RUNCONTEXT_HPP
+#include <thread>
+
#include "ingen/Atom.hpp"
#include "ingen/World.hpp"
#include "raul/RingBuffer.hpp"
@@ -28,6 +30,7 @@ namespace Server {
class Engine;
class PortImpl;
+class Task;
/** Graph execution context.
*
@@ -44,8 +47,19 @@ class PortImpl;
class RunContext
{
public:
- RunContext(Engine& engine);
- RunContext(const RunContext& copy);
+ /** Create a new run context.
+ *
+ * @param threaded If true, then this context is a worker which will launch
+ * a thread and execute tasks as they become available.
+ */
+ RunContext(Engine& engine, unsigned id, bool threaded);
+
+ /** Create a sub-context of `parent`.
+ *
+ * This is used to subdivide process cycles, the sub-context is
+ * lightweight and only serves to pass different time attributes.
+ */
+ RunContext(const RunContext& parent);
virtual ~RunContext();
@@ -73,42 +87,63 @@ public:
/** Return true iff any notifications are pending. */
bool pending_notifications() const { return _event_sink->read_space(); }
+ /** Return the duration of this cycle in microseconds.
+ *
+ * This is the cycle length in frames (nframes) converted to microseconds,
+ * that is, the amount of real time that this cycle's audio represents.
+ * Note that this is unrelated to the amount of time available to execute a
+ * cycle (other than the fact that it must be processed in significantly
+ * less time to avoid a dropout when running in real time).
+ */
+ inline uint64_t duration() const {
+ return (uint64_t)_nframes * 1e6 / _rate;
+ }
+
inline void locate(FrameTime s, SampleCount nframes) {
_start = s;
_end = s + nframes;
_nframes = nframes;
}
- inline void locate(const RunContext& other) {
- _start = other._start;
- _end = other._end;
- _nframes = other._nframes;
- }
-
inline void slice(SampleCount offset, SampleCount nframes) {
_offset = offset;
_nframes = nframes;
}
+ inline void set_task(Task* task) {
+ _task = task;
+ }
+
+ void set_priority(int priority);
+ void set_rate(SampleCount rate) { _rate = rate; }
+
inline Engine& engine() const { return _engine; }
+ inline Task* task() const { return _task; }
+ inline unsigned id() const { return _id; }
inline FrameTime start() const { return _start; }
inline FrameTime time() const { return _start + _offset; }
inline FrameTime end() const { return _end; }
inline SampleCount offset() const { return _offset; }
inline SampleCount nframes() const { return _nframes; }
+ inline SampleCount rate() const { return _rate; }
inline bool realtime() const { return _realtime; }
protected:
const RunContext& operator=(const RunContext& copy) = delete;
- Engine& _engine; ///< Engine we're running in
+ void run();
- Raul::RingBuffer* _event_sink; ///< Port updates from process context
+ Engine& _engine; ///< Engine we're running in
+ Raul::RingBuffer* _event_sink; ///< Port updates from process context
+ Task* _task; ///< Currently executing task
+ std::thread* _thread; ///< Thread (NULL for main run context)
+ unsigned _id; ///< Context ID
FrameTime _start; ///< Start frame of this cycle, timeline relative
FrameTime _end; ///< End frame of this cycle, timeline relative
SampleCount _offset; ///< Offset into data buffers
SampleCount _nframes; ///< Number of frames past offset to process
+ SampleCount _rate; ///< Sample rate in Hz
bool _realtime; ///< True iff context is hard realtime
bool _copy; ///< True iff this is a copy (shared event_sink)
};