I may need to replace the scheduler in the future, so modularize it.
#define __MODEL_H__
struct model_checker {
+ struct scheduler *scheduler;
};
#endif /* __MODEL_H__ */
+#include <stdlib.h>
+
#include "libthreads.h"
#include "schedule.h"
#include "common.h"
+#include "model.h"
struct thread_list_node {
struct thread *this;
{
return dequeue_thread();
}
+
+void scheduler_init(struct model_checker *mod)
+{
+ struct scheduler *sched;
+
+ /* Initialize FCFS scheduler */
+ sched = malloc(sizeof(*sched));
+ sched->init = NULL;
+ sched->exit = NULL;
+ sched->add_thread = schedule_add_thread;
+ sched->next_thread = schedule_choose_next;
+ sched->get_current_thread = thread_current;
+ mod->scheduler = sched;
+}
#define __SCHEDULE_H__
#include "libthreads.h"
+#include "model.h"
+struct scheduler {
+ void (*init)(void);
+ void (*exit)(void);
+ void (*add_thread)(struct thread *t);
+ struct thread * (*next_thread)(void);
+ struct thread * (*get_current_thread)(void);
+
+ void *priv;
+};
+
+void scheduler_init(struct model_checker *mod);
void schedule_add_thread(struct thread *t);
struct thread *schedule_choose_next(void);