Agora  1.2.0
Agora project
doer.h
Go to the documentation of this file.
1 
6 #ifndef DOER_H_
7 #define DOER_H_
8 
9 #include <cstddef>
10 
12 #include "concurrentqueue.h"
13 #include "config.h"
14 #include "message.h"
15 #include "utils.h"
16 
17 class Doer {
18  public:
19  virtual bool TryLaunch(
21  moodycamel::ConcurrentQueue<EventData>& complete_task_queue,
22  moodycamel::ProducerToken* worker_ptok) {
23  EventData req_event;
24  if (task_queue.try_dequeue(req_event)) {
25  // We will enqueue one response event containing results for all
26  // request tags in the request event
27  EventData resp_event;
28  resp_event.num_tags_ = req_event.num_tags_;
29 
30  for (size_t i = 0; i < req_event.num_tags_; i++) {
31  EventData resp_i = Launch(req_event.tags_[i]);
32  RtAssert(resp_i.num_tags_ == 1, "Invalid num_tags in resp");
33  resp_event.tags_[i] = resp_i.tags_[0];
34  resp_event.event_type_ = resp_i.event_type_;
35  }
36 
37  TryEnqueueFallback(&complete_task_queue, worker_ptok, resp_event);
38  return true;
39  }
40  return false;
41  }
42 
45  virtual EventData Launch(size_t tag) {
46  unused(tag);
47  RtAssert(false, "Doer: Launch(tag) not implemented");
48  return EventData();
49  }
50 
53  virtual EventData Launch(size_t tag, EventType event_type) {
54  unused(tag);
55  unused(event_type);
56  RtAssert(false, "Doer: Launch(tag, event_type) not implemented");
57  return EventData();
58  }
59 
60  protected:
61  Doer(Config* in_config, int in_tid) : cfg_(in_config), tid_(in_tid) {}
62  virtual ~Doer() = default;
63 
65  int tid_; // Thread ID of this Doer
66 };
67 #endif // DOER_H_
moodycamel::ProducerToken
Definition: concurrentqueue.h:630
Doer::Doer
Doer(Config *in_config, int in_tid)
Definition: doer.h:61
concurrent_queue_wrapper.h
Doer::Launch
virtual EventData Launch(size_t tag, EventType event_type)
Definition: doer.h:53
unused
#define unused(x)
Definition: utils.h:14
EventType
EventType
Definition: symbols.h:42
Doer::Launch
virtual EventData Launch(size_t tag)
Definition: doer.h:45
EventData::tags_
std::array< size_t, kMaxTags > tags_
Definition: message.h:146
EventData::event_type_
EventType event_type_
Definition: message.h:144
Doer
Definition: doer.h:17
Doer::tid_
int tid_
Definition: doer.h:65
TryEnqueueFallback
static void TryEnqueueFallback(moodycamel::ConcurrentQueue< EventData > *mc_queue, moodycamel::ProducerToken *producer_token, const EventData &event)
Definition: concurrent_queue_wrapper.h:18
EventData
Definition: message.h:142
EventData::num_tags_
uint32_t num_tags_
Definition: message.h:145
message.h
Self defined functions for message storage and passing.
i
for i
Definition: generate_data.m:107
Doer::cfg_
Config * cfg_
Definition: doer.h:64
moodycamel::ConcurrentQueue< EventData >
Doer::~Doer
virtual ~Doer()=default
Config
Definition: config.h:26
RtAssert
static void RtAssert(bool condition, const char *throw_str)
Definition: utils.h:104
Doer::TryLaunch
virtual bool TryLaunch(moodycamel::ConcurrentQueue< EventData > &task_queue, moodycamel::ConcurrentQueue< EventData > &complete_task_queue, moodycamel::ProducerToken *worker_ptok)
Definition: doer.h:19
config.h
Declaration file for the configuration class which importants json configuration values into class va...
moodycamel::ConcurrentQueue::try_dequeue
bool try_dequeue(U &item)
Definition: concurrentqueue.h:1104
concurrentqueue.h