model: drop public get_current_node() interface
[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
15 typedef enum enabled_type {
16         THREAD_DISABLED,
17         THREAD_ENABLED,
18         THREAD_SLEEP_SET
19 } enabled_type_t;
20
21 void enabled_type_to_string(enabled_type_t e, char *str);
22
23 /** @brief The Scheduler class performs the mechanics of Thread execution
24  * scheduling. */
25 class Scheduler {
26 public:
27         Scheduler();
28         void add_thread(Thread *t);
29         void remove_thread(Thread *t);
30         void sleep(Thread *t);
31         void wake(Thread *t);
32         Thread * select_next_thread(Node *n);
33         void set_current_thread(Thread *t);
34         Thread * get_current_thread() const;
35         void print() const;
36         enabled_type_t * get_enabled_array() const { return enabled; };
37         void remove_sleep(Thread *t);
38         void add_sleep(Thread *t);
39         enabled_type_t get_enabled(const Thread *t) const;
40         void update_sleep_set(Node *n);
41         bool is_enabled(const Thread *t) const;
42         bool is_enabled(thread_id_t tid) const;
43         bool is_sleep_set(const Thread *t) const;
44         bool all_threads_sleeping() const;
45         void set_scheduler_thread(thread_id_t tid);
46
47         SNAPSHOTALLOC
48 private:
49         /** The list of available Threads that are not currently running */
50         enabled_type_t *enabled;
51         int enabled_len;
52         int curr_thread_index;
53         void set_enabled(Thread *t, enabled_type_t enabled_status);
54
55         /** The currently-running Thread */
56         Thread *current;
57 };
58
59 #endif /* __SCHEDULE_H__ */