00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUOO_HALLOC_H
00019 #define CUOO_HALLOC_H
00020
00021 #include <cuoo/oalloc.h>
00022 #include <cu/conf.h>
00023 #include <cu/clos.h>
00024 #include <cu/wordarr.h>
00025 #include <cu/ptr.h>
00026
00027 CU_BEGIN_DECLARATIONS
00028
00029 #ifdef CUCONF_ENABLE_RISKY_OPTIMISATIONS
00030 # define CUOO_HCTEM_EXCLUDE_HCOBJ_SHIFT 1
00031 #endif
00032
00033
00034
00035
00036
00037
00038
00039 #define CUOO_HCOBJ_KEY_SIZEW(struct_size) \
00040 (((struct_size) + CU_WORD_SIZE - 1 - CUOO_HCOBJ_SHIFT)/CU_WORD_SIZE)
00041 #define CUOO_HCOBJ_KEY_SIZE(struct_size) \
00042 (CUOO_HCOBJ_KEY_SIZEW(struct_size)*CU_WORD_SIZE)
00043 #define CUOO_HCOBJ_ALLOC_SIZEG(struct_size) \
00044 CUOO_OBJ_ALLOC_SIZEG(struct_size)
00045
00046 #ifndef CU_IN_DOXYGEN
00047 void *cuexP_halloc_raw(cuex_meta_t meta, size_t key_sizew, void *key);
00048 void *cuexP_hxalloc_raw(cuex_meta_t meta, size_t raw_alloc_sizeg,
00049 size_t key_sizew, void *key,
00050 cu_clop(init_nonkey, void, void *));
00051 CU_SINLINE void *
00052 cuooP_hxalloc_init_raw(cuoo_type_t type, size_t raw_alloc_sizeg,
00053 size_t key_sizew, void *key,
00054 cu_clop(init_nonkey, void, void *))
00055 {
00056 return cuexP_hxalloc_raw(cuoo_type_to_meta(type), raw_alloc_sizeg,
00057 key_sizew, key, init_nonkey);
00058 }
00059 void *cuooP_hxalloc_setao_raw(cuoo_type_t type, size_t raw_alloc_sizeg,
00060 size_t key_sizew, void *key,
00061 cu_offset_t ao_offset, AO_t ao_value);
00062 void *cuooP_hxalloc_clear_raw(cuoo_type_t type, size_t raw_alloc_sizeg,
00063 size_t key_sizew, void *key);
00064 #endif
00065
00066 #ifndef CU_IN_DOXYGEN
00067 CU_SINLINE void *
00068 cuexP_halloc(cuex_meta_t meta, size_t key_size, void *key)
00069 {
00070 return cuexP_halloc_raw(meta,
00071 CUOO_HCOBJ_KEY_SIZEW(key_size + CUOO_HCOBJ_SHIFT),
00072 key);
00073 }
00074 #endif
00075
00076
00077
00078 CU_SINLINE void *
00079 cuoo_halloc(cuoo_type_t type, size_t key_size, void *key)
00080 {
00081 return cuexP_halloc_raw(cuoo_type_to_meta(type),
00082 CUOO_HCOBJ_KEY_SIZEW(key_size + CUOO_HCOBJ_SHIFT),
00083 key);
00084 }
00085
00086
00087
00088
00089
00090 CU_SINLINE void *
00091 cuoo_hxalloc_init(cuoo_type_t type, size_t struct_size,
00092 size_t key_size, void *key,
00093 cu_clop(init_nonkey, void, void *obj))
00094 {
00095 cu_debug_assert(key_size % CU_WORD_SIZE == 0);
00096 return cuooP_hxalloc_init_raw(
00097 type, CUOO_HCOBJ_ALLOC_SIZEG(struct_size),
00098 CUOO_HCOBJ_KEY_SIZEW(key_size + CUOO_HCOBJ_SHIFT),
00099 key, init_nonkey);
00100 }
00101
00102
00103
00104 CU_SINLINE void *
00105 cuoo_hxalloc_setao(cuoo_type_t type, size_t struct_size,
00106 size_t key_size, void *key,
00107 cu_offset_t ao_offset, AO_t ao_value)
00108 {
00109 cu_debug_assert(key_size % CU_WORD_SIZE == 0);
00110 return cuooP_hxalloc_setao_raw(
00111 type, CUOO_HCOBJ_ALLOC_SIZEG(struct_size),
00112 CUOO_HCOBJ_KEY_SIZEW(key_size + CUOO_HCOBJ_SHIFT),
00113 key, ao_offset, ao_value);
00114 }
00115
00116
00117
00118 CU_SINLINE void *
00119 cuoo_hxalloc_clear(cuoo_type_t type, size_t struct_size,
00120 size_t key_size, void *key)
00121 {
00122 cu_debug_assert(key_size % CU_WORD_SIZE == 0);
00123 return cuooP_hxalloc_clear_raw(
00124 type, CUOO_HCOBJ_ALLOC_SIZEG(struct_size),
00125 CUOO_HCOBJ_KEY_SIZEW(key_size + CUOO_HCOBJ_SHIFT), key);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 #define cuoo_hxnew_init(prefix, key_size, key, init_nonkey) \
00137 ((struct prefix *) \
00138 cuoo_hxalloc_init(prefix##_type(), sizeof(struct prefix), \
00139 key_size, key, init_nonkey))
00140
00141
00142
00143 #define cuoo_hxnew_setao(prefix, key_size, key, ao_offset, ao_value) \
00144 ((struct prefix *) \
00145 cuoo_hxalloc_setao(prefix##_type(), sizeof(struct prefix), \
00146 key_size, key, ao_offset, ao_value))
00147
00148
00149
00150 #define cuoo_hxnew_clear(prefix, key_size, key) \
00151 ((struct prefix *) \
00152 cuoo_hxalloc_clear(prefix##_type(), sizeof(struct prefix), \
00153 key_size, key))
00154
00155
00156
00157 #if defined(CU_COMPAT) && CU_COMPAT < 20080207
00158 # define cuoo_halloc_extra cuoo_hxalloc_init
00159 # define cuoo_halloc_extra_setao cuoo_hxalloc_setao
00160 # define cuoo_hnew_extra cuoo_hxnew_init
00161 # define cuoo_hnew_extra_setao cuoo_hxnew_setao
00162 #endif
00163
00164 CU_END_DECLARATIONS
00165
00166 #if defined(CU_COMPAT) && CU_COMPAT < 20091110
00167 # include <cuoo/hctem.h>
00168 #endif
00169
00170 #endif