hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cf_alloc.h
Go to the documentation of this file.
1 /*
2  * Citrusleaf Foundation
3  * include/alloc.h - memory allocation framework
4  *
5  * Copyright 2008 by Citrusleaf. All rights reserved.
6  * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE. THE COPYRIGHT NOTICE
7  * ABOVE DOES NOT EVIDENCE ANY ACTUAL OR INTENDED PUBLICATION.
8  */
9 
10 #pragma once
11 
12 #include <stddef.h>
13 
14 #include "cf_atomic.h"
16 
17 
18 /* SYNOPSIS
19  * Reference counting allocation
20  * This extends the traditional C memory allocation system to support
21  * reference-counted garbage collection. When a memory region is allocated
22  * via cf_rc_alloc(), slightly more memory than was requested is actually
23  * allocated. A reference counter is inserted in the excess space at the
24  * at the front of the region, and a pointer to the first byte of the data
25  * allocation is returned.
26  *
27  * Two additional functions are supplied to support using a reference
28  * counted region: cf_client_rc_reserve() reserves a memory region, and
29  * cf_client_rc_release() releases an already-held reservation. It is possible to
30  * call cf_client_rc_release() on a region without first acquiring a reservation.
31  * This will result in undefined behavior.
32  */
33 
34 
35 
36 /* cf_client_rc_counter
37  * A reference counter */
39 
40 /* Function declarations */
41 extern cf_atomic_int_t cf_client_rc_count(void *addr);
42 extern void *cf_client_rc_alloc(size_t sz);
43 extern int cf_client_rc_reserve(void *addr);
44 extern cf_atomic_int_t cf_client_rc_release_x(void *addr, bool autofree);
45 extern void cf_client_rc_free(void *addr);
46 #define cf_client_rc_release(a) (cf_client_rc_release_x((a), false))
47 #define cf_client_rc_releaseandfree(a) (cf_client_rc_release_x((a), true))
48