diff options
| author | Michael Bebenita <[email protected]> | 2010-08-17 23:40:07 -0700 |
|---|---|---|
| committer | Michael Bebenita <[email protected]> | 2010-08-17 23:49:57 -0700 |
| commit | 2c1ec6771bd09266308686ab13ca32e2aa73da49 (patch) | |
| tree | acbcae9da89c0f6d37fccdf8b4091f003e798683 /src/rt/memory_region.h | |
| parent | Add a "special" rust_log flag to be used for debugging in cases where the ful... (diff) | |
| download | rust-2c1ec6771bd09266308686ab13ca32e2aa73da49.tar.xz rust-2c1ec6771bd09266308686ab13ca32e2aa73da49.zip | |
Lots of changes around memory managment in the Runtime. Added memory regions and fixed race caused by calling rust_srv::malloc() from multiple threads when sending messages.
Diffstat (limited to 'src/rt/memory_region.h')
| -rw-r--r-- | src/rt/memory_region.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/rt/memory_region.h b/src/rt/memory_region.h new file mode 100644 index 00000000..3411d867 --- /dev/null +++ b/src/rt/memory_region.h @@ -0,0 +1,37 @@ +/* + * The Rust runtime uses memory regions to provide a primitive level of + * memory management and isolation between tasks, and domains. + * + * TODO: Implement a custom lock-free malloc / free instead of relying solely + * on the standard malloc / free. + */ + +#ifndef MEMORY_REGION_H +#define MEMORY_REGION_H + +#include "sync/spin_lock.h" + +class rust_srv; + +class memory_region { +private: + rust_srv *_srv; + memory_region *_parent; + size_t _live_allocations; + array_list<void *> _allocation_list; + const bool _synchronized; + spin_lock _lock; +public: + enum memory_region_type { + LOCAL = 0x1, SYNCHRONIZED = 0x2 + }; + memory_region(rust_srv *srv, bool synchronized); + memory_region(memory_region *parent); + void *malloc(size_t size); + void *calloc(size_t size); + void *realloc(void *mem, size_t size); + void free(void *mem); + virtual ~memory_region(); +}; + +#endif /* MEMORY_REGION_H */ |