LICENSE: add newline at end of file
[cdsspec-compiler.git] / schedule.h
1 /** @file schedule.h
2  *      @brief Thread scheduler.
3  */
4
5 #ifndef __SCHEDULE_H__
6 #define __SCHEDULE_H__
7
8 #include "mymemory.h"
9 #include "modeltypes.h"
10
11 /* Forward declaration */
12 class Thread;
13 class Node;
14 class ModelExecution;
15
16 typedef enum enabled_type {
17         THREAD_DISABLED,
18         THREAD_ENABLED,
19         THREAD_SLEEP_SET
20 } enabled_type_t;
21
22 void enabled_type_to_string(enabled_type_t e, char *str);
23
24 /** @brief The Scheduler class performs the mechanics of Thread execution
25  * scheduling. */
26 class Scheduler {
27 public:
28         Scheduler();
29         void register_engine(ModelExecution *execution);
30
31         void add_thread(Thread *t);
32         void remove_thread(Thread *t);
33         void sleep(Thread *t);
34         void wake(Thread *t);
35         Thread * select_next_thread(Node *n);
36         void set_current_thread(Thread *t);
37         Thread * get_current_thread() const;
38         void print() const;
39         enabled_type_t * get_enabled_array() const { return enabled; };
40         void remove_sleep(Thread *t);
41         void add_sleep(Thread *t);
42         enabled_type_t get_enabled(const Thread *t) const;
43         void update_sleep_set(Node *n);
44         bool is_enabled(const Thread *t) const;
45         bool is_enabled(thread_id_t tid) const;
46         bool is_sleep_set(const Thread *t) const;
47         bool all_threads_sleeping() const;
48         void set_scheduler_thread(thread_id_t tid);
49
50         SNAPSHOTALLOC
51 private:
52         ModelExecution *execution;
53         /** The list of available Threads that are not currently running */
54         enabled_type_t *enabled;
55         int enabled_len;
56         int curr_thread_index;
57         void set_enabled(Thread *t, enabled_type_t enabled_status);
58
59         /** The currently-running Thread */
60         Thread *current;
61 };
62
63 #endif /* __SCHEDULE_H__ */