su
1.12.11
|
00001 /* 00002 * This file is part of the Sofia-SIP package 00003 * 00004 * Copyright (C) 2006 Nokia Corporation. 00005 * 00006 * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden> 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation; either version 2.1 of 00011 * the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00021 * 02110-1301 USA 00022 * 00023 */ 00024 00025 #ifndef SU_ALLOC_H 00026 #define SU_ALLOC_H 00027 00037 #ifndef SU_TYPES_H 00038 #include <sofia-sip/su_types.h> 00039 #endif 00040 00041 #include <stdarg.h> 00042 00043 SOFIA_BEGIN_DECLS 00044 00045 #ifndef SU_HOME_T 00046 #define SU_HOME_T struct su_home_s 00047 #endif 00048 00050 typedef SU_HOME_T su_home_t; 00051 typedef struct su_block_s su_block_t; 00052 00054 typedef struct su_alock su_alock_t; 00055 00057 struct su_home_s { 00058 int suh_size; 00059 su_block_t *suh_blocks; 00060 su_alock_t *suh_lock; 00061 }; 00062 00063 #define SU_HOME_INIT(obj) { 0, NULL, NULL } 00064 00065 SU_DLL void *su_home_new(isize_t size) 00066 __attribute__((__malloc__)); 00067 SU_DLL void *su_home_ref(su_home_t const *); 00068 SU_DLL int su_home_unref(su_home_t *); 00069 00070 SU_DLL size_t su_home_refcount(su_home_t *home); 00071 00072 SU_DLL int su_home_destructor(su_home_t *, void (*)(void *)); 00073 00074 SU_DLL int su_home_desctructor(su_home_t *, void (*)(void *)); 00075 #ifndef su_home_desctructor 00076 /* This has typo in before 1.12.4 */ 00077 #define su_home_desctructor(home, destructor) \ 00078 su_home_destructor((home), (destructor)) 00079 #endif 00080 00081 SU_DLL void *su_home_clone(su_home_t *parent, isize_t size) 00082 __attribute__((__malloc__)); 00083 00084 SU_DLL int su_home_init(su_home_t *h); 00085 00086 SU_DLL void su_home_deinit(su_home_t *h); 00087 00088 SU_DLL void su_home_preload(su_home_t *h, isize_t n, isize_t size); 00089 00090 SU_DLL su_home_t *su_home_auto(void *area, isize_t size); 00091 00092 #define SU_HOME_AUTO_SIZE(n) \ 00093 (((n) + ((sizeof(su_home_t) + 7) & (size_t)~8) + \ 00094 ((3 * sizeof (void *) + 4 * sizeof(unsigned) + \ 00095 7 * (sizeof (long) + sizeof(void *)) + 7) & (size_t)~8)) \ 00096 / sizeof(su_home_t)) 00097 00098 SU_DLL int su_home_move(su_home_t *dst, su_home_t *src); 00099 00100 SU_DLL int su_home_threadsafe(su_home_t *home); 00101 00102 SU_DLL int su_home_has_parent(su_home_t const *home); 00103 00104 SU_DLL su_home_t *su_home_parent(su_home_t const *home); 00105 00106 SU_DLL void su_home_check(su_home_t const *home); 00107 00108 SU_DLL int su_home_check_alloc(su_home_t const *home, void const *data); 00109 00110 SU_DLL int su_home_mutex_lock(su_home_t *home); 00111 00112 SU_DLL int su_home_mutex_unlock(su_home_t *home); 00113 00114 SU_DLL int su_home_lock(su_home_t *home); 00115 SU_DLL int su_home_trylock(su_home_t *home); 00116 SU_DLL int su_home_unlock(su_home_t *home); 00117 00118 SU_DLL void *su_alloc(su_home_t *h, isize_t size) 00119 __attribute__((__malloc__)); 00120 SU_DLL void *su_zalloc(su_home_t *h, isize_t size) 00121 __attribute__((__malloc__)); 00122 SU_DLL void *su_salloc(su_home_t *h, isize_t size) 00123 __attribute__((__malloc__)); 00124 SU_DLL void *su_realloc(su_home_t *h, void *data, isize_t size) 00125 __attribute__((__malloc__)); 00126 SU_DLL int su_in_home(su_home_t *h, void const *data); 00127 00128 SU_DLL char *su_strdup(su_home_t *home, char const *s) 00129 __attribute__((__malloc__)); 00130 SU_DLL char *su_strcat(su_home_t *home, char const *s1, char const *s2) 00131 __attribute__((__malloc__)); 00132 SU_DLL char *su_strndup(su_home_t *home, char const *s, isize_t n) 00133 __attribute__((__malloc__)); 00134 00135 SU_DLL char *su_strcat_all(su_home_t *home, ...) 00136 __attribute__((__malloc__)); 00137 00138 SU_DLL char *su_sprintf(su_home_t *home, char const *fmt, ...) 00139 __attribute__ ((__malloc__, __format__ (printf, 2, 3))); 00140 00141 SU_DLL char *su_vsprintf(su_home_t *home, char const *fmt, va_list ap) 00142 __attribute__((__malloc__)); 00143 00144 /* free an independent block */ 00145 SU_DLL void su_free(su_home_t *h, void *); 00146 00148 SU_DLL int su_home_is_threadsafe(su_home_t const *home); 00149 00150 /* ---------------------------------------------------------------------- */ 00151 /* Deprecated */ 00152 00153 SU_DLL su_home_t *su_home_create(void) 00154 __attribute__((__malloc__)); 00155 SU_DLL void su_home_destroy(su_home_t *h); 00156 00157 #define su_home_zap(h) su_home_unref((h)) 00158 00159 SOFIA_END_DECLS 00160 00161 #endif /* ! defined(SU_ALLOC_H) */