Derecho  0.9
Distributed systems toolkit for RDMA
poll_utils.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <condition_variable>
4 #include <optional>
5 #include <list>
6 #include <map>
7 #include <mutex>
8 #include <thread>
9 #include <vector>
10 
11 namespace sst {
12 namespace util {
13 class PollingData {
14  // static std::vector<std::list<std::pair<int32_t, int32_t>>> completion_entries;
15  // static std::map<std::thread::id, uint32_t> tid_to_index;
16  // static std::vector<bool> if_waiting;
17  // static std::condition_variable poll_cv;
18  // static std::mutex poll_mutex;
19  // static bool check_waiting();
20 
21  std::vector<std::list<std::pair<int32_t, int32_t>>> completion_entries;
22  std::map<std::thread::id, uint32_t> tid_to_index;
23  std::vector<bool> if_waiting;
24  std::condition_variable poll_cv;
25  std::mutex poll_mutex;
26  bool check_waiting();
27 public:
28  void insert_completion_entry(uint32_t index, std::pair<int32_t, int32_t> ce);
29 
30  std::optional<std::pair<int32_t, int32_t>> get_completion_entry(const std::thread::id id);
31 
32  uint32_t get_index(const std::thread::id id);
33 
34  void set_waiting(const std::thread::id id);
35 
36  void reset_waiting(const std::thread::id id);
37 
38  void wait_for_requests();
39 };
40 
41 //There is one global instance of PollingData
43 } // namespace util
44 } // namespace sst
uint32_t get_index(const std::thread::id id)
Definition: poll_utils.cpp:39
void insert_completion_entry(uint32_t index, std::pair< int32_t, int32_t > ce)
Definition: poll_utils.cpp:23
PollingData polling_data
Definition: poll_utils.cpp:17
void set_waiting(const std::thread::id id)
Definition: poll_utils.cpp:49
std::map< std::thread::id, uint32_t > tid_to_index
Definition: poll_utils.hpp:22
void reset_waiting(const std::thread::id id)
Definition: poll_utils.cpp:56
std::condition_variable poll_cv
Definition: poll_utils.hpp:24
std::vector< std::list< std::pair< int32_t, int32_t > > > completion_entries
Definition: poll_utils.hpp:21
std::optional< std::pair< int32_t, int32_t > > get_completion_entry(const std::thread::id id)
Definition: poll_utils.cpp:28
std::vector< bool > if_waiting
Definition: poll_utils.hpp:23