00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CU_OALLOC_H
00019 #define CU_OALLOC_H
00020
00021 #include <cuoo/type.h>
00022 #include <cu/memory.h>
00023
00024 CU_BEGIN_DECLARATIONS
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define CUP_OBJ_EXTRA_BYTES 0
00034
00035 #define CUOO_OBJ_ALLOC_SIZEG(struct_size) \
00036 (((struct_size) + sizeof(cuex_meta_t) \
00037 + CU_GRAN_SIZE - 1 + CUP_OBJ_EXTRA_BYTES)/CU_GRAN_SIZE)
00038
00039 void *cuexP_oalloc_ord_fin_raw(cuex_meta_t meta, size_t sizeg);
00040 void *cuexP_oalloc_unord_fin_raw(cuex_meta_t meta, size_t sizeg);
00041
00042 CU_SINLINE void *
00043 cuexP_oalloc(cuex_meta_t meta, size_t size)
00044 {
00045 cuex_meta_t *p = (cuex_meta_t *)cu_galloc(size + sizeof(cuex_meta_t));
00046 *p = meta + 1;
00047 cu_debug_assert(((uintptr_t)*p & 3) != 0);
00048 return p + 1;
00049 }
00050
00051
00052
00053
00054 CU_SINLINE void *
00055 cuoo_oalloc(cuoo_type_t type, size_t size)
00056 {
00057 cuex_meta_t *p = (cuex_meta_t *)cu_galloc(size + sizeof(cuex_meta_t));
00058 *p = cuoo_type_to_meta(type) + 1;
00059 cu_debug_assert(((uintptr_t)*p & 3) != 0);
00060 return p + 1;
00061 }
00062
00063
00064
00065
00066 CU_SINLINE void *
00067 cuoo_oalloc_self_instance(size_t size)
00068 {
00069 cuex_meta_t *p = (cuex_meta_t *)cu_galloc(size + sizeof(cuex_meta_t));
00070 *p = cuoo_type_to_meta((cuoo_type_t)(p + 1)) + 1;
00071 return p + 1;
00072 }
00073
00074
00075
00076
00077 CU_SINLINE void *
00078 cuoo_oalloc_ord_fin(cuoo_type_t type, size_t size)
00079 {
00080 return cuexP_oalloc_ord_fin_raw(cuoo_type_to_meta(type),
00081 CUOO_OBJ_ALLOC_SIZEG(size));
00082 }
00083
00084
00085
00086
00087
00088
00089 CU_SINLINE void *
00090 cuoo_oalloc_unord_fin(cuoo_type_t type, size_t size)
00091 {
00092 return cuexP_oalloc_unord_fin_raw(cuoo_type_to_meta(type),
00093 CUOO_OBJ_ALLOC_SIZEG(size));
00094 }
00095
00096 #define cuoo_onew(prefix) \
00097 ((struct prefix *) \
00098 cuoo_oalloc(prefix##_type(), sizeof(struct prefix)))
00099
00100 #define cuoo_onew_ord_fin(prefix) \
00101 ((struct prefix *) \
00102 cuexP_oalloc_ord_fin_raw(cuoo_type_to_meta(prefix##_type()), \
00103 CUOO_OBJ_ALLOC_SIZEG(sizeof(struct prefix))))
00104
00105
00106 CU_END_DECLARATIONS
00107
00108 #endif