-
Notifications
You must be signed in to change notification settings - Fork 1
/
Scheduler.h
98 lines (85 loc) · 2.43 KB
/
Scheduler.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Scheduler.h
//
//
// Created by Benedikt Hegner on 4/10/12.
// Copyright (c) 2012 CERN. All rights reserved.
//
#ifndef _Scheduler_h
#define _Scheduler_h
// include c++
#include <map>
#include <vector>
#include <string>
#include <bitset>
// include tbb
#include "tbb/concurrent_queue.h"
#include "tbb/concurrent_vector.h"
#include "tbb/task.h"
//include fwk
#include "Algo.h"
#include "AlgoPool.h"
#include "Context.h"
//typedef uint64_t state_type;
typedef std::bitset<1000> state_type;
// forward declarations
class Scheduler;
class EventLoopManager;
/**
* The AlgoTaskId the item used for call back once tbb finished the AlgoTask
*/
class EventState;
class AlgoTaskId {
public:
AlgoTaskId(AlgoBase* algo, unsigned int algo_id, EventState* event_state): algo_(algo),algo_id_(algo_id), event_state_(event_state){};
AlgoBase* algo_;
unsigned int algo_id_;
EventState* event_state_;
};
/**
* The tbb::task implementation that gets passed to tbb::task::enqueue
* as opposed to AlgoTaskId it can be disposed by tbb (as per design)
*/
class AlgoTask : public tbb::task {
public:
AlgoTask(AlgoTaskId* task, Scheduler* scheduler): task_(task), scheduler_(scheduler){};
tbb::task* execute();
AlgoTaskId* task_;
Scheduler* scheduler_;
};
class EventState{
public:
EventState(unsigned int algos) : state(0), context(0), algo_states(algos,NOT_RUN){};
~EventState(){};
state_type state;
Context* context;
std::vector<AlgoState> algo_states;
};
class Scheduler {
public:
Scheduler(Whiteboard& wb);
void task_cleanup();
void algo_is_done(AlgoTaskId* task_id);
void start_event(unsigned int event);
void initialise(AlgoPool* algo_pool, const std::vector<AlgoBase*>* algos, EventLoopManager* looper);
void stop(){has_to_stop_ = true;};
void operator() ();
private:
std::vector<state_type> compute_dependencies();
const std::vector<AlgoBase*>* algos_;
AlgoPool* algo_pool_;
state_type termination_requirement_;
Whiteboard& wb_;
tbb::concurrent_queue<AlgoTaskId*> done_queue_;
tbb::concurrent_queue<unsigned int> new_events_queue_;
EventLoopManager* loop_manager_;
tbb::atomic<bool> has_to_stop_;
};
class SchedulerTask : public tbb::task {
public:
SchedulerTask(Scheduler* scheduler): scheduler_(scheduler){};
tbb::task* execute(){(*scheduler_)();return NULL;};
private:
Scheduler* scheduler_;
};
#endif