forked from rmbianchi/concurrent_framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Whiteboard.h
63 lines (53 loc) · 1.79 KB
/
Whiteboard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Whiteboard.h
*
* Created on: Mar 26, 2012
* Authors: [email protected] (Riccardo-Maria BIANCHI)
* [email protected] (Benedikt HEGNER)
*/
#ifndef WHITEBOARD_H_
#define WHITEBOARD_H_
// include tbb
#include "tbb/spin_mutex.h"
#include "tbb/concurrent_hash_map.h"
// include c++
#include <list>
#include <vector>
#include <map>
// include fwk
#include "ConcurrentTypes.h"
#include "Context.h"
// forward declarations
class Subscriber;
/**
* the Whiteboard class features a concurrent_hash_map to store published products
* from modules.
* As opposed to operations done via Context this class is not thread safe.
*/
enum ContextStatus {available, in_use, in_cleanup};
class Whiteboard {
public:
// methods
Whiteboard( const char* name, const int number_of_slots);
virtual ~Whiteboard();
const char* get_name() {return name_;};
// I/O methods
// TODO: do a proper handling of object ownership
bool read(DataItem&, const std::string& label, const unsigned int slot_number) const;
void write(const DataItem& item, const::std::string& label, const unsigned int slot_number);
void notify(const void* what = 0);
void print_slot_content(const unsigned int slot_number) const;
bool get_context(Context*&);
void release_context(Context*& context);
unsigned int register_dependency(const std::string& label); // registers a dependency and returns the index in the later used bit mask
private:
const char* name_;
const int number_of_slots_;
unsigned int data_id_counter_;
tbb::spin_mutex my_mutex;
std::vector<StringDataMap*> slots_;
typedef std::pair<Context*,ContextStatus> registry_type;
std::vector<registry_type> contexts_;
std::map<std::string,unsigned int> data_id_map_;
};
#endif /* WHITEBOARD_H_ */