Loading...
Searching...
No Matches
su_alloc.h
Go to the documentation of this file.
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2006 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef SU_ALLOC_H
#define SU_ALLOC_H
#ifndef SU_TYPES_H
#include <sofia-sip/su_types.h>
#endif
#include <stdarg.h>
SOFIA_BEGIN_DECLS
#ifndef SU_HOME_T
#define SU_HOME_T struct su_home_s
#endif
typedef SU_HOME_T su_home_t;
typedef struct su_block_s su_block_t;
typedef struct su_alock su_alock_t;
struct su_home_s {
int suh_size;
su_block_t *suh_blocks;
su_alock_t *suh_lock;
};
#define SU_HOME_INIT(obj) { 0, NULL, NULL }
SU_DLL void *su_home_new(isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_home_ref(su_home_t const *);
SU_DLL int su_home_unref(su_home_t *);
SU_DLL size_t su_home_refcount(su_home_t *home);
SU_DLL int su_home_destructor(su_home_t *, void (*)(void *));
SU_DLL int su_home_desctructor(su_home_t *, void (*)(void *));
#ifndef su_home_desctructor
/* This has typo in before 1.12.4 */
#define su_home_desctructor(home, destructor) \
su_home_destructor((home), (destructor))
#endif
SU_DLL void *su_home_clone(su_home_t *parent, isize_t size)
__attribute__((__malloc__));
SU_DLL int su_home_init(su_home_t *h);
SU_DLL void su_home_deinit(su_home_t *h);
SU_DLL void su_home_preload(su_home_t *h, isize_t n, isize_t size);
SU_DLL su_home_t *su_home_auto(void *area, isize_t size);
#define SU_HOME_AUTO_SIZE(n) \
(((n) + ((sizeof(su_home_t) + 7) & (size_t)~8) + \
((3 * sizeof (void *) + 4 * sizeof(unsigned) + \
7 * (sizeof (long) + sizeof(void *)) + 7) & (size_t)~8)) \
/ sizeof(su_home_t))
SU_DLL int su_home_move(su_home_t *dst, su_home_t *src);
SU_DLL int su_home_threadsafe(su_home_t *home);
SU_DLL int su_home_has_parent(su_home_t const *home);
SU_DLL su_home_t *su_home_parent(su_home_t const *home);
SU_DLL void su_home_check(su_home_t const *home);
SU_DLL int su_home_check_alloc(su_home_t const *home, void const *data);
SU_DLL int su_home_mutex_lock(su_home_t *home);
SU_DLL int su_home_mutex_unlock(su_home_t *home);
SU_DLL int su_home_lock(su_home_t *home);
SU_DLL int su_home_trylock(su_home_t *home);
SU_DLL int su_home_unlock(su_home_t *home);
SU_DLL void *su_alloc(su_home_t *h, isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_zalloc(su_home_t *h, isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_salloc(su_home_t *h, isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_realloc(su_home_t *h, void *data, isize_t size)
__attribute__((__malloc__));
SU_DLL int su_in_home(su_home_t *h, void const *data);
SU_DLL char *su_strdup(su_home_t *home, char const *s)
__attribute__((__malloc__));
SU_DLL char *su_strcat(su_home_t *home, char const *s1, char const *s2)
__attribute__((__malloc__));
SU_DLL char *su_strndup(su_home_t *home, char const *s, isize_t n)
__attribute__((__malloc__));
SU_DLL char *su_strcat_all(su_home_t *home, ...)
__attribute__((__malloc__, __sentinel__ (0)));
SU_DLL char *su_sprintf(su_home_t *home, char const *fmt, ...)
__attribute__ ((__malloc__, __format__ (printf, 2, 3)));
SU_DLL char *su_vsprintf(su_home_t *home, char const *fmt, va_list ap)
__attribute__((__malloc__));
/* free an independent block */
SU_DLL void su_free(su_home_t *h, void *);
SU_DLL int su_home_is_threadsafe(su_home_t const *home);
/* ---------------------------------------------------------------------- */
/* Deprecated */
SU_DLL su_home_t *su_home_create(void)
__attribute__((__malloc__));
SU_DLL void su_home_destroy(su_home_t *h);
#define su_home_zap(h) su_home_unref((h))
SOFIA_END_DECLS
#endif /* ! defined(SU_ALLOC_H) */
su_home_threadsafe
int su_home_threadsafe(su_home_t *home)
Convert su_home_t object to a thread-safe one.
Definition su_alloc_lock.c:92
su_strdup
char * su_strdup(su_home_t *home, char const *s))
Duplicate a string, allocate memory from home.
Definition su_strdup.c:51
su_home_s
Memory home structure.
Definition su_alloc.h:57
su_home_destroy
void su_home_destroy(su_home_t *h)
Destroy a home object.
Definition su_alloc.c:944
su_home_mutex_unlock
int su_home_mutex_unlock(su_home_t *home)
Release exclusive lock on home and decrease refcount (if home is threadsafe).
Definition su_alloc.c:1575
su_home_has_parent
int su_home_has_parent(su_home_t const *home)
Return true if home is a clone.
Definition su_alloc.c:747
su_strcat_all
char * su_strcat_all(su_home_t *home,...)))
Concate multiple strings, allocate memory for result from home.
Definition su_strdup.c:111
su_alloc
void * su_alloc(su_home_t *h, isize_t size))
Allocate a memory block.
Definition su_alloc.c:779
su_vsprintf
char * su_vsprintf(su_home_t *home, char const *fmt, va_list ap))
Copy a formatted string.
Definition su_sprintf.c:68
su_home_check_alloc
int su_home_check_alloc(su_home_t const *home, void const *data)
Check if pointer has been allocated through home.
Definition su_alloc.c:861
su_home_move
int su_home_move(su_home_t *dst, su_home_t *src)
Move allocations from a su_home_t object to another.
Definition su_alloc.c:1087
su_sprintf
char * su_sprintf(su_home_t *home, char const *fmt,...)))
Copy a formatted string.
Definition su_sprintf.c:119
su_realloc
void * su_realloc(su_home_t *h, void *data, isize_t size))
Reallocate a memory block.
Definition su_alloc.c:1290
su_zalloc
void * su_zalloc(su_home_t *h, isize_t size))
Allocate and zero a memory block.
Definition su_alloc.c:1466
su_home_trylock
int su_home_trylock(su_home_t *home)
Try to obtain exclusive lock on home without increasing refcount.
Definition su_alloc.c:1627
su_home_parent
su_home_t * su_home_parent(su_home_t const *home)
Return home's parent home.
Definition su_alloc.c:753
su_home_check
void su_home_check(su_home_t const *home)
Check home consistency.
Definition su_alloc.c:885
su_in_home
int su_in_home(su_home_t *h, void const *data)
Check if a memory block has been allocated from the home.
Definition su_alloc.c:1427
su_home_new
void * su_home_new(isize_t size))
Create a new su_home_t object.
Definition su_alloc.c:548
su_home_ref
void * su_home_ref(su_home_t const *)
Create a new reference to a home object.
Definition su_alloc.c:573
su_home_clone
void * su_home_clone(su_home_t *parent, isize_t size))
Clone a su_home_t object.
Definition su_alloc.c:723
su_home_refcount
size_t su_home_refcount(su_home_t *home)
Return reference count of home.
Definition su_alloc.c:688
su_strndup
char * su_strndup(su_home_t *home, char const *s, isize_t n))
Duplicate a string with given size, allocate memory from home.
Definition su_strdup.c:159
su_salloc
void * su_salloc(su_home_t *h, isize_t size))
Allocate a structure.
Definition su_alloc.c:1512
su_home_unlock
int su_home_unlock(su_home_t *home)
Release exclusive lock on home.
Definition su_alloc.c:1649
su_home_deinit
void su_home_deinit(su_home_t *h)
Free memory blocks allocated through home.
Definition su_alloc.c:1060
su_home_destructor
int su_home_destructor(su_home_t *, void(*)(void *))
Set destructor function.
Definition su_alloc.c:603
su_alock_t
struct su_alock su_alock_t
Thread-locking function.
Definition su_alloc.h:54
su_home_auto
su_home_t * su_home_auto(void *area, isize_t size)
Preload a memory home from stack.
Definition su_alloc.c:1234
su_home_unref
int su_home_unref(su_home_t *)
Unreference a su_home_t object.
Definition su_alloc.c:650
su_home_mutex_lock
int su_home_mutex_lock(su_home_t *home)
Increase refcount and obtain exclusive lock on home.
Definition su_alloc.c:1551
su_home_lock
int su_home_lock(su_home_t *home)
Obtain exclusive lock on home without increasing refcount.
Definition su_alloc.c:1606
su_home_create
su_home_t * su_home_create(void))
Create an su_home_t object.
Definition su_alloc.c:928
su_free
void su_free(su_home_t *h, void *)
Free a memory block.
Definition su_alloc.c:802
su_home_is_threadsafe
int su_home_is_threadsafe(su_home_t const *home)
Check if a memory home is threadsafe.
Definition su_alloc.c:1536
su_home_t
SU_HOME_T su_home_t
Memory home type.
Definition su_alloc.h:50
su_home_preload
void su_home_preload(su_home_t *h, isize_t n, isize_t size)
Preload a memory home.
Definition su_alloc.c:1202
su_strcat
char * su_strcat(su_home_t *home, char const *s1, char const *s2))
Concate two strings, allocate memory for result from home.
Definition su_strdup.c:77
su_home_init
int su_home_init(su_home_t *h)
Initialize an su_home_t struct.
Definition su_alloc.c:975
su_types.h
Basic integer types for su library.

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