/*
* User program API functions
*/
-int thrd_create(thrd_t *t, void (*start_routine)(), void *arg)
+int thrd_create(thrd_t *t, void (*start_routine)(void *), void *arg)
{
int ret;
DBG();
extern "C" {
#endif
- typedef void (*thrd_start_t)();
+ typedef void (*thrd_start_t)(void *);
typedef int thrd_t;
do {
/* Start user program */
- model->add_thread(new Thread(&user_thread, &user_main, NULL));
+ model->add_thread(new Thread(&user_thread, (void (*)(void *)) &user_main, NULL));
/* Wait for all threads to complete */
thread_wait_finish();
+/* -*- Mode: C; indent-tabs-mode: t -*- */
+
#include "threads.h"
#include "schedule.h"
#include "common.h"
#include "model.h"
+Scheduler::Scheduler():
+current(NULL)
+{
+}
+
void Scheduler::add_thread(Thread *t)
{
DEBUG("thread %d\n", t->get_id());
+/* -*- Mode: C; indent-tabs-mode: t -*- */
+
#ifndef __SCHEDULE_H__
#define __SCHEDULE_H__
class Scheduler {
public:
+ Scheduler();
void add_thread(Thread *t);
void remove_thread(Thread *t);
Thread * next_thread(void);
context.uc_stack.ss_size = STACK_SIZE;
context.uc_stack.ss_flags = 0;
context.uc_link = model->get_system_context();
- makecontext(&context, start_routine, 1);
+ makecontext(&context, thread_startup, 0);
return 0;
}
}
}
-Thread::Thread(thrd_t *t, void (*func)(), void *a) {
+Thread::Thread(thrd_t *t, void (*func)(void *), void *a) {
int ret;
user_thread = t;
class Thread {
public:
- Thread(thrd_t *t, void (*func)(), void *a);
+ Thread(thrd_t *t, void (*func)(void *), void *a);
~Thread();
void complete();
thread_id_t get_id();
thrd_t get_thrd_t() { return *user_thread; }
Thread * get_parent() { return parent; }
+ friend void thread_startup();
MEMALLOC
private:
int create_context();
Thread *parent;
- void (*start_routine)();
+ void (*start_routine)(void *);
void *arg;
ucontext_t context;
void *stack;