mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-19 10:24:16 +00:00
Refactor includes structure, getting rid of rust_internal.h
Many changes to code structure are included: - removed TIME_SLICE_IN_MS - removed sychronized_indexed_list - removed region_owned - kernel_owned move to kernel.h, task_owned moved to task.h - global configs moved to rust_globals.h - changed #pragma once to standard guard in rust_upcall.h - got rid of memory.h
This commit is contained in:
parent
704ca046a1
commit
632a4c9326
@ -1,10 +1,6 @@
|
||||
|
||||
#include "context.h"
|
||||
|
||||
#include "../../rust.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "../../rust_globals.h"
|
||||
|
||||
extern "C" uint32_t CDECL swap_registers(registers_t *oregs,
|
||||
registers_t *regs)
|
||||
|
@ -1,10 +1,6 @@
|
||||
|
||||
#include "context.h"
|
||||
|
||||
#include "../../rust.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "../../rust_globals.h"
|
||||
|
||||
extern "C" void CDECL swap_registers(registers_t *oregs,
|
||||
registers_t *regs)
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#include "boxed_region.h"
|
||||
#include "rust_internal.h"
|
||||
#include "rust_globals.h"
|
||||
#include "rust_task.h"
|
||||
|
||||
// #define DUMP_BOXED_REGION
|
||||
|
||||
|
@ -2,7 +2,9 @@
|
||||
* A simple resizable circular buffer.
|
||||
*/
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include "circular_buffer.h"
|
||||
#include "rust_globals.h"
|
||||
#include "rust_kernel.h"
|
||||
|
||||
circular_buffer::circular_buffer(rust_kernel *kernel, size_t unit_sz) :
|
||||
kernel(kernel),
|
||||
|
@ -5,6 +5,9 @@
|
||||
#ifndef CIRCULAR_BUFFER_H
|
||||
#define CIRCULAR_BUFFER_H
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "rust_kernel.h"
|
||||
|
||||
class
|
||||
circular_buffer : public kernel_owned<circular_buffer> {
|
||||
static const size_t INITIAL_CIRCULAR_BUFFER_SIZE_IN_UNITS = 8;
|
||||
|
@ -2,40 +2,8 @@
|
||||
#ifndef MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
// FIXME: It would be really nice to be able to get rid of this.
|
||||
inline void *operator new[](size_t size, rust_task *task, const char *tag) {
|
||||
return task->malloc(size, tag);
|
||||
}
|
||||
#include "rust_task.h"
|
||||
|
||||
template <typename T>
|
||||
inline void *task_owned<T>::operator new(size_t size, rust_task *task,
|
||||
const char *tag) {
|
||||
return task->malloc(size, tag);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void *task_owned<T>::operator new[](size_t size, rust_task *task,
|
||||
const char *tag) {
|
||||
return task->malloc(size, tag);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void *task_owned<T>::operator new(size_t size, rust_task &task,
|
||||
const char *tag) {
|
||||
return task.malloc(size, tag);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void *task_owned<T>::operator new[](size_t size, rust_task &task,
|
||||
const char *tag) {
|
||||
return task.malloc(size, tag);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void *kernel_owned<T>::operator new(size_t size, rust_kernel *kernel,
|
||||
const char *tag) {
|
||||
return kernel->malloc(size, tag);
|
||||
}
|
||||
|
||||
|
||||
#endif /* MEMORY_H */
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "sync/sync.h"
|
||||
#include "memory_region.h"
|
||||
#include "rust_env.h"
|
||||
|
||||
#if RUSTRT_TRACK_ALLOCATIONS >= 3
|
||||
#include <execinfo.h>
|
||||
|
@ -9,7 +9,9 @@
|
||||
#ifndef MEMORY_REGION_H
|
||||
#define MEMORY_REGION_H
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "sync/lock_and_signal.h"
|
||||
#include "util/array_list.h"
|
||||
|
||||
// There are three levels of debugging:
|
||||
//
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "rust_kernel.h"
|
||||
#include "rust_util.h"
|
||||
#include "rust_scheduler.h"
|
||||
#include <cstdio>
|
||||
|
||||
struct
|
||||
command_line_args : public kernel_owned<command_line_args>
|
||||
|
@ -1,41 +0,0 @@
|
||||
#ifndef RUST_H
|
||||
#define RUST_H
|
||||
|
||||
/*
|
||||
* Include this file after you've defined the ISO C9x stdint
|
||||
* types (size_t, uint8_t, uintptr_t, etc.)
|
||||
*/
|
||||
|
||||
#ifdef __i386__
|
||||
// 'cdecl' ABI only means anything on i386
|
||||
#ifdef __WIN32__
|
||||
#ifndef CDECL
|
||||
#define CDECL __cdecl
|
||||
#endif
|
||||
#ifndef FASTCALL
|
||||
#define FASTCALL __fastcall
|
||||
#endif
|
||||
#else
|
||||
#define CDECL __attribute__((cdecl))
|
||||
#define FASTCALL __attribute__((fastcall))
|
||||
#endif
|
||||
#else
|
||||
#define CDECL
|
||||
#define FASTCALL
|
||||
#endif
|
||||
|
||||
/* Controls whether claims are turned into checks */
|
||||
/* Variable name must be kept consistent with trans.rs */
|
||||
extern "C" int check_claims;
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* 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:
|
||||
*/
|
||||
|
||||
#endif /* RUST_H */
|
@ -1,4 +1,6 @@
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "rust_task.h"
|
||||
#include "rust_shape.h"
|
||||
|
||||
class annihilator : public shape::data<annihilator,shape::ptr> {
|
||||
|
@ -1,12 +1,12 @@
|
||||
/* Native builtins. */
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include "rust_sched_loop.h"
|
||||
#include "rust_task.h"
|
||||
#include "rust_util.h"
|
||||
#include "rust_scheduler.h"
|
||||
#include "sync/timer.h"
|
||||
#include "rust_abi.h"
|
||||
#include "rust_port.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <crt_externs.h>
|
||||
|
@ -1,19 +1,17 @@
|
||||
// Rust cycle collector. Temporary, but will probably stick around for some
|
||||
// time until LLVM's GC infrastructure is more mature.
|
||||
|
||||
#include "rust_debug.h"
|
||||
#include "rust_internal.h"
|
||||
#include "rust_shape.h"
|
||||
#include "rust_task.h"
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <ios>
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "rust_cc.h"
|
||||
#include "rust_debug.h"
|
||||
#include "rust_shape.h"
|
||||
#include "rust_task.h"
|
||||
|
||||
// The number of allocations Rust code performs before performing cycle
|
||||
// collection.
|
||||
#define RUST_CC_FREQUENCY 5000
|
||||
|
@ -1,13 +1,13 @@
|
||||
// Routines useful when debugging the Rust runtime.
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "rust_abi.h"
|
||||
#include "rust_debug.h"
|
||||
#include "rust_internal.h"
|
||||
#include "rust_task.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
// that might come from the environment is loaded here, once, during
|
||||
// init.
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include "rust_env.h"
|
||||
|
||||
// The environment variables that the runtime knows about
|
||||
#define RUST_THREADS "RUST_THREADS"
|
||||
|
@ -1,3 +1,9 @@
|
||||
|
||||
#ifndef RUST_ENV_H
|
||||
#define RUST_ENV_H
|
||||
|
||||
#include "rust_globals.h"
|
||||
|
||||
struct rust_env {
|
||||
size_t num_sched_threads;
|
||||
size_t min_stack_size;
|
||||
@ -11,3 +17,5 @@ struct rust_env {
|
||||
|
||||
rust_env* load_env();
|
||||
void free_env(rust_env *rust_env);
|
||||
|
||||
#endif
|
||||
|
@ -25,11 +25,10 @@
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "rust.h"
|
||||
#include "rand.h"
|
||||
#include "uthash.h"
|
||||
#include "rust_env.h"
|
||||
|
||||
#if defined(__WIN32__)
|
||||
extern "C" {
|
||||
@ -52,6 +51,28 @@ extern "C" {
|
||||
#error "Platform not supported."
|
||||
#endif
|
||||
|
||||
#ifdef __i386__
|
||||
// 'cdecl' ABI only means anything on i386
|
||||
#ifdef __WIN32__
|
||||
#ifndef CDECL
|
||||
#define CDECL __cdecl
|
||||
#endif
|
||||
#ifndef FASTCALL
|
||||
#define FASTCALL __fastcall
|
||||
#endif
|
||||
#else
|
||||
#define CDECL __attribute__((cdecl))
|
||||
#define FASTCALL __attribute__((fastcall))
|
||||
#endif
|
||||
#else
|
||||
#define CDECL
|
||||
#define FASTCALL
|
||||
#endif
|
||||
|
||||
/* Controls whether claims are turned into checks */
|
||||
/* Variable name must be kept consistent with trans.rs */
|
||||
extern "C" int check_claims;
|
||||
|
||||
#define CHECKED(call) \
|
||||
{ \
|
||||
int res = (call); \
|
||||
@ -64,4 +85,16 @@ extern "C" {
|
||||
} \
|
||||
}
|
||||
|
||||
#define PTR "0x%" PRIxPTR
|
||||
|
||||
// This accounts for logging buffers.
|
||||
static size_t const BUF_BYTES = 2048;
|
||||
|
||||
// The error status to use when the process fails
|
||||
#define PROC_FAIL_CODE 101
|
||||
|
||||
// A cond(ition) is something we can block on. This can be a channel
|
||||
// (writing), a port (reading) or a task (waiting).
|
||||
struct rust_cond { };
|
||||
|
||||
#endif /* RUST_GLOBALS_H */
|
||||
|
@ -1,183 +0,0 @@
|
||||
#ifndef RUST_INTERNAL_H
|
||||
#define RUST_INTERNAL_H
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "util/array_list.h"
|
||||
#include "util/indexed_list.h"
|
||||
#include "util/synchronized_indexed_list.h"
|
||||
#include "util/hash_map.h"
|
||||
#include "sync/sync.h"
|
||||
#include "sync/lock_and_signal.h"
|
||||
#include "sync/lock_free_queue.h"
|
||||
|
||||
struct rust_sched_loop;
|
||||
struct rust_task;
|
||||
class rust_log;
|
||||
class rust_port;
|
||||
class rust_kernel;
|
||||
|
||||
struct stk_seg;
|
||||
struct type_desc;
|
||||
struct frame_glue_fns;
|
||||
|
||||
typedef intptr_t rust_sched_id;
|
||||
typedef intptr_t rust_task_id;
|
||||
typedef intptr_t rust_port_id;
|
||||
|
||||
#define PTR "0x%" PRIxPTR
|
||||
|
||||
// This drives our preemption scheme.
|
||||
|
||||
static size_t const TIME_SLICE_IN_MS = 10;
|
||||
|
||||
// This accounts for logging buffers.
|
||||
|
||||
static size_t const BUF_BYTES = 2048;
|
||||
|
||||
// The error status to use when the process fails
|
||||
#define PROC_FAIL_CODE 101
|
||||
|
||||
// Every reference counted object should use this macro and initialize
|
||||
// ref_count.
|
||||
|
||||
#define RUST_REFCOUNTED(T) \
|
||||
RUST_REFCOUNTED_WITH_DTOR(T, delete (T*)this)
|
||||
#define RUST_REFCOUNTED_WITH_DTOR(T, dtor) \
|
||||
intptr_t ref_count; \
|
||||
void ref() { ++ref_count; } \
|
||||
void deref() { if (--ref_count == 0) { dtor; } }
|
||||
|
||||
#define RUST_ATOMIC_REFCOUNT() \
|
||||
private: \
|
||||
intptr_t ref_count; \
|
||||
public: \
|
||||
void ref() { \
|
||||
intptr_t old = sync::increment(ref_count); \
|
||||
assert(old > 0); \
|
||||
} \
|
||||
void deref() { if(0 == sync::decrement(ref_count)) { delete_this(); } } \
|
||||
intptr_t get_ref_count() { return sync::read(ref_count); }
|
||||
|
||||
template <typename T> struct task_owned {
|
||||
inline void *operator new(size_t size, rust_task *task, const char *tag);
|
||||
|
||||
inline void *operator new[](size_t size, rust_task *task,
|
||||
const char *tag);
|
||||
|
||||
inline void *operator new(size_t size, rust_task &task, const char *tag);
|
||||
|
||||
inline void *operator new[](size_t size, rust_task &task,
|
||||
const char *tag);
|
||||
|
||||
void operator delete(void *ptr) {
|
||||
((T *)ptr)->task->free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct kernel_owned {
|
||||
inline void *operator new(size_t size, rust_kernel *kernel,
|
||||
const char *tag);
|
||||
|
||||
void operator delete(void *ptr) {
|
||||
((T *)ptr)->kernel->free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct region_owned {
|
||||
void operator delete(void *ptr) {
|
||||
((T *)ptr)->region->free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
// A cond(ition) is something we can block on. This can be a channel
|
||||
// (writing), a port (reading) or a task (waiting).
|
||||
|
||||
struct rust_cond { };
|
||||
|
||||
#include "memory_region.h"
|
||||
#include "rust_log.h"
|
||||
#include "rust_kernel.h"
|
||||
#include "rust_sched_loop.h"
|
||||
|
||||
typedef void CDECL (glue_fn)(void *, void *,
|
||||
const type_desc **, void *);
|
||||
|
||||
struct rust_shape_tables {
|
||||
uint8_t *tags;
|
||||
uint8_t *resources;
|
||||
};
|
||||
|
||||
typedef unsigned long ref_cnt_t;
|
||||
|
||||
// Corresponds to the boxed data in the @ region. The body follows the
|
||||
// header; you can obtain a ptr via box_body() below.
|
||||
struct rust_opaque_box {
|
||||
ref_cnt_t ref_count;
|
||||
type_desc *td;
|
||||
rust_opaque_box *prev;
|
||||
rust_opaque_box *next;
|
||||
};
|
||||
|
||||
// The type of functions that we spawn, which fall into two categories:
|
||||
// - the main function: has a NULL environment, but uses the void* arg
|
||||
// - unique closures of type fn~(): have a non-NULL environment, but
|
||||
// no arguments (and hence the final void*) is harmless
|
||||
typedef void (*CDECL spawn_fn)(void*, rust_opaque_box*, void *);
|
||||
|
||||
// corresponds to the layout of a fn(), fn@(), fn~() etc
|
||||
struct fn_env_pair {
|
||||
spawn_fn f;
|
||||
rust_opaque_box *env;
|
||||
};
|
||||
|
||||
static inline void *box_body(rust_opaque_box *box) {
|
||||
// Here we take advantage of the fact that the size of a box in 32
|
||||
// (resp. 64) bit is 16 (resp. 32) bytes, and thus always 16-byte aligned.
|
||||
// If this were to change, we would have to update the method
|
||||
// rustc::middle::trans::base::opaque_box_body() as well.
|
||||
return (void*)(box + 1);
|
||||
}
|
||||
|
||||
struct type_desc {
|
||||
// First part of type_desc is known to compiler.
|
||||
// first_param = &descs[1] if dynamic, null if static.
|
||||
const type_desc **first_param;
|
||||
size_t size;
|
||||
size_t align;
|
||||
glue_fn *take_glue;
|
||||
glue_fn *drop_glue;
|
||||
glue_fn *free_glue;
|
||||
void *UNUSED;
|
||||
glue_fn *sever_glue; // For GC.
|
||||
glue_fn *mark_glue; // For GC.
|
||||
uintptr_t unused2;
|
||||
void *UNUSED_2;
|
||||
const uint8_t *shape;
|
||||
const rust_shape_tables *shape_tables;
|
||||
uintptr_t n_params;
|
||||
uintptr_t n_obj_params;
|
||||
|
||||
// Residual fields past here are known only to runtime.
|
||||
UT_hash_handle hh;
|
||||
size_t n_descs;
|
||||
const type_desc *descs[];
|
||||
};
|
||||
|
||||
extern "C" type_desc *rust_clone_type_desc(type_desc*);
|
||||
|
||||
#include "circular_buffer.h"
|
||||
#include "rust_task.h"
|
||||
#include "rust_port.h"
|
||||
#include "memory.h"
|
||||
|
||||
//
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
// fill-column: 78;
|
||||
// indent-tabs-mode: nil
|
||||
// c-basic-offset: 4
|
||||
// buffer-file-coding-system: utf-8-unix
|
||||
// End:
|
||||
//
|
||||
|
||||
#endif
|
@ -1,4 +1,7 @@
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_kernel.h"
|
||||
#include "rust_globals.h"
|
||||
#include "rust_port.h"
|
||||
#include "rust_util.h"
|
||||
#include "rust_scheduler.h"
|
||||
|
||||
|
@ -7,9 +7,15 @@
|
||||
#include "memory_region.h"
|
||||
#include "rust_log.h"
|
||||
#include "rust_sched_reaper.h"
|
||||
#include "util/hash_map.h"
|
||||
|
||||
struct rust_task_thread;
|
||||
class rust_scheduler;
|
||||
class rust_port;
|
||||
|
||||
typedef intptr_t rust_sched_id;
|
||||
typedef intptr_t rust_task_id;
|
||||
typedef intptr_t rust_port_id;
|
||||
|
||||
typedef std::map<rust_sched_id, rust_scheduler*> sched_map;
|
||||
|
||||
@ -81,4 +87,19 @@ public:
|
||||
void set_exit_status(int code);
|
||||
};
|
||||
|
||||
template <typename T> struct kernel_owned {
|
||||
inline void *operator new(size_t size, rust_kernel *kernel,
|
||||
const char *tag);
|
||||
|
||||
void operator delete(void *ptr) {
|
||||
((T *)ptr)->kernel->free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void *kernel_owned<T>::operator new(size_t size, rust_kernel *kernel,
|
||||
const char *tag) {
|
||||
return kernel->malloc(size, tag);
|
||||
}
|
||||
|
||||
#endif /* RUST_KERNEL_H */
|
||||
|
@ -2,12 +2,11 @@
|
||||
* Logging infrastructure that aims to support multi-threading
|
||||
*/
|
||||
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_log.h"
|
||||
#include "util/array_list.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "rust_util.h"
|
||||
#include "rust_task.h"
|
||||
|
||||
/**
|
||||
* Synchronizes access to the underlying logging mechanism.
|
||||
|
@ -2,6 +2,8 @@
|
||||
#ifndef RUST_LOG_H
|
||||
#define RUST_LOG_H
|
||||
|
||||
#include "rust_globals.h"
|
||||
|
||||
const uint32_t log_err = 0;
|
||||
const uint32_t log_warn = 1;
|
||||
const uint32_t log_info = 2;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "rust_internal.h"
|
||||
#include "rust_port.h"
|
||||
|
||||
#include "rust_port.h"
|
||||
#include "rust_task.h"
|
||||
|
||||
rust_port::rust_port(rust_task *task, size_t unit_sz)
|
||||
: ref_count(1), kernel(task->kernel), task(task),
|
||||
|
@ -1,7 +1,8 @@
|
||||
#ifndef RUST_PORT_H
|
||||
#define RUST_PORT_H
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include "rust_globals.h"
|
||||
#include "circular_buffer.h"
|
||||
|
||||
class port_detach_cond : public rust_cond { };
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
|
||||
#include "rust_port.h"
|
||||
#include "rust_port_selector.h"
|
||||
#include "rust_task.h"
|
||||
|
||||
rust_port_selector::rust_port_selector()
|
||||
: ports(NULL), n_ports(0) {
|
||||
|
@ -1,9 +1,8 @@
|
||||
#ifndef RUST_PORT_SELECTOR_H
|
||||
#define RUST_PORT_SELECTOR_H
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include "rust_globals.h"
|
||||
|
||||
struct rust_task;
|
||||
class rust_port;
|
||||
|
||||
class rust_port_selector : public rust_cond {
|
||||
|
31
src/rt/rust_refcount.h
Normal file
31
src/rt/rust_refcount.h
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
#ifndef RUST_REFCOUNT_H
|
||||
#define RUST_REFCOUNT_H
|
||||
|
||||
#include "sync/sync.h"
|
||||
|
||||
// Refcounting defines
|
||||
typedef unsigned long ref_cnt_t;
|
||||
|
||||
#define RUST_REFCOUNTED(T) \
|
||||
RUST_REFCOUNTED_WITH_DTOR(T, delete (T*)this)
|
||||
|
||||
#define RUST_REFCOUNTED_WITH_DTOR(T, dtor) \
|
||||
intptr_t ref_count; \
|
||||
void ref() { ++ref_count; } \
|
||||
void deref() { if (--ref_count == 0) { dtor; } }
|
||||
|
||||
#define RUST_ATOMIC_REFCOUNT() \
|
||||
private: \
|
||||
intptr_t ref_count; \
|
||||
public: \
|
||||
void ref() { \
|
||||
intptr_t old = sync::increment(ref_count); \
|
||||
assert(old > 0); \
|
||||
} \
|
||||
void deref() { if(0 == sync::decrement(ref_count)) { delete_this(); } } \
|
||||
intptr_t get_ref_count() { return sync::read(ref_count); }
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_kernel.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <crt_externs.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <assert.h>
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "rust_sched_driver.h"
|
||||
#include "rust_sched_loop.h"
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
#include "rust_sched_launcher.h"
|
||||
#include "rust_scheduler.h"
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
#ifndef RUST_SCHED_LAUNCHER_H
|
||||
#define RUST_SCHED_LAUNCHER_H
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include "sync/rust_thread.h"
|
||||
#include "rust_sched_driver.h"
|
||||
#include "rust_kernel.h"
|
||||
#include "rust_sched_loop.h"
|
||||
|
||||
class rust_sched_launcher : public kernel_owned<rust_sched_launcher> {
|
||||
public:
|
||||
|
@ -1,9 +1,5 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <cassert>
|
||||
#include <pthread.h>
|
||||
#include <vector>
|
||||
#include "rust_internal.h"
|
||||
#include "rust_sched_loop.h"
|
||||
#include "rust_util.h"
|
||||
#include "rust_scheduler.h"
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
#ifndef RUST_SCHED_LOOP_H
|
||||
#define RUST_SCHED_LOOP_H
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include "rust_globals.h"
|
||||
#include "rust_log.h"
|
||||
#include "rust_stack.h"
|
||||
#include "rust_signal.h"
|
||||
#include "context.h"
|
||||
#include "util/indexed_list.h"
|
||||
|
||||
enum rust_task_state {
|
||||
task_state_newborn,
|
||||
@ -23,6 +25,8 @@ enum rust_sched_loop_state {
|
||||
sched_loop_state_exit
|
||||
};
|
||||
|
||||
class rust_kernel;
|
||||
class rust_scheduler;
|
||||
struct rust_task;
|
||||
|
||||
typedef indexed_list<rust_task> rust_task_list;
|
||||
@ -176,6 +180,8 @@ rust_sched_loop::return_c_stack(stk_seg *stack) {
|
||||
}
|
||||
}
|
||||
|
||||
// this is needed to appease the circular dependency gods
|
||||
#include "rust_task.h"
|
||||
|
||||
//
|
||||
// Local Variables:
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_kernel.h"
|
||||
#include "rust_sched_reaper.h"
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
|
||||
#include "rust_scheduler.h"
|
||||
#include "rust_task.h"
|
||||
#include "rust_globals.h"
|
||||
#include "rust_util.h"
|
||||
#include "rust_sched_launcher.h"
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
#ifndef RUST_SCHEDULER_H
|
||||
#define RUST_SCHEDULER_H
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include "rust_globals.h"
|
||||
#include "util/array_list.h"
|
||||
#include "rust_kernel.h"
|
||||
|
||||
class rust_sched_launcher;
|
||||
|
||||
|
@ -1,16 +1,14 @@
|
||||
// Functions that interpret the shape of a type to perform various low-level
|
||||
// actions, such as copying, freeing, comparing, and so on.
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_task.h"
|
||||
#include "rust_shape.h"
|
||||
|
||||
namespace shape {
|
||||
|
@ -9,7 +9,8 @@
|
||||
#undef min
|
||||
|
||||
#include <iostream>
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "rust_util.h"
|
||||
|
||||
// ISAAC pollutes our namespace.
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_stack.h"
|
||||
#include "vg/valgrind.h"
|
||||
#include "vg/memcheck.h"
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
#ifndef RUST_STACK_H
|
||||
#define RUST_STACK_H
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "memory_region.h"
|
||||
|
||||
struct rust_task;
|
||||
|
||||
struct stk_seg {
|
||||
stk_seg *prev;
|
||||
stk_seg *next;
|
||||
|
@ -1,16 +1,15 @@
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include "rust_cc.h"
|
||||
|
||||
#ifndef __WIN32__
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
#include "rust_task.h"
|
||||
#include "rust_cc.h"
|
||||
#include "rust_upcall.h"
|
||||
#include "rust_env.h"
|
||||
#include "rust_port.h"
|
||||
|
||||
// Tasks
|
||||
rust_task::rust_task(rust_sched_loop *sched_loop, rust_task_state state,
|
||||
|
@ -1,6 +1,3 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RUST_TASK_H
|
||||
#define RUST_TASK_H
|
||||
@ -8,14 +5,15 @@
|
||||
#include <map>
|
||||
|
||||
#include "util/array_list.h"
|
||||
|
||||
#include "context.h"
|
||||
#include "rust_debug.h"
|
||||
#include "rust_internal.h"
|
||||
#include "rust_kernel.h"
|
||||
#include "boxed_region.h"
|
||||
#include "rust_stack.h"
|
||||
#include "rust_port_selector.h"
|
||||
#include "rust_type.h"
|
||||
#include "rust_sched_loop.h"
|
||||
#include "memory.h"
|
||||
|
||||
// The amount of extra space at the end of each stack segment, available
|
||||
// to the rt, compiler and dynamic linker for running small functions
|
||||
@ -272,6 +270,38 @@ public:
|
||||
void cleanup_after_turn();
|
||||
};
|
||||
|
||||
// FIXME: It would be really nice to be able to get rid of this.
|
||||
inline void *operator new[](size_t size, rust_task *task, const char *tag) {
|
||||
return task->malloc(size, tag);
|
||||
}
|
||||
|
||||
|
||||
template <typename T> struct task_owned {
|
||||
inline void *operator new(size_t size, rust_task *task,
|
||||
const char *tag) {
|
||||
return task->malloc(size, tag);
|
||||
}
|
||||
|
||||
inline void *operator new[](size_t size, rust_task *task,
|
||||
const char *tag) {
|
||||
return task->malloc(size, tag);
|
||||
}
|
||||
|
||||
inline void *operator new(size_t size, rust_task &task,
|
||||
const char *tag) {
|
||||
return task.malloc(size, tag);
|
||||
}
|
||||
|
||||
inline void *operator new[](size_t size, rust_task &task,
|
||||
const char *tag) {
|
||||
return task.malloc(size, tag);
|
||||
}
|
||||
|
||||
void operator delete(void *ptr) {
|
||||
((T *)ptr)->task->free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
// This stuff is on the stack-switching fast path
|
||||
|
||||
// Get a rough approximation of the current stack pointer
|
||||
|
72
src/rt/rust_type.h
Normal file
72
src/rt/rust_type.h
Normal file
@ -0,0 +1,72 @@
|
||||
|
||||
#ifndef RUST_TYPE_H
|
||||
#define RUST_TYPE_H
|
||||
|
||||
#include "rust_refcount.h"
|
||||
|
||||
// The type of functions that we spawn, which fall into two categories:
|
||||
// - the main function: has a NULL environment, but uses the void* arg
|
||||
// - unique closures of type fn~(): have a non-NULL environment, but
|
||||
// no arguments (and hence the final void*) is harmless
|
||||
typedef void (*CDECL spawn_fn)(void*, rust_opaque_box*, void *);
|
||||
|
||||
struct type_desc;
|
||||
|
||||
typedef void CDECL (glue_fn)(void *, void *, const type_desc **, void *);
|
||||
|
||||
struct rust_shape_tables {
|
||||
uint8_t *tags;
|
||||
uint8_t *resources;
|
||||
};
|
||||
|
||||
// Corresponds to the boxed data in the @ region. The body follows the
|
||||
// header; you can obtain a ptr via box_body() below.
|
||||
struct rust_opaque_box {
|
||||
ref_cnt_t ref_count;
|
||||
type_desc *td;
|
||||
rust_opaque_box *prev;
|
||||
rust_opaque_box *next;
|
||||
};
|
||||
|
||||
// corresponds to the layout of a fn(), fn@(), fn~() etc
|
||||
struct fn_env_pair {
|
||||
spawn_fn f;
|
||||
rust_opaque_box *env;
|
||||
};
|
||||
|
||||
static inline void *box_body(rust_opaque_box *box) {
|
||||
// Here we take advantage of the fact that the size of a box in 32
|
||||
// (resp. 64) bit is 16 (resp. 32) bytes, and thus always 16-byte aligned.
|
||||
// If this were to change, we would have to update the method
|
||||
// rustc::middle::trans::base::opaque_box_body() as well.
|
||||
return (void*)(box + 1);
|
||||
}
|
||||
|
||||
struct type_desc {
|
||||
// First part of type_desc is known to compiler.
|
||||
// first_param = &descs[1] if dynamic, null if static.
|
||||
const type_desc **first_param;
|
||||
size_t size;
|
||||
size_t align;
|
||||
glue_fn *take_glue;
|
||||
glue_fn *drop_glue;
|
||||
glue_fn *free_glue;
|
||||
void *UNUSED;
|
||||
glue_fn *sever_glue; // For GC.
|
||||
glue_fn *mark_glue; // For GC.
|
||||
uintptr_t unused2;
|
||||
void *UNUSED_2;
|
||||
const uint8_t *shape;
|
||||
const rust_shape_tables *shape_tables;
|
||||
uintptr_t n_params;
|
||||
uintptr_t n_obj_params;
|
||||
|
||||
// Residual fields past here are known only to runtime.
|
||||
UT_hash_handle hh;
|
||||
size_t n_descs;
|
||||
const type_desc *descs[];
|
||||
};
|
||||
|
||||
extern "C" type_desc *rust_clone_type_desc(type_desc*);
|
||||
|
||||
#endif
|
@ -6,15 +6,15 @@
|
||||
switch to the C stack.
|
||||
*/
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "rust_task.h"
|
||||
#include "rust_cc.h"
|
||||
#include "rust_internal.h"
|
||||
#include "rust_sched_loop.h"
|
||||
#include "rust_unwind.h"
|
||||
#include "rust_upcall.h"
|
||||
#include "rust_util.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define LOG_UPCALL_ENTRY(task) \
|
||||
LOG(task, upcall, \
|
||||
|
@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef RUST_UPCALL_H
|
||||
#define RUST_UPCALL_H
|
||||
|
||||
// Upcalls used from C code on occasion:
|
||||
|
||||
extern "C" CDECL void upcall_shared_free(void* ptr);
|
||||
|
||||
#endif
|
||||
|
@ -1,8 +1,9 @@
|
||||
#ifndef RUST_UTIL_H
|
||||
#define RUST_UTIL_H
|
||||
|
||||
#include "rust_task.h"
|
||||
#include <limits.h>
|
||||
#include "rust_task.h"
|
||||
#include "rust_env.h"
|
||||
|
||||
// Inline fn used regularly elsewhere.
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "rust_internal.h"
|
||||
|
||||
#include "rust_globals.h"
|
||||
#include "rust_task.h"
|
||||
#include "uv.h"
|
||||
|
||||
// crust fn pointers
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "../rust_globals.h"
|
||||
#include "lock_and_signal.h"
|
||||
|
||||
/*
|
||||
* A "lock-and-signal" pair. These are necessarily coupled on pthreads
|
||||
@ -8,8 +9,6 @@
|
||||
* if you're using a pthreads cvar+mutex pair.
|
||||
*/
|
||||
|
||||
#include "lock_and_signal.h"
|
||||
|
||||
// FIXME: This is not a portable way of specifying an invalid pthread_t
|
||||
#define INVALID_THREAD 0
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
#ifndef LOCK_AND_SIGNAL_H
|
||||
#define LOCK_AND_SIGNAL_H
|
||||
|
||||
#include "rust_globals.h"
|
||||
|
||||
#ifndef RUST_NDEBUG
|
||||
#define DEBUG_LOCKS
|
||||
#endif
|
||||
|
@ -42,6 +42,7 @@
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
template <class T>
|
||||
class lock_free_queue {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "rust_globals.h"
|
||||
|
||||
#include "rust_thread.h"
|
||||
|
||||
const size_t default_stack_sz = 1024*1024;
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef RUST_THREAD_H
|
||||
#define RUST_THREAD_H
|
||||
|
||||
#include "rust_globals.h"
|
||||
|
||||
/**
|
||||
* Thread utility class. Derive and implement your own run() method.
|
||||
*/
|
||||
|
@ -2,6 +2,9 @@
|
||||
#ifndef ARRAY_LIST_H
|
||||
#define ARRAY_LIST_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* A simple, resizable array list.
|
||||
*/
|
||||
|
@ -1,74 +0,0 @@
|
||||
#ifndef SYNCHRONIZED_INDEXED_LIST_H
|
||||
#define SYNCHRONIZED_INDEXED_LIST_H
|
||||
|
||||
#include "indexed_list.h"
|
||||
#include "../sync/lock_and_signal.h"
|
||||
|
||||
template<typename T> class synchronized_indexed_list :
|
||||
public indexed_list<T> {
|
||||
lock_and_signal _lock;
|
||||
|
||||
public:
|
||||
synchronized_indexed_list() {
|
||||
}
|
||||
|
||||
int32_t append(T *value) {
|
||||
int32_t index = 0;
|
||||
_lock.lock();
|
||||
index = indexed_list<T>::append(value);
|
||||
_lock.unlock();
|
||||
return index;
|
||||
}
|
||||
|
||||
bool pop(T **value) {
|
||||
_lock.lock();
|
||||
bool result = indexed_list<T>::pop(value);
|
||||
_lock.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t length() {
|
||||
size_t length = 0;
|
||||
_lock.lock();
|
||||
length = indexed_list<T>::length();
|
||||
_lock.unlock();
|
||||
return length;
|
||||
}
|
||||
|
||||
bool is_empty() {
|
||||
bool empty = false;
|
||||
_lock.lock();
|
||||
empty = indexed_list<T>::is_empty();
|
||||
_lock.unlock();
|
||||
return empty;
|
||||
}
|
||||
|
||||
int32_t remove(T* value) {
|
||||
size_t index = 0;
|
||||
_lock.lock();
|
||||
index = indexed_list<T>::remove(value);
|
||||
_lock.unlock();
|
||||
return index;
|
||||
}
|
||||
|
||||
T *operator[](size_t index) {
|
||||
T *value = NULL;
|
||||
_lock.lock();
|
||||
value = indexed_list<T>::operator[](index);
|
||||
_lock.unlock();
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
|
||||
#endif /* SYNCHRONIZED_INDEXED_LIST_H */
|
Loading…
Reference in New Issue
Block a user