remove rust_srv

This commit is contained in:
Jon Morton 2012-04-01 22:18:40 -05:00
parent 413994ea3e
commit 128a8b6ed5
19 changed files with 44 additions and 174 deletions

View File

@ -64,7 +64,6 @@ RUNTIME_CS_$(1) := \
rt/rust_port_selector.cpp \
rt/circular_buffer.cpp \
rt/isaac/randport.cpp \
rt/rust_srv.cpp \
rt/rust_kernel.cpp \
rt/rust_shape.cpp \
rt/rust_abi.cpp \

View File

@ -24,8 +24,12 @@ circular_buffer::circular_buffer(rust_kernel *kernel, size_t unit_sz) :
circular_buffer::~circular_buffer() {
KLOG(kernel, mem, "~circular_buffer 0x%" PRIxPTR, this);
assert(_buffer);
W(kernel, _unread == 0,
"freeing circular_buffer with %d unread bytes", _unread);
if (_unread != 0) {
fprintf(stderr, "warning: freeing circular_buffer with"
" %lu unread bytes", _unread);
fflush(stderr);
}
kernel->free(_buffer);
}

View File

@ -23,14 +23,14 @@ void *memory_region::get_data(alloc_header *ptr) {
return (void*)((char *)ptr + HEADER_SIZE);
}
memory_region::memory_region(rust_srv *srv, bool synchronized) :
_srv(srv), _parent(NULL), _live_allocations(0),
_detailed_leaks(srv->env->detailed_leaks),
memory_region::memory_region(rust_env *env, bool synchronized) :
_env(env), _parent(NULL), _live_allocations(0),
_detailed_leaks(env->detailed_leaks),
_synchronized(synchronized) {
}
memory_region::memory_region(memory_region *parent) :
_srv(parent->_srv), _parent(parent), _live_allocations(0),
_env(parent->_env), _parent(parent), _live_allocations(0),
_detailed_leaks(parent->_detailed_leaks),
_synchronized(parent->_synchronized) {
}
@ -59,7 +59,7 @@ void memory_region::free(void *mem) {
}
release_alloc(mem);
maybe_poison(mem);
_srv->free(alloc);
::free(alloc);
}
void *
@ -74,7 +74,7 @@ memory_region::realloc(void *mem, size_t orig_size) {
# endif
size_t size = orig_size + HEADER_SIZE;
alloc_header *newMem = (alloc_header *)_srv->realloc(alloc, size);
alloc_header *newMem = (alloc_header *)::realloc(alloc, size);
# if RUSTRT_TRACK_ALLOCATIONS >= 1
assert(newMem->magic == MAGIC);
@ -105,7 +105,7 @@ void *
memory_region::malloc(size_t size, const char *tag, bool zero) {
size_t old_size = size;
size += HEADER_SIZE;
alloc_header *mem = (alloc_header *)_srv->malloc(size);
alloc_header *mem = (alloc_header *)::malloc(size);
# if RUSTRT_TRACK_ALLOCATIONS >= 1
mem->magic = MAGIC;
@ -222,7 +222,7 @@ memory_region::claim_alloc(void *mem) {
void
memory_region::maybe_poison(void *mem) {
if (!_srv->env->poison_on_free)
if (!_env->poison_on_free)
return;
# if RUSTRT_TRACK_ALLOCATIONS >= 1

View File

@ -22,7 +22,7 @@
// hugely expensive and should only be used as a last resort.
#define RUSTRT_TRACK_ALLOCATIONS 0
class rust_srv;
class rust_env;
class memory_region {
private:
@ -42,7 +42,7 @@ private:
inline alloc_header *get_header(void *mem);
inline void *get_data(alloc_header *);
rust_srv *_srv;
rust_env *_env;
memory_region *_parent;
int _live_allocations;
array_list<alloc_header *> _allocation_list;
@ -58,7 +58,7 @@ private:
void claim_alloc(void *mem);
public:
memory_region(rust_srv *srv, bool synchronized);
memory_region(rust_env *env, bool synchronized);
memory_region(memory_region *parent);
void *malloc(size_t size, const char *tag, bool zero = true);
void *calloc(size_t size, const char *tag);

View File

@ -75,8 +75,7 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
update_log_settings(crate_map, env->logspec);
check_claims = env->check_claims;
rust_srv *srv = new rust_srv(env);
rust_kernel *kernel = new rust_kernel(srv);
rust_kernel *kernel = new rust_kernel(env);
rust_sched_id sched_id = kernel->create_scheduler(env->num_sched_threads);
rust_scheduler *sched = kernel->get_scheduler_by_id(sched_id);
rust_task *root_task = sched->create_task(NULL, "main");
@ -96,7 +95,6 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
int ret = kernel->wait_for_exit();
delete args;
delete kernel;
delete srv;
free_env(env);

View File

@ -95,7 +95,6 @@ template <typename T> struct region_owned {
struct rust_cond { };
#include "memory_region.h"
#include "rust_srv.h"
#include "rust_log.h"
#include "rust_kernel.h"
#include "rust_sched_loop.h"

View File

@ -9,16 +9,15 @@
#define KLOG_ERR_(field, ...) \
KLOG_LVL(this, field, log_err, __VA_ARGS__)
rust_kernel::rust_kernel(rust_srv *srv) :
_region(srv, true),
_log(srv, NULL),
srv(srv),
rust_kernel::rust_kernel(rust_env *env) :
_region(env, true),
_log(env, NULL),
max_task_id(0),
max_port_id(0),
rval(0),
max_sched_id(0),
sched_reaper(this),
env(srv->env)
env(env)
{
}
@ -69,7 +68,7 @@ rust_kernel::create_scheduler(size_t num_threads) {
id = max_sched_id++;
assert(id != INTPTR_MAX && "Hit the maximum scheduler id");
sched = new (this, "rust_scheduler")
rust_scheduler(this, srv, num_threads, id);
rust_scheduler(this, num_threads, id);
bool is_new = sched_table
.insert(std::pair<rust_sched_id,
rust_scheduler*>(id, sched)).second;

View File

@ -22,9 +22,6 @@ class rust_kernel {
memory_region _region;
rust_log _log;
public:
rust_srv *srv;
private:
// The next task id
rust_task_id max_task_id;
@ -50,10 +47,9 @@ private:
rust_sched_reaper sched_reaper;
public:
struct rust_env *env;
rust_kernel(rust_srv *srv);
rust_kernel(rust_env *env);
void log(uint32_t level, char const *fmt, ...);
void fatal(char const *fmt, ...);

View File

@ -40,8 +40,8 @@ log_console_off(rust_env *env) {
}
}
rust_log::rust_log(rust_srv *srv, rust_sched_loop *sched_loop) :
_srv(srv),
rust_log::rust_log(rust_env *env, rust_sched_loop *sched_loop) :
_env(env),
_sched_loop(sched_loop) {
}
@ -98,7 +98,8 @@ rust_log::trace_ln(char *prefix, char *message) {
append_string(buffer, "%s", prefix);
append_string(buffer, "%s", message);
if (_log_to_console) {
_srv->log(buffer);
fprintf(stderr, "rust: %s\n", buffer);
fflush(stderr);
}
_log_lock.unlock();
}

View File

@ -40,7 +40,7 @@ struct rust_task;
class rust_log {
public:
rust_log(rust_srv *srv, rust_sched_loop *sched_loop);
rust_log(rust_env *env, rust_sched_loop *sched_loop);
virtual ~rust_log();
void trace_ln(rust_task *task, uint32_t level, char *message);
@ -48,7 +48,7 @@ public:
bool is_tracing(uint32_t type_bits);
private:
rust_srv *_srv;
rust_env *_env;
rust_sched_loop *_sched_loop;
bool _use_labels;
void trace_ln(rust_task *task, char *message);

View File

@ -3,16 +3,15 @@
const size_t SCHED_STACK_SIZE = 1024*100;
rust_sched_launcher::rust_sched_launcher(rust_scheduler *sched,
rust_srv *srv, int id)
rust_sched_launcher::rust_sched_launcher(rust_scheduler *sched, int id)
: kernel(sched->kernel),
sched_loop(sched, srv, id),
sched_loop(sched, id),
driver(&sched_loop) {
}
rust_thread_sched_launcher::rust_thread_sched_launcher(rust_scheduler *sched,
rust_srv *srv, int id)
: rust_sched_launcher(sched, srv, id),
int id)
: rust_sched_launcher(sched, id),
rust_thread(SCHED_STACK_SIZE) {
}

View File

@ -16,7 +16,7 @@ protected:
rust_sched_driver driver;
public:
rust_sched_launcher(rust_scheduler *sched, rust_srv *srv, int id);
rust_sched_launcher(rust_scheduler *sched, int id);
virtual ~rust_sched_launcher() { }
virtual void start() = 0;
@ -28,7 +28,7 @@ class rust_thread_sched_launcher
:public rust_sched_launcher,
private rust_thread {
public:
rust_thread_sched_launcher(rust_scheduler *sched, rust_srv *srv, int id);
rust_thread_sched_launcher(rust_scheduler *sched, int id);
virtual void start() { rust_thread::start(); }
virtual void run() { driver.start_main_loop(); }
virtual void join() { rust_thread::join(); }

View File

@ -17,10 +17,8 @@ const size_t C_STACK_SIZE = 1024*1024;
bool rust_sched_loop::tls_initialized = false;
rust_sched_loop::rust_sched_loop(rust_scheduler *sched,
rust_srv *srv,
int id) :
_log(srv, this),
rust_sched_loop::rust_sched_loop(rust_scheduler *sched,int id) :
_log(env, this),
id(id),
should_exit(false),
cached_c_stack(NULL),
@ -28,10 +26,10 @@ rust_sched_loop::rust_sched_loop(rust_scheduler *sched,
pump_signal(NULL),
kernel(sched->kernel),
sched(sched),
srv(srv),
log_lvl(log_debug),
min_stack_size(kernel->env->min_stack_size),
env(kernel->env),
local_region(env, false),
// TODO: calculate a per scheduler name.
name("main")
{

View File

@ -69,7 +69,6 @@ private:
public:
rust_kernel *kernel;
rust_scheduler *sched;
rust_srv *srv;
// NB: this is used to filter *runtime-originating* debug
// logging, on a per-scheduler basis. It's not likely what
@ -81,6 +80,7 @@ public:
size_t min_stack_size;
rust_env *env;
memory_region local_region;
randctx rctx;
@ -90,7 +90,7 @@ public:
// Only a pointer to 'name' is kept, so it must live as long as this
// domain.
rust_sched_loop(rust_scheduler *sched, rust_srv *srv, int id);
rust_sched_loop(rust_scheduler *sched, int id);
void activate(rust_task *task);
void log(rust_task *task, uint32_t level, char const *fmt, ...);
rust_log & get_log();

View File

@ -3,12 +3,9 @@
#include "rust_sched_launcher.h"
rust_scheduler::rust_scheduler(rust_kernel *kernel,
rust_srv *srv,
size_t num_threads,
rust_sched_id id) :
kernel(kernel),
srv(srv),
env(srv->env),
live_threads(num_threads),
live_tasks(0),
num_threads(num_threads),
@ -24,10 +21,9 @@ rust_scheduler::~rust_scheduler() {
rust_sched_launcher *
rust_scheduler::create_task_thread(int id) {
rust_srv *srv = this->srv->clone();
rust_sched_launcher *thread =
new (kernel, "rust_thread_sched_launcher")
rust_thread_sched_launcher(this, srv, id);
rust_thread_sched_launcher(this, id);
KLOG(kernel, kern, "created task thread: " PTR ", id: %d",
thread, id);
return thread;
@ -36,9 +32,7 @@ rust_scheduler::create_task_thread(int id) {
void
rust_scheduler::destroy_task_thread(rust_sched_launcher *thread) {
KLOG(kernel, kern, "deleting task thread: " PTR, thread);
rust_srv *srv = thread->get_loop()->srv;
delete thread;
delete srv;
}
void

View File

@ -9,8 +9,6 @@ class rust_scheduler : public kernel_owned<rust_scheduler> {
// FIXME: Make these private
public:
rust_kernel *kernel;
rust_srv *srv;
rust_env *env;
private:
// Protects live_threads and cur_thread increments
lock_and_signal lock;
@ -34,7 +32,7 @@ private:
void exit();
public:
rust_scheduler(rust_kernel *kernel, rust_srv *srv, size_t num_threads,
rust_scheduler(rust_kernel *kernel, size_t num_threads,
rust_sched_id id);
~rust_scheduler();

View File

@ -1,86 +0,0 @@
#include "rust_internal.h"
#include "rust_srv.h"
rust_srv::rust_srv(rust_env *env) :
env(env),
local_region(this, false) {
}
void
rust_srv::free(void *p) {
::free(p);
}
void *
rust_srv::malloc(size_t bytes) {
return ::malloc(bytes);
}
void *
rust_srv::realloc(void *p, size_t bytes) {
return ::realloc(p, bytes);
}
void
rust_srv::log(char const *msg) {
fprintf(stderr, "rust: %s\n", msg);
// FIXME: flushing each time is expensive, but at the moment
// necessary to get output through before a rust_task::fail
// call. This should be changed.
fflush(stderr);
}
void
rust_srv::fatal(const char *expression,
const char *file,
size_t line,
const char *format,
...) {
char buf[BUF_BYTES];
va_list args;
va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
char msg[BUF_BYTES];
snprintf(msg, sizeof(msg),
"fatal, '%s' failed, %s:%d %s",
expression, file, (int)line, buf);
log(msg);
abort();
}
void
rust_srv::warning(char const *expression,
char const *file,
size_t line,
const char *format,
...) {
char buf[BUF_BYTES];
va_list args;
va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
char msg[BUF_BYTES];
snprintf(msg, sizeof(msg),
"warning: '%s', at: %s:%d %s",
expression, file, (int)line, buf);
log(msg);
}
rust_srv *
rust_srv::clone() {
return new rust_srv(env);
}
//
// Local Variables:
// mode: C++
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//

View File

@ -1,29 +0,0 @@
// -*- c++ -*-
#ifndef RUST_SRV_H
#define RUST_SRV_H
#include "rust_internal.h"
class rust_srv {
public:
rust_env *env;
memory_region local_region;
void log(char const *msg);
void fatal(char const *expression,
char const *file,
size_t line,
char const *format,
...);
void warning(char const *expression,
char const *file,
size_t line,
char const *format,
...);
void free(void *);
void *malloc(size_t);
void *realloc(void *, size_t);
rust_srv(rust_env *);
rust_srv *clone();
};
#endif /* RUST_SRV_H */

View File

@ -27,7 +27,7 @@ rust_task::rust_task(rust_sched_loop *sched_loop, rust_task_state state,
name(name),
list_index(-1),
rendezvous_ptr(0),
local_region(&sched_loop->srv->local_region),
local_region(&sched_loop->local_region),
boxed(&local_region),
unwinding(false),
propagate_failure(true),