CMS 3D CMS Logo

WaitingServer.h
Go to the documentation of this file.
1 #ifndef FWCore_Integration_WaitingServer_h
2 #define FWCore_Integration_WaitingServer_h
3 
5 
6 #include <atomic>
7 #include <condition_variable>
8 #include <memory>
9 #include <mutex>
10 #include <thread>
11 #include <vector>
12 
13 namespace edmtest {
14  namespace test_acquire {
15 
16  struct StreamData {
17  StreamData() : in_(nullptr), out_(nullptr) {}
18 
19  std::vector<int> const* in_;
20  std::vector<int>* out_;
22  };
23 
24  class WaitingServer {
25  public:
26  WaitingServer(unsigned int iNumberOfStreams,
27  unsigned int iMinNumberOfStreamsBeforeDoingWork,
28  unsigned int iSecondsToWait)
29  : m_perStream(iNumberOfStreams),
30  m_minNumStreamsBeforeDoingWork(iMinNumberOfStreamsBeforeDoingWork),
31  m_secondsToWait(iSecondsToWait),
33 
34  void start();
35  void stop();
36 
37  void requestValuesAsync(unsigned int dataID,
38  std::vector<int> const* iIn,
39  std::vector<int>* iOut,
41 
42  private:
43  void serverDoWork();
44 
45  bool readyForWork() const;
46 
47  std::mutex m_mutex; //needed by m_cond
48  std::condition_variable m_cond;
49  std::unique_ptr<std::thread> m_thread;
50  std::vector<StreamData> m_perStream;
51  std::vector<unsigned int> m_waitingStreams;
52  const unsigned int m_minNumStreamsBeforeDoingWork;
53  const unsigned int m_secondsToWait;
54  std::atomic<bool> m_shouldStop;
55  };
56 
57  class Cache {
58  public:
59  std::vector<int> const& retrieved() const { return m_retrieved; }
60  std::vector<int>& retrieved() { return m_retrieved; }
61 
62  std::vector<int> const& processed() const { return m_processed; }
63  std::vector<int>& processed() { return m_processed; }
64 
65  private:
66  std::vector<int> m_retrieved;
67  std::vector<int> m_processed;
68  };
69  } // namespace test_acquire
70 } // namespace edmtest
71 #endif
std::vector< StreamData > m_perStream
Definition: WaitingServer.h:50
static std::mutex mutex
Definition: Proxy.cc:8
const unsigned int m_minNumStreamsBeforeDoingWork
Definition: WaitingServer.h:52
std::condition_variable m_cond
Definition: WaitingServer.h:48
std::vector< int > const * in_
Definition: WaitingServer.h:19
std::vector< int > m_retrieved
Definition: WaitingServer.h:66
edm::WaitingTaskWithArenaHolder holder_
Definition: WaitingServer.h:21
std::vector< int > & retrieved()
Definition: WaitingServer.h:60
std::vector< int > & processed()
Definition: WaitingServer.h:63
std::unique_ptr< std::thread > m_thread
Definition: WaitingServer.h:49
std::vector< int > m_processed
Definition: WaitingServer.h:67
std::vector< int > const & processed() const
Definition: WaitingServer.h:62
WaitingServer(unsigned int iNumberOfStreams, unsigned int iMinNumberOfStreamsBeforeDoingWork, unsigned int iSecondsToWait)
Definition: WaitingServer.h:26
std::vector< unsigned int > m_waitingStreams
Definition: WaitingServer.h:51
std::vector< int > const & retrieved() const
Definition: WaitingServer.h:59
void requestValuesAsync(unsigned int dataID, std::vector< int > const *iIn, std::vector< int > *iOut, edm::WaitingTaskWithArenaHolder holder)
Definition: WaitingServer.cc:9