a8a6936bde61d73e33c0138e118d1300bc015c71
[model-checker.git] / model.c
1 #include "model.h"
2 #include "schedule.h"
3 #include <stdlib.h>
4 #include <string.h>
5
6 struct model_checker *model;
7
8 void model_checker_add_system_thread(struct thread *t)
9 {
10         model->system_thread = t;
11 }
12
13 void model_checker_init(void)
14 {
15         model = (struct model_checker *)malloc(sizeof(*model));
16         memset(model, 0, sizeof(*model));
17
18         /* First thread created (system_thread) will have id 1 */
19         model->used_thread_id = 0;
20
21         scheduler_init(model);
22 }
23
24 void model_checker_exit(void)
25 {
26         struct scheduler *sched = model->scheduler;
27
28         if (sched->exit)
29                 sched->exit();
30         free(sched);
31         free(model);
32 }
33
34 void model_checker_assign_id(struct thread *t)
35 {
36         t->id = ++model->used_thread_id;
37 }