rust/src/rt/rust_kernel.h

83 lines
2.1 KiB
C
Raw Normal View History

// -*- c++ -*-
#ifndef RUST_KERNEL_H
#define RUST_KERNEL_H
2012-02-07 18:11:57 -06:00
#include <map>
#include <vector>
#include "memory_region.h"
#include "rust_log.h"
struct rust_task_thread;
2012-02-09 00:08:24 -06:00
class rust_scheduler;
2012-02-07 18:11:57 -06:00
typedef std::map<rust_sched_id, rust_scheduler*> sched_map;
/**
* A global object shared by all thread domains. Most of the data structures
* in this class are synchronized since they are accessed from multiple
* threads.
*/
2011-07-29 13:00:44 -05:00
class rust_kernel {
memory_region _region;
rust_log _log;
public:
rust_srv *srv;
private:
// Protects live_tasks, max_task_id and task_table
lock_and_signal task_lock;
// Tracks the number of tasks that are being managed by
// schedulers. When this hits 0 we will tell all schedulers
// to exit.
uintptr_t live_tasks;
// The next task id
rust_task_id max_task_id;
hash_map<rust_task_id, rust_task *> task_table;
lock_and_signal rval_lock;
int rval;
// Protects max_sched_id and sched_table, join_list
lock_and_signal sched_lock;
// The next scheduler id
2012-02-07 18:11:57 -06:00
rust_sched_id max_sched_id;
// A map from scheduler ids to schedulers. When this is empty
// the kernel terminates
2012-02-07 18:11:57 -06:00
sched_map sched_table;
// A list of scheduler ids that are ready to exit
std::vector<rust_sched_id> join_list;
public:
struct rust_env *env;
rust_kernel(rust_srv *srv);
void log(uint32_t level, char const *fmt, ...);
void fatal(char const *fmt, ...);
void *malloc(size_t size, const char *tag);
2011-07-06 00:44:22 -05:00
void *realloc(void *mem, size_t size);
void free(void *mem);
void fail();
rust_sched_id create_scheduler(size_t num_threads);
rust_scheduler* get_scheduler_by_id(rust_sched_id id);
// Called by a scheduler to indicate that it is terminating
void release_scheduler_id(rust_sched_id id);
int wait_for_schedulers();
2011-06-28 13:34:20 -05:00
#ifdef __WIN32__
void win32_require(LPCTSTR fn, BOOL ok);
#endif
2011-07-23 16:01:43 -05:00
void register_task(rust_task *task);
rust_task *get_task_by_id(rust_task_id id);
void release_task_id(rust_task_id tid);
void set_exit_status(int code);
};
#endif /* RUST_KERNEL_H */