OperationThread.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2010 - 2011 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 #ifndef __OperationThread_h
10 #define __OperationThread_h
11 
12 #include "dsp/Operation.h"
13 #include "ThreadContext.h"
14 
15 namespace dsp
16 {
17 
19 
20  class OperationThread : public Operation
21  {
22 
23  public:
24 
27 
30 
32  void append_operation (Operation* op);
33 
35  void reserve ();
36 
38  void prepare ();
39 
41  void add_extensions (Extensions* ext);
42 
44  void operation ();
45 
47  void combine (const Operation*);
48 
50  void report () const;
51 
53  uint64_t bytes_storage() const override;
54 
56  uint64_t bytes_scratch () const override;
57 
59  void reset ();
60 
62  class Wait;
63 
65  Wait * get_wait();
66 
67  unsigned get_nop() const { return operations.size(); }
68  Operation* get_op (unsigned i) { return operations.at(i); }
69 
70  protected:
71 
73  static void* operation_thread (void*);
74 
76  void thread ();
77 
79  std::vector< Reference::To<Operation> > operations;
80 
83  pthread_t id;
84 
85  enum State { Idle, Active, Quit };
86  State state;
87 
88  };
89 
90  class OperationThread::Wait : public Operation
91  {
92 
93  public:
94 
95  Wait (OperationThread* parent);
96  void operation ();
97 
98  uint64_t bytes_storage() const override { return 0; }
99  uint64_t bytes_scratch () const override { return 0; }
100 
101  OperationThread* get_parent() const { return parent; }
102 
103  protected:
104 
106  };
107 }
108 
109 #endif
Executes one or more Operations in sequence in a separate thread.
Definition: OperationThread.h:25
uint64_t bytes_storage() const override
The number of bytes of additional storage used by the operation.
Definition: OperationThread.C:137
ThreadContext * context
Used to communicate between calling thread and operation thread.
Definition: OperationThread.h:92
static void * operation_thread(void *)
Operation thread calls thread method.
Definition: OperationThread.C:35
virtual void reset()
Reset accumulated results to intial values.
Definition: Operation.C:161
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
virtual void add_extensions(Extensions *)
Add any extensions.
Definition: Operation.C:86
~OperationThread()
Destructor destroys all Operation instances.
Definition: OperationThread.C:29
Operation(const char *name)
All sub-classes must specify a unique name.
Definition: Operation.C:46
virtual void report() const
Report operation statistics.
Definition: Operation.C:168
uint64_t bytes_scratch() const override
The number of bytes of scratch space used by the operation.
Definition: OperationThread.C:146
void reserve()
Calls the reserve method of each Operation.
Definition: OperationThread.C:92
Defines the interface by which operations are performed on data.
Definition: Operation.h:37
void reset()
Calls the reset method of each Operation.
Definition: OperationThread.C:131
virtual bool operate()
Call this method to operate on data Returns false on failure.
Definition: Operation.C:90
void append_operation(Operation *op)
Append operation to the list of operations, thread state must be Idle.
Definition: OperationThread.C:76
void thread()
Calls the operation method of each Operation instance.
Definition: OperationThread.C:41
virtual void prepare()
Prepare for data operations.
Definition: Operation.C:77
void report() const
Calls the report method of each Operation.
Definition: OperationThread.C:125
void operation()
Signals the operation thread to start.
Definition: OperationThread.C:66
std::vector< Reference::To< Operation > > operations
The operations performed on each call to operation.
Definition: OperationThread.h:89
virtual void reserve()
Reserve the maximum amount of memory required.
Definition: Operation.C:82
void combine(const Operation *)
Calls the combine method of each Operation.
Definition: OperationThread.C:104
void add_extensions(Extensions *ext)
Calls the add_extensions method of each Operation.
Definition: OperationThread.C:98
void prepare()
Calls the prepare method of each Operation.
Definition: OperationThread.C:86
Wait * get_wait()
Return a new Wait operation for this thread.
Definition: OperationThread.C:169
OperationThread(Operation *=0)
Default constructor with optional first Operation.
Definition: OperationThread.C:14

Generated using doxygen 1.8.17