add archipelago-dbg package
[archipelago] / xseg / xtypes / xobj.h
1 #ifndef __XOBJ_H__
2 #define __XOBJ_H__
3
4 #include <sys/util.h>
5 #include <xtypes/xlock.h>
6 #include <xtypes/xheap.h>
7 #include <xtypes/domain.h>
8 #include <xtypes/xhash.h>
9
10 struct xobject_header {
11         XPTR_TYPE(struct xseg_object_handler) obj_h;
12 };
13
14 struct xobject {
15         uint32_t magic;
16         uint64_t size;
17         xptr next;
18 };
19
20 struct xobject_h {
21         struct xlock lock;
22         uint32_t magic;
23         uint64_t obj_size;
24         uint32_t flags;
25         XPTR_TYPE(void) container;
26         xptr heap;
27         xptr allocated;
28         uint64_t nr_allocated;
29         uint64_t allocated_space;
30         xptr list;
31         uint64_t nr_free;
32 };
33
34 struct xobject_iter {
35         struct xobject_h *obj_h;
36         xhash_iter_t xhash_it;
37         void *chunk;
38         xhashidx cnt;
39 };
40
41 void *xobj_get_obj(struct xobject_h * obj_h, uint32_t flags);
42 void xobj_put_obj(struct xobject_h * obj_h, void *ptr);
43 int xobj_alloc_obj(struct xobject_h * obj_h, uint64_t nr);
44 int xobj_handler_init(struct xobject_h *obj_h, void *container,
45                 uint32_t magic, uint64_t size, struct xheap *heap);
46
47 void xobj_iter_init(struct xobject_h *obj_h, struct xobject_iter *it);
48 int xobj_iterate(struct xobject_h *obj_h, struct xobject_iter *it, void **obj);
49 int xobj_check(struct xobject_h *obj_h, void *obj);
50 int xobj_isFree(struct xobject_h *obj_h, void *obj);
51
52 int __xobj_check(struct xobject_h *obj_h, void *obj);
53 int __xobj_isFree(struct xobject_h *obj_h, void *obj);
54
55 //TODO 
56 //xobj_handler_destroy()
57 //releases allocated pages
58 //
59 //maybe we need lock free versions of get/put obj
60 //
61 //also an
62 //unsigned long xobj_get_objs(obj_h, flags, uint64_t nr, void **buf)
63 //which will put nr objects in buf
64 #endif