gam-resource-manager: adjust to updated proxied call callback signature.
[profile/ivi/murphy.git] / src / breedline / mm.h
1 /*
2  * Copyright (c) 2012, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *   * Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *   * Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *   * Neither the name of Intel Corporation nor the names of its contributors
14  *     may be used to endorse or promote products derived from this software
15  *     without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef __BREEDLINE_MM_H__
31 #define __BREEDLINE_MM_H__
32
33 #include <stdlib.h>
34 #include <string.h>
35
36 /* Macro that can be used to pass the location of its usage further. */
37 #define BRL_LOC __FILE__, __LINE__, __func__
38
39 /* Memory allocation macros used by breedline. */
40 #define brl_allocz(size) ({                                        \
41             void   *_ptr;                                          \
42             size_t  _size = size;                                  \
43                                                                    \
44             if ((_ptr = __brl_mm.allocfn(_size, BRL_LOC)) != NULL) \
45                 memset(_ptr, 0, _size);                            \
46                                                                    \
47             __brl_mm_busy = TRUE;                                  \
48                                                                    \
49             _ptr; })
50
51 #define brl_reallocz(ptr, o, n) ({                               \
52             typeof(ptr) _ptr;                                    \
53             size_t      _size = sizeof(*_ptr) * (n);             \
54             typeof(n)   _n    = (n);                             \
55             typeof(o)   _o;                                      \
56                                                                  \
57             if ((ptr) != NULL)                                   \
58                 _o = o;                                          \
59             else                                                 \
60                 _o = 0;                                          \
61                                                                  \
62             _ptr = __brl_mm.reallocfn(ptr, _size, BRL_LOC);      \
63             if (_ptr != NULL || _n == 0) {                       \
64                 if ((unsigned)(_n) > (unsigned)(_o))             \
65                     memset(_ptr + (_o), 0,                       \
66                            ((_n) - (_o)) * sizeof(*_ptr));       \
67                 ptr = _ptr;                                      \
68             }                                                    \
69                                                                  \
70             __brl_mm_busy = TRUE;                                \
71                                                                  \
72             _ptr; })
73
74 #define brl_strdup(s) ({                                         \
75             __brl_mm_busy = TRUE;                                \
76                                                                  \
77             __brl_mm.strdupfn((s), BRL_LOC);                     \
78         })
79
80 #define brl_free(ptr) __brl_mm.freefn((ptr), BRL_LOC)
81
82 extern brl_allocator_t __brl_mm;
83 extern int __brl_mm_busy;
84
85 #endif /* __BREEDLINE_MM_H__ */