#include "schedule.h"
#include "common.h"
-/* global "model" struct */
+/* global "model" object */
#include "model.h"
#define STACK_SIZE (1024 * 1024)
static int create_initial_thread(struct thread *t)
{
memset(t, 0, sizeof(*t));
- model_checker_assign_id(t);
+ model->assign_id(t);
return create_context(t);
}
-static int thread_swap(struct thread *old, struct thread *new)
+static int thread_swap(struct thread *t1, struct thread *t2)
{
- return swapcontext(&old->context, &new->context);
+ return swapcontext(&t1->context, &t2->context);
}
static void thread_dispose(struct thread *t)
{
- DEBUG("completed thread %d\n", thread_current()->index);
+ DEBUG("completed thread %d\n", thread_current()->id);
t->state = THREAD_COMPLETED;
stack_free(t->stack);
}
next = model->scheduler->next_thread();
if (next)
next->state = THREAD_RUNNING;
- DEBUG("(%d, %d)\n", curr ? curr->index : -1, next ? next->index : -1);
+ DEBUG("(%d, %d)\n", curr ? curr->id : -1, next ? next->id : -1);
if (!next)
return 1;
return thread_swap(model->system_thread, next);
/*
* User program API functions
*/
-int thread_create(struct thread *t, void (*start_routine), void *arg)
+int thread_create(struct thread *t, void (*start_routine)(), void *arg)
{
int ret = 0;
DBG();
memset(t, 0, sizeof(*t));
- model_checker_assign_id(t);
- DEBUG("create thread %d\n", t->index);
+ model->assign_id(t);
+ DEBUG("create thread %d\n", t->id);
t->start_routine = start_routine;
t->arg = arg;
struct thread user_thread;
struct thread *main_thread;
- model_checker_init();
+ model = new ModelChecker();
- main_thread = malloc(sizeof(struct thread));
+ main_thread = (struct thread *)malloc(sizeof(*main_thread));
create_initial_thread(main_thread);
- model_checker_add_system_thread(main_thread);
+ model->add_system_thread(main_thread);
/* Start user program */
thread_create(&user_thread, &user_main, NULL);