adding iris benchmark
[c11concurrency-benchmarks.git] / iris / include / notifier.h
1 #ifndef IRIS_NOTIFIER_H_
2 #define IRIS_NOTIFIER_H_
3 #include <vector>
4
5 namespace iris {
6
7 // Bitmask at the lowest bits of a long type
8 // representing types of notification.
9 enum ntf_type{
10     ntf_msg = 1,           // first bit for message
11     ntf_queue_deletion = 2, // second bit for queue deletion
12     ntf_type_mask = 3
13 };
14
15 typedef long ntf_t;
16
17 class notifier {
18 public:
19     notifier();
20     ~notifier();
21     // send a notification to the receiver
22     void notify(const ntf_t & ntf);
23     // wait for notifications
24     // return false if timed out or on error
25     bool wait(long timeout, std::vector<ntf_t> & ntfs);
26     static inline ntf_t to_ntf_t(long data, ntf_type type) {
27         return data | (int)type;
28     }
29     static inline long to_data_t(ntf_t ntf) {
30         return ntf & ~ntf_type_mask;
31     }
32     static inline ntf_type to_ntf_type(ntf_t ntf) {
33         return static_cast<ntf_type>(ntf & ntf_type_mask);
34     }
35 private:
36     int  m_pipe[2];
37     long m_poll_time;
38 };
39
40 }
41 #endif