Assign each predicate's initial weight ad 100. Remove some unused function and data...
[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 "mymemory.h"
9 #include "modeltypes.h"
10 #include "classlist.h"
11
12 typedef enum enabled_type {
13         THREAD_DISABLED,
14         THREAD_ENABLED,
15         THREAD_SLEEP_SET
16 } enabled_type_t;
17
18 void enabled_type_to_string(enabled_type_t e, char *str);
19
20 /** @brief The Scheduler class performs the mechanics of Thread execution
21  * scheduling. */
22 class Scheduler {
23 public:
24         Scheduler();
25         void register_engine(ModelExecution *execution);
26
27         void add_thread(Thread *t);
28         void remove_thread(Thread *t);
29         void sleep(Thread *t);
30         void wake(Thread *t);
31         Thread * select_next_thread();
32         void set_current_thread(Thread *t);
33         Thread * get_current_thread() const;
34         void print() const;
35         enabled_type_t * get_enabled_array() const { return enabled; };
36         void remove_sleep(Thread *t);
37         void add_sleep(Thread *t);
38         enabled_type_t get_enabled(const Thread *t) const;
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         ModelExecution *execution;
48         /** The list of available Threads that are not currently running */
49         enabled_type_t *enabled;
50         int enabled_len;
51         int curr_thread_index;
52         void set_enabled(Thread *t, enabled_type_t enabled_status);
53
54         /** The currently-running Thread */
55         Thread *current;
56 };
57
58 #endif  /* __SCHEDULE_H__ */