2012-02-01 20:52:08 -06:00
|
|
|
#ifndef BOXED_REGION_H
|
|
|
|
#define BOXED_REGION_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
struct type_desc;
|
|
|
|
class memory_region;
|
|
|
|
struct rust_opaque_box;
|
2012-05-14 10:22:51 -05:00
|
|
|
struct rust_env;
|
2012-02-01 20:52:08 -06:00
|
|
|
|
|
|
|
/* Tracks the data allocated by a particular task in the '@' region.
|
|
|
|
* Currently still relies on the standard malloc as a backing allocator, but
|
|
|
|
* this could be improved someday if necessary. Every allocation must provide
|
|
|
|
* a type descr which describes the payload (what follows the header). */
|
|
|
|
class boxed_region {
|
|
|
|
private:
|
2012-05-14 10:22:51 -05:00
|
|
|
rust_env *env;
|
2012-02-01 20:52:08 -06:00
|
|
|
memory_region *backing_region;
|
|
|
|
rust_opaque_box *live_allocs;
|
|
|
|
|
|
|
|
size_t align_to(size_t v, size_t align) {
|
|
|
|
size_t alignm1 = align - 1;
|
|
|
|
v += alignm1;
|
|
|
|
v &= ~alignm1;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2012-05-14 10:22:51 -05:00
|
|
|
boxed_region(rust_env *e, memory_region *br)
|
|
|
|
: env(e)
|
|
|
|
, backing_region(br)
|
2012-02-01 20:52:08 -06:00
|
|
|
, live_allocs(NULL)
|
|
|
|
{}
|
|
|
|
|
|
|
|
rust_opaque_box *first_live_alloc() { return live_allocs; }
|
|
|
|
|
2012-06-13 19:59:21 -05:00
|
|
|
rust_opaque_box *malloc(type_desc *td, size_t body_size);
|
|
|
|
rust_opaque_box *calloc(type_desc *td, size_t body_size);
|
2012-07-17 18:31:19 -05:00
|
|
|
rust_opaque_box *realloc(rust_opaque_box *box, size_t new_size);
|
2012-02-01 20:52:08 -06:00
|
|
|
void free(rust_opaque_box *box);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* BOXED_REGION_H */
|
2012-06-13 19:59:21 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: C++
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|