2012-06-03 01:14:25 -05:00
|
|
|
/**
|
|
|
|
The rust scheduler. Schedulers may be added to the kernel
|
|
|
|
dynamically and they run until there are no more tasks to
|
|
|
|
schedule. Most of the scheduler work is carried out in worker
|
|
|
|
threads by rust_sched_loop.
|
|
|
|
*/
|
|
|
|
|
2012-02-03 17:12:18 -06:00
|
|
|
#ifndef RUST_SCHEDULER_H
|
|
|
|
#define RUST_SCHEDULER_H
|
|
|
|
|
2012-04-02 22:18:01 -05:00
|
|
|
#include "rust_globals.h"
|
|
|
|
#include "util/array_list.h"
|
|
|
|
#include "rust_kernel.h"
|
2012-07-20 17:47:47 -05:00
|
|
|
#include "rust_refcount.h"
|
2012-02-03 17:12:18 -06:00
|
|
|
|
2012-03-29 17:21:32 -05:00
|
|
|
class rust_sched_launcher;
|
2012-04-01 19:22:24 -05:00
|
|
|
class rust_sched_launcher_factory;
|
2012-03-29 17:21:32 -05:00
|
|
|
|
2012-02-03 17:12:18 -06:00
|
|
|
class rust_scheduler : public kernel_owned<rust_scheduler> {
|
2012-07-20 17:47:47 -05:00
|
|
|
RUST_ATOMIC_REFCOUNT();
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2693): Make these private
|
2012-02-03 17:12:18 -06:00
|
|
|
public:
|
|
|
|
rust_kernel *kernel;
|
|
|
|
private:
|
2012-04-01 18:38:42 -05:00
|
|
|
// Protects live_threads, live_tasks, cur_thread, may_exit
|
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-04-01 18:38:42 -05:00
|
|
|
size_t cur_thread;
|
|
|
|
bool may_exit;
|
2012-09-14 08:01:17 -05:00
|
|
|
bool killed;
|
2012-02-04 16:54:10 -06:00
|
|
|
|
2012-09-14 08:01:17 -05:00
|
|
|
rust_sched_launcher_factory *launchfac;
|
2012-03-29 17:21:32 -05:00
|
|
|
array_list<rust_sched_launcher *> threads;
|
2012-09-14 08:01:17 -05:00
|
|
|
const size_t max_num_threads;
|
2012-02-03 17:12:18 -06:00
|
|
|
|
2012-02-06 20:00:49 -06:00
|
|
|
rust_sched_id id;
|
|
|
|
|
2012-02-03 17:12:18 -06:00
|
|
|
void destroy_task_threads();
|
|
|
|
|
2012-09-14 08:01:17 -05:00
|
|
|
rust_sched_launcher *create_task_thread(int id);
|
2012-03-29 17:21:32 -05:00
|
|
|
void destroy_task_thread(rust_sched_launcher *thread);
|
2012-02-03 17:12:18 -06:00
|
|
|
|
2012-02-07 01:38:22 -06:00
|
|
|
void exit();
|
|
|
|
|
2012-07-20 17:47:47 -05:00
|
|
|
// Called when refcount reaches zero
|
|
|
|
void delete_this();
|
|
|
|
|
2012-02-03 17:12:18 -06:00
|
|
|
public:
|
2012-09-14 08:01:17 -05:00
|
|
|
rust_scheduler(rust_kernel *kernel, size_t max_num_threads,
|
2012-07-20 17:06:17 -05:00
|
|
|
rust_sched_id id, bool allow_exit, bool killed,
|
2012-04-01 20:42:28 -05:00
|
|
|
rust_sched_launcher_factory *launchfac);
|
2012-02-03 17:12:18 -06:00
|
|
|
|
|
|
|
void start_task_threads();
|
2012-02-27 15:36:54 -06:00
|
|
|
void join_task_threads();
|
2012-02-03 17:12:18 -06:00
|
|
|
void kill_all_tasks();
|
2012-03-14 22:22:34 -05:00
|
|
|
rust_task* 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-09-14 08:01:17 -05:00
|
|
|
size_t max_number_of_threads();
|
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-04-01 18:38:42 -05:00
|
|
|
// Tells the scheduler that as soon as it runs out of tasks
|
|
|
|
// to run it should exit
|
|
|
|
void allow_exit();
|
2012-04-03 19:39:35 -05:00
|
|
|
void disallow_exit();
|
2012-02-03 17:12:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* RUST_SCHEDULER_H */
|