summaryrefslogtreecommitdiff
path: root/libclapi/cl_alloc.h
blob: 4980d0fc4375aac3e6bf6b217ba8b365021e2c98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright © 2012 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Benjamin Segovia <benjamin.segovia@intel.com>
 */

#ifndef __CL_ALLOC_H__
#define __CL_ALLOC_H__

#include <stdlib.h>

//#define CL_ALLOC_DEBUG 1
#ifdef CL_ALLOC_DEBUG

/* Return a valid pointer for the requested memory block size */
extern void* cl_malloc(size_t sz, char* file, int line);
#define CL_MALLOC(SZ) cl_malloc(SZ, __FILE__, __LINE__)

/* Aligned malloc */
extern void* cl_memalign(size_t sz, size_t align, char* file, int line);
#define CL_MEMALIGN(SZ, ALIGN) cl_memalign(SZ, ALIGN, __FILE__, __LINE__)

/* malloc + memzero */
extern void* cl_calloc(size_t n, size_t elem_size, char* file, int line);
#define CL_CALLOC(N, ELEM_SIZE) cl_calloc(N, ELEM_SIZE, __FILE__, __LINE__)

/* Regular realloc */
extern void* cl_realloc(void *ptr, size_t sz, char* file, int line);
#define CL_REALLOC(PTR, SZ) cl_realloc(PTR, SZ, __FILE__, __LINE__)

/* Free a pointer allocated with cl_*alloc */
extern void cl_free(void *ptr, char* file, int line);
#define CL_FREE(PTR) cl_free(PTR, __FILE__, __LINE__)

/* We count the number of allocation. This function report the number of
 * allocation still unfreed
 */
extern void cl_alloc_report_unfreed(void);
#define CL_ALLOC_REPORT_UNFREED() cl_alloc_report_unfreed()

extern void cl_alloc_debug_init(void);
#define CL_ALLOC_DEBUG_INIT() cl_alloc_debug_init()

#else
#define CL_MALLOC(SZ) malloc(SZ)
#define CL_MEMALIGN(SZ, ALIGN) memalign(SZ, ALIGN)
#define CL_CALLOC(N, ELEM_SIZE) calloc(N, ELEM_SIZE)
#define CL_REALLOC(PTR, SZ) realloc(PTR, SZ)
#define CL_FREE(PTR) free(PTR)
#define CL_ALLOC_REPORT_UNFREED()
#define CL_ALLOC_DEBUG_INIT()
#endif /* end of CL_ALLOC_DEBUG */
#endif /* __CL_ALLOC_H__ */