1 #ifndef RUST_INTERNAL_H
2 #define RUST_INTERNAL_H
5 // these are defined in two files, and GCC complains.
6 #define __STDC_LIMIT_MACROS 1
7 #define __STDC_CONSTANT_MACROS 1
8 #define __STDC_FORMAT_MACROS 1
17 #include <sys/types.h>
29 #if defined(__WIN32__)
35 #elif defined(__GNUC__)
42 #error "Platform not supported."
45 #include "util/array_list.h"
46 #include "util/indexed_list.h"
47 #include "util/synchronized_indexed_list.h"
48 #include "util/hash_map.h"
49 #include "sync/sync.h"
50 #include "sync/timer.h"
51 #include "sync/lock_and_signal.h"
52 #include "sync/lock_free_queue.h"
54 struct rust_scheduler;
59 class rust_crate_cache;
63 struct frame_glue_fns;
65 typedef intptr_t rust_task_id;
66 typedef intptr_t rust_port_id;
68 //NDM #ifndef __i386__
69 //NDM #error "Target CPU not supported."
72 #define I(dom, e) ((e) ? (void)0 : \
73 (dom)->srv->fatal(#e, __FILE__, __LINE__, ""))
75 #define W(dom, e, s, ...) ((e) ? (void)0 : \
76 (dom)->srv->warning(#e, __FILE__, __LINE__, s, ## __VA_ARGS__))
78 #define A(dom, e, s, ...) ((e) ? (void)0 : \
79 (dom)->srv->fatal(#e, __FILE__, __LINE__, s, ## __VA_ARGS__))
81 #define K(srv, e, s, ...) ((e) ? (void)0 : \
82 srv->fatal(#e, __FILE__, __LINE__, s, ## __VA_ARGS__))
84 #define PTR "0x%" PRIxPTR
86 // This drives our preemption scheme.
88 static size_t const TIME_SLICE_IN_MS = 10;
90 // This accounts for logging buffers.
92 static size_t const BUF_BYTES = 2048;
94 // The error status to use when the process fails
95 #define PROC_FAIL_CODE 101;
97 // Every reference counted object should use this macro and initialize
100 #define RUST_REFCOUNTED(T) \
101 RUST_REFCOUNTED_WITH_DTOR(T, delete (T*)this)
102 #define RUST_REFCOUNTED_WITH_DTOR(T, dtor) \
103 intptr_t ref_count; \
104 void ref() { ++ref_count; } \
105 void deref() { if (--ref_count == 0) { dtor; } }
107 #define RUST_ATOMIC_REFCOUNT() \
109 intptr_t ref_count; \
112 intptr_t old = sync::increment(ref_count); \
115 void deref() { if(0 == sync::decrement(ref_count)) { delete this; } }
117 template <typename T> struct task_owned {
118 inline void *operator new(size_t size, rust_task *task, const char *tag);
120 inline void *operator new[](size_t size, rust_task *task,
123 inline void *operator new(size_t size, rust_task &task, const char *tag);
125 inline void *operator new[](size_t size, rust_task &task,
128 void operator delete(void *ptr) {
129 ((T *)ptr)->task->free(ptr);
138 smart_ptr() : p(NULL) {};
139 smart_ptr(T *p) : p(p) { if(p) { p->ref(); } }
140 smart_ptr(const smart_ptr &sp) : p(sp.p) {
162 T *operator->() const { return p; };
164 operator T*() const { return p; }
167 template <typename T> struct kernel_owned {
168 inline void *operator new(size_t size, rust_kernel *kernel,
171 void operator delete(void *ptr) {
172 ((T *)ptr)->kernel->free(ptr);
176 template <typename T> struct region_owned {
177 void operator delete(void *ptr) {
178 ((T *)ptr)->region->free(ptr);
182 #include "rust_task_list.h"
184 // A cond(ition) is something we can block on. This can be a channel
185 // (writing), a port (reading) or a task (waiting).
187 struct rust_cond { };
189 // Helper class used regularly elsewhere.
191 template <typename T> class ptr_vec : public task_owned<ptr_vec<T> > {
192 static const size_t INIT_SIZE = 8;
198 ptr_vec(rust_task *task);
209 T *& operator[](size_t offset);
213 void trim(size_t fill);
214 void swap_delete(T* p);
217 #include "memory_region.h"
218 #include "rust_srv.h"
219 #include "rust_log.h"
220 #include "rust_kernel.h"
221 #include "rust_scheduler.h"
224 // FIXME: This will probably eventually need replacement
225 // with something more sophisticated and integrated with
226 // an IO event-handling library, when we have such a thing.
227 // For now it's just the most basic "thread that can interrupt
228 // its associated domain-thread" device, so that we have
229 // *some* form of task-preemption.
230 rust_scheduler *sched;
233 #if defined(__WIN32__)
240 rust_timer(rust_scheduler *sched);
244 #include "rust_util.h"
246 typedef void CDECL (glue_fn)(void *, void *,
247 const type_desc **, void *);
248 typedef void CDECL (cmp_glue_fn)(void *, void *,
250 void *, void *, int8_t);
252 struct rust_shape_tables {
258 // First part of type_desc is known to compiler.
259 // first_param = &descs[1] if dynamic, null if static.
260 const type_desc **first_param;
267 glue_fn *sever_glue; // For GC.
268 glue_fn *mark_glue; // For GC.
270 cmp_glue_fn *cmp_glue;
271 const uint8_t *shape;
272 const rust_shape_tables *shape_tables;
274 uintptr_t n_obj_params;
276 // Residual fields past here are known only to runtime.
279 const type_desc *descs[];
282 extern "C" type_desc *rust_clone_type_desc(type_desc*);
284 #include "circular_buffer.h"
285 #include "rust_task.h"
286 #include "rust_port.h"
289 #include "test/rust_test_harness.h"
290 #include "test/rust_test_util.h"
291 #include "test/rust_test_runtime.h"
297 // indent-tabs-mode: nil
299 // buffer-file-coding-system: utf-8-unix
300 // compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";