2011-05-31 17:44:54 -07:00
|
|
|
// -*- c++ -*-
|
2010-08-27 18:26:36 -07:00
|
|
|
#ifndef RUST_KERNEL_H
|
|
|
|
#define RUST_KERNEL_H
|
|
|
|
|
2011-09-23 11:42:20 -07:00
|
|
|
#include "memory_region.h"
|
|
|
|
#include "rust_log.h"
|
|
|
|
|
|
|
|
struct rust_scheduler;
|
|
|
|
|
2010-09-07 18:39:07 -07: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 11:00:44 -07:00
|
|
|
class rust_kernel {
|
2011-07-18 12:02:26 -07:00
|
|
|
memory_region _region;
|
2010-08-27 18:26:36 -07:00
|
|
|
rust_log _log;
|
2011-07-23 19:03:02 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
rust_srv *srv;
|
|
|
|
private:
|
2010-09-08 19:13:49 -07:00
|
|
|
lock_and_signal _kernel_lock;
|
2010-09-07 18:39:07 -07:00
|
|
|
|
2011-07-23 19:03:02 -07:00
|
|
|
array_list<rust_scheduler *> threads;
|
|
|
|
|
|
|
|
randctx rctx;
|
2011-06-28 12:54:41 -07:00
|
|
|
|
2011-07-23 19:03:02 -07:00
|
|
|
rust_scheduler *create_scheduler(int id);
|
|
|
|
void destroy_scheduler(rust_scheduler *sched);
|
|
|
|
|
|
|
|
void create_schedulers();
|
|
|
|
void destroy_schedulers();
|
2010-09-07 18:39:07 -07:00
|
|
|
|
2011-08-08 13:38:20 -07:00
|
|
|
rust_task_id max_id;
|
|
|
|
hash_map<rust_task_id, rust_task *> task_table;
|
2011-07-23 19:03:02 -07:00
|
|
|
|
2011-08-08 13:38:20 -07:00
|
|
|
public:
|
2011-07-25 18:07:20 -07:00
|
|
|
const size_t num_threads;
|
2011-07-23 19:03:02 -07:00
|
|
|
int rval;
|
|
|
|
|
|
|
|
volatile int live_tasks;
|
2011-07-27 14:34:39 -07:00
|
|
|
struct rust_env *env;
|
|
|
|
|
2011-07-23 19:03:02 -07:00
|
|
|
rust_kernel(rust_srv *srv, size_t num_threads);
|
2010-09-07 18:39:07 -07:00
|
|
|
|
|
|
|
bool is_deadlocked();
|
|
|
|
|
2010-09-15 11:56:45 -07:00
|
|
|
void signal_kernel_lock();
|
2011-07-25 18:00:37 -07:00
|
|
|
void wakeup_schedulers();
|
2010-09-15 11:56:45 -07:00
|
|
|
|
2011-06-28 12:15:41 -07:00
|
|
|
void log_all_scheduler_state();
|
2011-04-19 12:21:57 +02:00
|
|
|
void log(uint32_t level, char const *fmt, ...);
|
2011-07-06 15:06:30 -07:00
|
|
|
void fatal(char const *fmt, ...);
|
2010-08-27 18:26:36 -07:00
|
|
|
virtual ~rust_kernel();
|
2010-09-07 18:39:07 -07:00
|
|
|
|
2011-07-18 12:02:26 -07:00
|
|
|
void *malloc(size_t size, const char *tag);
|
2011-07-05 22:44:22 -07:00
|
|
|
void *realloc(void *mem, size_t size);
|
2010-09-07 18:39:07 -07:00
|
|
|
void free(void *mem);
|
2011-06-24 15:56:12 -07:00
|
|
|
|
2011-08-10 12:57:53 -07:00
|
|
|
void fail();
|
|
|
|
|
2011-07-23 19:03:02 -07:00
|
|
|
int start_task_threads();
|
2011-06-28 11:34:20 -07:00
|
|
|
|
|
|
|
#ifdef __WIN32__
|
|
|
|
void win32_require(LPCTSTR fn, BOOL ok);
|
|
|
|
#endif
|
2011-07-23 14:01:43 -07:00
|
|
|
|
2011-08-08 13:38:20 -07: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 18:26:36 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* RUST_KERNEL_H */
|