Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
pipeline_task.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_pipeline/pipeline_task.h
10 //! @brief Base class for pipeline tasks.
11 
12 #ifndef ROC_PIPELINE_PIPELINE_TASK_H_
13 #define ROC_PIPELINE_PIPELINE_TASK_H_
14 
15 #include "roc_core/atomic.h"
17 #include "roc_core/optional.h"
18 #include "roc_core/semaphore.h"
19 
20 namespace roc {
21 namespace pipeline {
22 
23 class PipelineLoop;
24 class IPipelineTaskCompleter;
25 
26 //! Base class for pipeline tasks.
28 public:
29  ~PipelineTask();
30 
31  //! Check that the task finished and succeeded.
32  bool success() const;
33 
34 protected:
35  PipelineTask();
36 
37 private:
38  friend class PipelineLoop;
39 
40  enum { StateNew, StateScheduled, StateFinished };
41 
42  // Task state, defines whether task is finished already.
43  // The task becomes immutable after setting state_ to StateFinished;
44  core::Atomic<int> state_;
45 
46  // Task result, defines wether finished task succeeded or failed.
47  // Makes sense only after setting state_ to StateFinished.
48  // This atomic should be assigned before setting state_ to StateFinished.
49  core::Atomic<int> success_;
50 
51  // Completion handler;
52  IPipelineTaskCompleter* completer_;
53 
54  // Completion semaphore.
56 };
57 
58 } // namespace pipeline
59 } // namespace roc
60 
61 #endif // ROC_PIPELINE_PIPELINE_TASK_H_
Atomic.
Base class for MpscQueue element.
Optionally constructed object.
Definition: optional.h:25
Pipeline task completion handler.
Base class for task-based pipelines.
Base class for pipeline tasks.
Definition: pipeline_task.h:27
bool success() const
Check that the task finished and succeeded.
MpscQueue node.
Root namespace.
Optionally constructed object.