2012-02-03 17:12:18 -06:00
|
|
|
#ifndef RUST_SCHEDULER_H
|
|
|
|
#define RUST_SCHEDULER_H
|
|
|
|
|
|
|
|
#include "rust_internal.h"
|
|
|
|
|
|
|
|
class rust_scheduler : public kernel_owned<rust_scheduler> {
|
|
|
|
// FIXME: Make these private
|
|
|
|
public:
|
|
|
|
rust_kernel *kernel;
|
|
|
|
rust_srv *srv;
|
|
|
|
rust_env *env;
|
|
|
|
private:
|
2012-02-04 16:54:10 -06:00
|
|
|
// Protects the random number context and live_threads
|
2012-02-03 17:12:18 -06:00
|
|
|
lock_and_signal lock;
|
2012-02-04 16:54:10 -06:00
|
|
|
// When this hits zero we'll tell the kernel to release us
|
|
|
|
uintptr_t live_threads;
|
2012-02-07 01:38:22 -06:00
|
|
|
// When this hits zero we'll tell the threads to exit
|
|
|
|
uintptr_t live_tasks;
|
2012-02-03 17:12:18 -06:00
|
|
|
randctx rctx;
|
2012-02-04 16:54:10 -06:00
|
|
|
|
|
|
|
array_list<rust_task_thread *> threads;
|
2012-02-03 17:12:18 -06:00
|
|
|
const size_t num_threads;
|
|
|
|
|
2012-02-06 20:00:49 -06:00
|
|
|
rust_sched_id id;
|
|
|
|
|
2012-02-03 17:12:18 -06:00
|
|
|
void create_task_threads();
|
|
|
|
void destroy_task_threads();
|
|
|
|
|
|
|
|
rust_task_thread *create_task_thread(int id);
|
|
|
|
void destroy_task_thread(rust_task_thread *thread);
|
|
|
|
|
2012-02-07 01:38:22 -06:00
|
|
|
void exit();
|
|
|
|
|
2012-02-03 17:12:18 -06:00
|
|
|
public:
|
2012-02-06 20:00:49 -06:00
|
|
|
rust_scheduler(rust_kernel *kernel, rust_srv *srv, size_t num_threads,
|
|
|
|
rust_sched_id id);
|
2012-02-03 17:12:18 -06:00
|
|
|
~rust_scheduler();
|
|
|
|
|
|
|
|
void start_task_threads();
|
|
|
|
void kill_all_tasks();
|
|
|
|
rust_task_id create_task(rust_task *spawner,
|
|
|
|
const char *name,
|
|
|
|
size_t init_stack_sz);
|
|
|
|
rust_task_id create_task(rust_task *spawner, const char *name);
|
2012-02-04 16:54:10 -06:00
|
|
|
|
2012-02-07 01:38:22 -06:00
|
|
|
void release_task();
|
|
|
|
|
2012-02-03 17:12:18 -06:00
|
|
|
size_t number_of_threads();
|
2012-02-04 16:54:10 -06:00
|
|
|
// Called by each thread when it terminates. When all threads
|
|
|
|
// terminate the scheduler does as well.
|
|
|
|
void release_task_thread();
|
2012-02-07 19:43:54 -06:00
|
|
|
|
|
|
|
rust_sched_id get_id() { return id; }
|
2012-02-03 17:12:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* RUST_SCHEDULER_H */
|