SourceXtractorPlusPlus  0.16
Please provide a description of the project.
Prefetcher.h
Go to the documentation of this file.
1 
18 #ifndef _SEIMPLEMENTATION_MEASUREMENT_PREFETCHER_H_
19 #define _SEIMPLEMENTATION_MEASUREMENT_PREFETCHER_H_
20 
21 #include <condition_variable>
26 #include "SEUtils/Observable.h"
27 
28 namespace SourceXtractor {
29 
41 class Prefetcher : public Observer<std::shared_ptr<SourceInterface>>,
42  public Observable<std::shared_ptr<SourceInterface>>,
43  public Observer<ProcessSourcesEvent>,
44  public Observable<ProcessSourcesEvent> {
45 public:
46 
52  Prefetcher(const std::shared_ptr<Euclid::ThreadPool>& thread_pool, unsigned max_queue_size);
53 
57  virtual ~Prefetcher();
58 
64  void handleMessage(const std::shared_ptr<SourceInterface>& message) override;
65 
71  void handleMessage(const ProcessSourcesEvent& message) override;
72 
80  template<typename Container>
81  void requestProperties(Container&& properties) {
82  for (auto& p : properties) {
83  requestProperty(p);
84  }
85  }
86 
92  void wait();
93 
94 private:
95  struct EventType {
96  enum Type {
100 
101  explicit EventType(Type type, intptr_t source_addr = -1)
102  : m_event_type(type), m_source_addr(source_addr) {}
103  };
104 
119 
121 
123  std::atomic_bool m_stop;
124 
127 
128  void requestProperty(const PropertyId& property_id);
129  void outputLoop();
130 };
131 
132 } // end of namespace SourceXtractor
133 
134 #endif // _SEIMPLEMENTATION_MEASUREMENT_PREFETCHER_H_
Implements the Observer pattern. Notifications will be made using a message of type T.
Definition: Observable.h:51
Observer interface to be used with Observable to implement the Observer pattern.
Definition: Observable.h:38
void requestProperty(const PropertyId &property_id)
Definition: Prefetcher.cpp:76
std::deque< ProcessSourcesEvent > m_event_queue
Queue of received ProcessSourceEvent, order preserved.
Definition: Prefetcher.h:116
std::shared_ptr< Euclid::ThreadPool > m_thread_pool
Pointer to the pool of worker threads.
Definition: Prefetcher.h:106
Prefetcher(const std::shared_ptr< Euclid::ThreadPool > &thread_pool, unsigned max_queue_size)
Definition: Prefetcher.cpp:44
std::condition_variable m_new_output
Notifies there is a new source done processing.
Definition: Prefetcher.h:112
std::deque< EventType > m_received
Queue of type of received events. Used to pass downstream events respecting the received order.
Definition: Prefetcher.h:118
void handleMessage(const std::shared_ptr< SourceInterface > &message) override
Definition: Prefetcher.cpp:54
void requestProperties(Container &&properties)
Definition: Prefetcher.h:81
Euclid::Semaphore m_semaphore
Keep the queue under control.
Definition: Prefetcher.h:126
std::set< PropertyId > m_prefetch_set
Properties to prefetch.
Definition: Prefetcher.h:108
std::unique_ptr< std::thread > m_output_thread
Orchestration thread.
Definition: Prefetcher.h:110
std::atomic_bool m_stop
Termination condition for the output loop.
Definition: Prefetcher.h:123
std::map< intptr_t, std::shared_ptr< SourceInterface > > m_finished_sources
Finished sources.
Definition: Prefetcher.h:114
Identifier used to set and retrieve properties.
Definition: PropertyId.h:40
EventType(Type type, intptr_t source_addr=-1)
Definition: Prefetcher.h:101
enum SourceXtractor::Prefetcher::EventType::Type m_event_type
Event received by SourceGrouping to request the processing of some of the Sources stored.