su_alloc.h 3.57 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
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
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
 * * 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  /** Defined when su_alloc.h has been included. */
#define SU_ALLOC_H "$Id: su_alloc.h,v 1.1.1.1 2005/07/20 20:35:57 kaiv Exp $"

/**@ingroup su_alloc
 *
 * @file su_alloc.h Home-based memory management interface
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 * 
 * @date Created: Thu Aug 19 01:12:25 1999 ppessi
 * $Date: 2005/07/20 20:35:57 $
 */

#ifndef SU_CONFIG_H
#include <su_config.h>
#endif

#ifndef SU_HOME_T
#define SU_HOME_T struct su_home_s
#endif

#include <stdarg.h>

/** Memory home type. */
typedef SU_HOME_T su_home_t;
typedef struct su_block_s su_block_t;

/** Thread-locking function. @internal */
Pekka Pessi's avatar
Pekka Pessi committed
53
typedef struct su_alock su_alock_t;
Pekka Pessi's avatar
Pekka Pessi committed
54 55 56

/** Memory home structure */
struct su_home_s { 
Pekka Pessi's avatar
Pekka Pessi committed
57
  int  suh_size;
Pekka Pessi's avatar
Pekka Pessi committed
58
  su_block_t *suh_blocks;
Pekka Pessi's avatar
Pekka Pessi committed
59
  su_alock_t *suh_lock;
Pekka Pessi's avatar
Pekka Pessi committed
60 61
};

Pekka Pessi's avatar
Pekka Pessi committed
62 63 64 65 66 67 68 69 70 71 72
#define SU_HOME_INIT(obj) { 0 }

SU_DLL void *su_home_new(int size)
     __attribute__((__malloc__));
SU_DLL void *su_home_ref(su_home_t *);
SU_DLL void su_home_unref(su_home_t *);

SU_DLL void *su_home_clone(su_home_t *parent, int size)
     __attribute__((__malloc__));

#define su_home_zap(h) su_home_unref((h))
Pekka Pessi's avatar
Pekka Pessi committed
73 74 75 76 77 78 79 80 81 82

SU_DLL su_home_t *su_home_create(void)
     __attribute__((__malloc__));
SU_DLL void su_home_destroy(su_home_t *h);

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, int n, int size);

Pekka Pessi's avatar
Pekka Pessi committed
83
SU_DLL su_home_t *su_home_incref(su_home_t const *);
Pekka Pessi's avatar
Pekka Pessi committed
84

Pekka Pessi's avatar
Pekka Pessi committed
85
SU_DLL void su_home_decref(su_home_t *);
Pekka Pessi's avatar
Pekka Pessi committed
86 87 88 89 90

SU_DLL int su_home_move(su_home_t *dst, su_home_t *src);

SU_DLL int su_home_threadsafe(su_home_t *home);

Pekka Pessi's avatar
Pekka Pessi committed
91 92
SU_DLL int su_home_has_parent(su_home_t const *home);

Pekka Pessi's avatar
Pekka Pessi committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
SU_DLL void su_home_check(su_home_t const *home);

SU_DLL int su_home_mutex_lock(su_home_t *home);

SU_DLL int su_home_mutex_unlock(su_home_t *home);

SU_DLL void *su_alloc(su_home_t *h, int size)
     __attribute__((__malloc__));
SU_DLL void *su_zalloc(su_home_t *h, int size)
     __attribute__((__malloc__));
SU_DLL void *su_salloc(su_home_t *h, int size)
     __attribute__((__malloc__));
SU_DLL void *su_realloc(su_home_t *h, void *data, int size)
     __attribute__((__malloc__));

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, int n)
     __attribute__((__malloc__));

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 *);		

#endif /* ! defined(SU_ALLOC_H) */