2011-05-31 19:44:54 -05:00
|
|
|
// -*- c++ -*-
|
2010-08-27 20:26:36 -05:00
|
|
|
#ifndef RUST_KERNEL_H
|
|
|
|
#define RUST_KERNEL_H
|
|
|
|
|
2012-02-07 18:11:57 -06:00
|
|
|
#include <map>
|
2012-02-27 15:36:54 -06:00
|
|
|
#include <vector>
|
2011-09-23 13:42:20 -05:00
|
|
|
#include "memory_region.h"
|
|
|
|
#include "rust_log.h"
|
|
|
|
|
2012-02-03 14:47:01 -06:00
|
|
|
struct rust_task_thread;
|
2012-02-09 00:08:24 -06:00
|
|
|
class rust_scheduler;
|
2011-09-23 13:42:20 -05:00
|
|
|
|
2012-02-07 18:11:57 -06:00
|
|
|
typedef std::map<rust_sched_id, rust_scheduler*> sched_map;
|
|
|
|
|
2010-09-07 20:39:07 -05:00
|
|
|
/**
|
|
|
|
* 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 {
|
2011-07-18 14:02:26 -05:00
|
|
|
memory_region _region;
|
2010-08-27 20:26:36 -05:00
|
|
|
rust_log _log;
|
2011-07-23 21:03:02 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
rust_srv *srv;
|
|
|
|
private:
|
2012-02-04 02:03:45 -06:00
|
|
|
// The next task id
|
2012-02-03 19:26:54 -06:00
|
|
|
rust_task_id max_task_id;
|
|
|
|
|
2012-03-14 19:24:19 -05:00
|
|
|
// Protects max_port_id and port_table
|
|
|
|
lock_and_signal port_lock;
|
|
|
|
// The next port id
|
|
|
|
rust_task_id max_port_id;
|
|
|
|
hash_map<rust_port_id, rust_port *> port_table;
|
|
|
|
|
2012-02-03 19:26:54 -06:00
|
|
|
lock_and_signal rval_lock;
|
2012-01-13 00:17:21 -06:00
|
|
|
int rval;
|
|
|
|
|
2012-02-27 15:36:54 -06:00
|
|
|
// Protects max_sched_id and sched_table, join_list
|
2012-02-04 16:54:10 -06:00
|
|
|
lock_and_signal sched_lock;
|
2012-02-27 15:36:54 -06:00
|
|
|
// The next scheduler id
|
2012-02-07 18:11:57 -06:00
|
|
|
rust_sched_id max_sched_id;
|
2012-02-27 15:36:54 -06:00
|
|
|
// 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;
|
2012-02-27 15:36:54 -06:00
|
|
|
// A list of scheduler ids that are ready to exit
|
|
|
|
std::vector<rust_sched_id> join_list;
|
2012-02-04 16:54:10 -06:00
|
|
|
|
2011-08-08 15:38:20 -05:00
|
|
|
public:
|
2011-07-23 21:03:02 -05:00
|
|
|
|
2011-07-27 16:34:39 -05:00
|
|
|
struct rust_env *env;
|
|
|
|
|
2012-02-06 23:06:12 -06:00
|
|
|
rust_kernel(rust_srv *srv);
|
2010-09-15 13:56:45 -05:00
|
|
|
|
2011-04-19 05:21:57 -05:00
|
|
|
void log(uint32_t level, char const *fmt, ...);
|
2011-07-06 17:06:30 -05:00
|
|
|
void fatal(char const *fmt, ...);
|
2010-09-07 20:39:07 -05:00
|
|
|
|
2011-07-18 14:02:26 -05:00
|
|
|
void *malloc(size_t size, const char *tag);
|
2011-07-06 00:44:22 -05:00
|
|
|
void *realloc(void *mem, size_t size);
|
2010-09-07 20:39:07 -05:00
|
|
|
void free(void *mem);
|
2012-02-27 17:42:22 -06:00
|
|
|
memory_region *region() { return &_region; }
|
2011-06-24 17:56:12 -05:00
|
|
|
|
2011-08-10 14:57:53 -05:00
|
|
|
void fail();
|
|
|
|
|
2012-02-06 23:06:12 -06:00
|
|
|
rust_sched_id create_scheduler(size_t num_threads);
|
|
|
|
rust_scheduler* get_scheduler_by_id(rust_sched_id id);
|
2012-02-04 16:54:10 -06:00
|
|
|
// Called by a scheduler to indicate that it is terminating
|
2012-02-06 23:06:12 -06:00
|
|
|
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
|
|
|
|
2012-03-14 22:55:57 -05:00
|
|
|
rust_task_id generate_task_id();
|
2012-02-03 17:45:59 -06:00
|
|
|
|
2012-03-14 19:24:19 -05:00
|
|
|
rust_port_id register_port(rust_port *port);
|
|
|
|
rust_port *get_port_by_id(rust_port_id id);
|
|
|
|
void release_port_id(rust_port_id tid);
|
|
|
|
|
2012-01-13 00:17:21 -06:00
|
|
|
void set_exit_status(int code);
|
2010-08-27 20:26:36 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* RUST_KERNEL_H */
|