mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-12-04 14:46:30 -05:00
Feature: Added some useful macros to refobject API
This commit is contained in:
parent
ac372a2edc
commit
4e1dc94c50
@ -17,11 +17,7 @@
|
||||
|
||||
#include "refobject.h"
|
||||
|
||||
#ifdef HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
|
||||
#define TO_BASE(x) ((x).refobject_base)
|
||||
#else
|
||||
#define TO_BASE(x) ((refobject_base_t*)(x))
|
||||
#endif
|
||||
#define TO_BASE(x) REFOBJECT_TO_TYPE((x), refobject_base_t *)
|
||||
|
||||
refobject_t refobject_new(size_t len, refobject_free_t freecb, void *userdata, const char *name, refobject_t parent)
|
||||
{
|
||||
@ -44,14 +40,14 @@ refobject_t refobject_new(size_t len, refobject_free_t freecb, void *userdat
|
||||
ret->name = strdup(name);
|
||||
if (!ret->name) {
|
||||
refobject_unref(ret);
|
||||
return (refobject_t)(refobject_base_t*)NULL;
|
||||
return REFOBJECT_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (TO_BASE(parent) != NULL) {
|
||||
if (!REFOBJECT_IS_NULL(parent)) {
|
||||
if (refobject_ref(parent) != 0) {
|
||||
refobject_unref(ret);
|
||||
return (refobject_t)(refobject_base_t*)NULL;
|
||||
return REFOBJECT_NULL;
|
||||
}
|
||||
|
||||
ret->parent = parent;
|
||||
@ -62,7 +58,7 @@ refobject_t refobject_new(size_t len, refobject_free_t freecb, void *userdat
|
||||
|
||||
int refobject_ref(refobject_t self)
|
||||
{
|
||||
if (TO_BASE(self) == NULL)
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return -1;
|
||||
|
||||
thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
@ -76,7 +72,7 @@ int refobject_unref(refobject_t self)
|
||||
{
|
||||
register refobject_base_t *base = TO_BASE(self);
|
||||
|
||||
if (base == NULL)
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return -1;
|
||||
|
||||
thread_mutex_lock(&(base->lock));
|
||||
@ -107,7 +103,7 @@ void * refobject_get_userdata(refobject_t self)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
if (TO_BASE(self) == NULL)
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return NULL;
|
||||
|
||||
thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
@ -119,7 +115,7 @@ void * refobject_get_userdata(refobject_t self)
|
||||
|
||||
int refobject_set_userdata(refobject_t self, void *userdata)
|
||||
{
|
||||
if (TO_BASE(self) == NULL)
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return -1;
|
||||
|
||||
thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
@ -133,7 +129,7 @@ const char * refobject_get_name(refobject_t self)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
if (TO_BASE(self) == NULL)
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return NULL;
|
||||
|
||||
thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
@ -147,8 +143,8 @@ refobject_t refobject_get_parent(refobject_t self)
|
||||
{
|
||||
refobject_t ret;
|
||||
|
||||
if (TO_BASE(self) == NULL)
|
||||
return (refobject_t)(refobject_base_t*)NULL;
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return REFOBJECT_NULL;
|
||||
|
||||
thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
ret = TO_BASE(self)->parent;
|
||||
|
@ -9,11 +9,25 @@
|
||||
#ifndef __REFOBJECT_H__
|
||||
#define __REFOBJECT_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "common/thread/thread.h"
|
||||
|
||||
#include "icecasttypes.h"
|
||||
#include "compat.h"
|
||||
|
||||
#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
|
||||
|
||||
typedef void (*refobject_free_t)(refobject_t self, void **userdata);
|
||||
|
||||
struct refobject_base_tag {
|
||||
|
Loading…
Reference in New Issue
Block a user