{
/* First thread created (system_thread) will have id 1 */
this->used_thread_id = 0;
-
- scheduler_init(this);
+ /* Initialize default scheduler */
+ this->scheduler = new DefaultScheduler();
}
ModelChecker::~ModelChecker()
{
- struct scheduler *sched = this->scheduler;
-
- if (sched->exit)
- sched->exit();
- free(sched);
+ delete this->scheduler;
}
void ModelChecker::assign_id(struct thread *t)
#ifndef __MODEL_H__
#define __MODEL_H__
+#include "schedule.h"
+
class ModelChecker {
public:
ModelChecker();
~ModelChecker();
- struct scheduler *scheduler;
+ class Scheduler *scheduler;
struct thread *system_thread;
void add_system_thread(struct thread *t);
return pop;
}
-static void default_add_thread(struct thread *t)
+void DefaultScheduler::add_thread(struct thread *t)
{
DEBUG("thread %d\n", t->id);
enqueue_thread(t);
}
-static struct thread *default_choose_next(void)
+struct thread *DefaultScheduler::next_thread(void)
{
return dequeue_thread();
}
-static struct thread *default_thread_current(void)
+struct thread *DefaultScheduler::get_current_thread(void)
{
return current;
}
-
-void scheduler_init(ModelChecker *mod)
-{
- struct scheduler *sched;
-
- /* Initialize default scheduler */
- sched = (struct scheduler *)malloc(sizeof(*sched));
- sched->init = NULL;
- sched->exit = NULL;
- sched->add_thread = default_add_thread;
- sched->next_thread = default_choose_next;
- sched->get_current_thread = default_thread_current;
- mod->scheduler = sched;
-}
#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;
+class Scheduler {
+public:
+ virtual void add_thread(struct thread *t) = 0;
+ virtual struct thread * next_thread(void) = 0;
+ virtual struct thread * get_current_thread(void) = 0;
};
-void scheduler_init(ModelChecker *mod);
+class DefaultScheduler: public Scheduler {
+public:
+ void add_thread(struct thread *t);
+ struct thread * next_thread(void);
+ struct thread * get_current_thread(void);
+};
#endif /* __SCHEDULE_H__ */