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
|
|
|
|
|
2011-09-23 13:42:20 -05:00
|
|
|
#include "memory_region.h"
|
|
|
|
#include "rust_log.h"
|
|
|
|
|
|
|
|
struct rust_scheduler;
|
|
|
|
|
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:
|
2010-09-08 21:13:49 -05:00
|
|
|
lock_and_signal _kernel_lock;
|
2010-09-07 20:39:07 -05:00
|
|
|
|
2011-07-23 21:03:02 -05:00
|
|
|
array_list<rust_scheduler *> threads;
|
|
|
|
|
|
|
|
randctx rctx;
|
2011-06-28 14:54:41 -05:00
|
|
|
|
2011-07-23 21:03:02 -05:00
|
|
|
rust_scheduler *create_scheduler(int id);
|
|
|
|
void destroy_scheduler(rust_scheduler *sched);
|
|
|
|
|
|
|
|
void create_schedulers();
|
|
|
|
void destroy_schedulers();
|
2010-09-07 20:39:07 -05:00
|
|
|
|
2011-08-08 15:38:20 -05:00
|
|
|
rust_task_id max_id;
|
|
|
|
hash_map<rust_task_id, rust_task *> task_table;
|
2011-07-23 21:03:02 -05:00
|
|
|
|
2011-08-08 15:38:20 -05:00
|
|
|
public:
|
2011-07-25 20:07:20 -05:00
|
|
|
const size_t num_threads;
|
2011-07-23 21:03:02 -05:00
|
|
|
int rval;
|
|
|
|
|
|
|
|
volatile int live_tasks;
|
2011-07-27 16:34:39 -05:00
|
|
|
struct rust_env *env;
|
|
|
|
|
2011-07-23 21:03:02 -05:00
|
|
|
rust_kernel(rust_srv *srv, size_t num_threads);
|
2010-09-07 20:39:07 -05:00
|
|
|
|
|
|
|
bool is_deadlocked();
|
|
|
|
|
2010-09-15 13:56:45 -05:00
|
|
|
void signal_kernel_lock();
|
2011-07-25 20:00:37 -05:00
|
|
|
void wakeup_schedulers();
|
2010-09-15 13:56:45 -05:00
|
|
|
|
2011-06-28 14:15:41 -05:00
|
|
|
void log_all_scheduler_state();
|
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-08-27 20:26:36 -05:00
|
|
|
virtual ~rust_kernel();
|
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);
|
2011-06-24 17:56:12 -05:00
|
|
|
|
2011-08-10 14:57:53 -05:00
|
|
|
void fail();
|
|
|
|
|
2011-07-23 21:03:02 -05:00
|
|
|
int start_task_threads();
|
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
|
|
|
|
2011-08-08 15:38:20 -05:00
|
|
|
rust_task_id create_task(rust_task *spawner, const char *name);
|
|
|
|
rust_task *get_task_by_id(rust_task_id id);
|
|
|
|
void release_task_id(rust_task_id tid);
|
2010-08-27 20:26:36 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* RUST_KERNEL_H */
|