refobject.h 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/* Icecast
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2018,      Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
 */

#ifndef __REFOBJECT_H__
#define __REFOBJECT_H__

12 13 14 15
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

16 17 18 19 20
#include "common/thread/thread.h"

#include "icecasttypes.h"
#include "compat.h"

21 22 23 24 25 26 27 28 29 30
#ifdef HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
#define REFOBJECT_NULL          ((refobject_t)(refobject_base_t*)NULL)
#define REFOBJECT_IS_NULL(x)    (((refobject_t)(x)).refobject_base == NULL)
#define REFOBJECT_TO_TYPE(x,y)  ((y)(((refobject_t)(x)).refobject_base))
#else
#define REFOBJECT_NULL          NULL
#define REFOBJECT_IS_NULL(x)    ((x) == NULL)
#define REFOBJECT_TO_TYPE(x,y)  ((y)(x))
#endif

31
typedef void (*refobject_free_t)(refobject_t self, void **userdata);
32 33 34 35 36

struct refobject_base_tag {
    size_t refc;
    mutex_t lock;
    void *userdata;
37 38
    refobject_free_t freecb;
    char *name;
39
    refobject_t associated;
40 41
};

42
refobject_t     refobject_new(size_t len, refobject_free_t freecb, void *userdata, const char *name, refobject_t associated);
43 44 45 46
int             refobject_ref(refobject_t self);
int             refobject_unref(refobject_t self);
void *          refobject_get_userdata(refobject_t self);
int             refobject_set_userdata(refobject_t self, void *userdata);
47
const char *    refobject_get_name(refobject_t self);
48
refobject_t     refobject_get_associated(refobject_t self);
49 50

#endif