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