nodestack: add release sequence breakage backtracking
[c11tester.git] / schedule.h
1 /** @file schedule.h
2  *      @brief Thread scheduler.
3  */
4
5 #ifndef __SCHEDULE_H__
6 #define __SCHEDULE_H__
7
8 #include <list>
9 #include "mymemory.h"
10
11 /* Forward declaration */
12 class Thread;
13
14 typedef enum enabled_type {
15         THREAD_DISABLED,
16         THREAD_ENABLED,
17         THREAD_SLEEP_SET
18 } enabled_type_t;
19
20 /** @brief The Scheduler class performs the mechanics of Thread execution
21  * scheduling. */
22 class Scheduler {
23 public:
24         Scheduler();
25         void add_thread(Thread *t);
26         void remove_thread(Thread *t);
27         void sleep(Thread *t);
28         void wake(Thread *t);
29         Thread * next_thread(Thread *t);
30         Thread * get_current_thread() const;
31         void print() const;
32         enabled_type_t * get_enabled() { return enabled; };
33         bool is_enabled(Thread *t) const;
34
35         SNAPSHOTALLOC
36 private:
37         /** The list of available Threads that are not currently running */
38         enabled_type_t *enabled;
39         int enabled_len;
40         int curr_thread_index;
41         void set_enabled(Thread *t, enabled_type_t enabled_status);
42
43         /** The currently-running Thread */
44         Thread *current;
45 };
46
47 #endif /* __SCHEDULE_H__ */