136 } |
136 } |
137 abort(); |
137 abort(); |
138 } |
138 } |
139 |
139 |
140 void cxMempoolDestroy(CxMempool *pool) { |
140 void cxMempoolDestroy(CxMempool *pool) { |
|
141 if (pool == NULL) return; |
141 struct cx_mempool_memory_s *mem; |
142 struct cx_mempool_memory_s *mem; |
142 for (size_t i = 0; i < pool->size; i++) { |
143 for (size_t i = 0; i < pool->size; i++) { |
143 mem = pool->data[i]; |
144 mem = pool->data[i]; |
144 if (mem->destructor) { |
145 if (mem->destructor) { |
145 mem->destructor(mem->c); |
146 mem->destructor(mem->c); |
154 void cxMempoolSetDestructor( |
155 void cxMempoolSetDestructor( |
155 void *ptr, |
156 void *ptr, |
156 cx_destructor_func func |
157 cx_destructor_func func |
157 ) { |
158 ) { |
158 *(cx_destructor_func *) ((char *) ptr - sizeof(cx_destructor_func)) = func; |
159 *(cx_destructor_func *) ((char *) ptr - sizeof(cx_destructor_func)) = func; |
|
160 } |
|
161 |
|
162 void cxMempoolRemoveDestructor(void *ptr) { |
|
163 *(cx_destructor_func *) ((char *) ptr - sizeof(cx_destructor_func)) = NULL; |
159 } |
164 } |
160 |
165 |
161 struct cx_mempool_foreign_mem_s { |
166 struct cx_mempool_foreign_mem_s { |
162 cx_destructor_func destr; |
167 cx_destructor_func destr; |
163 void* mem; |
168 void* mem; |