su  1.12.11devel
 All Data Structures Files Functions Variables Typedefs Enumerator Macros Groups Pages
su_alloc.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Sofia-SIP package
3  *
4  * Copyright (C) 2006 Nokia Corporation.
5  *
6  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 
25 #ifndef SU_ALLOC_H
26 #define SU_ALLOC_H
27 
37 #ifndef SU_TYPES_H
38 #include <sofia-sip/su_types.h>
39 #endif
40 
41 #include <stdarg.h>
42 
43 SOFIA_BEGIN_DECLS
44 
45 #ifndef SU_HOME_T
46 #define SU_HOME_T struct su_home_s
47 #endif
48 
50 typedef SU_HOME_T su_home_t;
51 typedef struct su_block_s su_block_t;
52 
54 typedef struct su_alock su_alock_t;
55 
57 struct su_home_s {
58  int suh_size;
59  su_block_t *suh_blocks;
60  su_alock_t *suh_lock;
61 };
62 
63 #define SU_HOME_INIT(obj) { 0, NULL, NULL }
64 
65 SU_DLL void *su_home_new(isize_t size)
66  __attribute__((__malloc__));
67 SU_DLL void *su_home_ref(su_home_t const *);
68 SU_DLL int su_home_unref(su_home_t *);
69 
70 SU_DLL size_t su_home_refcount(su_home_t *home);
71 
72 SU_DLL int su_home_destructor(su_home_t *, void (*)(void *));
73 
74 SU_DLL int su_home_desctructor(su_home_t *, void (*)(void *));
75 #ifndef su_home_desctructor
76 /* This has typo in before 1.12.4 */
77 #define su_home_desctructor(home, destructor) \
78  su_home_destructor((home), (destructor))
79 #endif
80 
81 SU_DLL void *su_home_clone(su_home_t *parent, isize_t size)
82  __attribute__((__malloc__));
83 
84 SU_DLL int su_home_init(su_home_t *h);
85 
86 SU_DLL void su_home_deinit(su_home_t *h);
87 
88 SU_DLL void su_home_preload(su_home_t *h, isize_t n, isize_t size);
89 
90 SU_DLL su_home_t *su_home_auto(void *area, isize_t size);
91 
92 #define SU_HOME_AUTO_SIZE(n) \
93  (((n) + ((sizeof(su_home_t) + 7) & (size_t)~8) + \
94  ((3 * sizeof (void *) + 4 * sizeof(unsigned) + \
95  7 * (sizeof (long) + sizeof(void *)) + 7) & (size_t)~8)) \
96  / sizeof(su_home_t))
97 
98 SU_DLL int su_home_move(su_home_t *dst, su_home_t *src);
99 
100 SU_DLL int su_home_threadsafe(su_home_t *home);
101 
102 SU_DLL int su_home_has_parent(su_home_t const *home);
103 
104 SU_DLL su_home_t *su_home_parent(su_home_t const *home);
105 
106 SU_DLL void su_home_check(su_home_t const *home);
107 
108 SU_DLL int su_home_check_alloc(su_home_t const *home, void const *data);
109 
110 SU_DLL int su_home_mutex_lock(su_home_t *home);
111 
112 SU_DLL int su_home_mutex_unlock(su_home_t *home);
113 
114 SU_DLL int su_home_lock(su_home_t *home);
115 SU_DLL int su_home_trylock(su_home_t *home);
116 SU_DLL int su_home_unlock(su_home_t *home);
117 
118 SU_DLL void *su_alloc(su_home_t *h, isize_t size)
119  __attribute__((__malloc__));
120 SU_DLL void *su_zalloc(su_home_t *h, isize_t size)
121  __attribute__((__malloc__));
122 SU_DLL void *su_salloc(su_home_t *h, isize_t size)
123  __attribute__((__malloc__));
124 SU_DLL void *su_realloc(su_home_t *h, void *data, isize_t size)
125  __attribute__((__malloc__));
126 SU_DLL int su_in_home(su_home_t *h, void const *data);
127 
128 SU_DLL char *su_strdup(su_home_t *home, char const *s)
129  __attribute__((__malloc__));
130 SU_DLL char *su_strcat(su_home_t *home, char const *s1, char const *s2)
131  __attribute__((__malloc__));
132 SU_DLL char *su_strndup(su_home_t *home, char const *s, isize_t n)
133  __attribute__((__malloc__));
134 
135 SU_DLL char *su_strcat_all(su_home_t *home, ...)
136  __attribute__((__malloc__, __sentinel__ (0)));
137 
138 SU_DLL char *su_sprintf(su_home_t *home, char const *fmt, ...)
139  __attribute__ ((__malloc__, __format__ (printf, 2, 3)));
140 
141 SU_DLL char *su_vsprintf(su_home_t *home, char const *fmt, va_list ap)
142  __attribute__((__malloc__));
143 
144 /* free an independent block */
145 SU_DLL void su_free(su_home_t *h, void *);
146 
148 SU_DLL int su_home_is_threadsafe(su_home_t const *home);
149 
150 /* ---------------------------------------------------------------------- */
151 /* Deprecated */
152 
153 SU_DLL su_home_t *su_home_create(void)
154  __attribute__((__malloc__));
155 SU_DLL void su_home_destroy(su_home_t *h);
156 
157 #define su_home_zap(h) su_home_unref((h))
158 
159 SOFIA_END_DECLS
160 
161 #endif /* ! defined(SU_ALLOC_H) */

Sofia-SIP 1.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.