mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-12-04 14:46:30 -05:00
Feature: Make refobject more general useful
This commit is contained in:
parent
a9d391ffbc
commit
7cba708a50
@ -22,7 +22,7 @@
|
||||
#define TO_BASE(x) ((refobject_base_t*)(x))
|
||||
#endif
|
||||
|
||||
refobject_t refobject_new(size_t len, refobject_free freecb, void *userdata)
|
||||
refobject_t refobject_new(size_t len, refobject_free_t freecb, void *userdata, const char *name, refobject_t parent)
|
||||
{
|
||||
refobject_base_t *ret = NULL;
|
||||
|
||||
@ -39,6 +39,23 @@ refobject_t refobject_new(size_t len, refobject_free freecb, void *userdata)
|
||||
|
||||
thread_mutex_create(&(ret->lock));
|
||||
|
||||
if (name) {
|
||||
ret->name = strdup(name);
|
||||
if (!ret->name) {
|
||||
refobject_unref(ret);
|
||||
return (refobject_t)(refobject_base_t*)NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (TO_BASE(parent) != NULL) {
|
||||
if (refobject_ref(parent) != 0) {
|
||||
refobject_unref(ret);
|
||||
return (refobject_t)(refobject_base_t*)NULL;
|
||||
}
|
||||
|
||||
ret->parent = parent;
|
||||
}
|
||||
|
||||
return (refobject_t)ret;
|
||||
}
|
||||
|
||||
@ -74,6 +91,9 @@ int refobject_unref(refobject_t self)
|
||||
if (base->userdata)
|
||||
free(base->userdata);
|
||||
|
||||
if (base->name)
|
||||
free(base->name);
|
||||
|
||||
thread_mutex_unlock(&(base->lock));
|
||||
thread_mutex_destroy(&(base->lock));
|
||||
|
||||
@ -105,3 +125,31 @@ int refobject_set_userdata(refobject_t self, void *userdata)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * refobject_get_name(refobject_t self)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
if (TO_BASE(self) == NULL)
|
||||
return NULL;
|
||||
|
||||
thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
ret = TO_BASE(self)->name;
|
||||
thread_mutex_unlock(&(TO_BASE(self)->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
refobject_t refobject_get_parent(refobject_t self)
|
||||
{
|
||||
refobject_t ret;
|
||||
|
||||
if (TO_BASE(self) == NULL)
|
||||
return (refobject_t)(refobject_base_t*)NULL;
|
||||
|
||||
thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
ret = TO_BASE(self)->parent;
|
||||
thread_mutex_unlock(&(TO_BASE(self)->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -14,19 +14,23 @@
|
||||
#include "icecasttypes.h"
|
||||
#include "compat.h"
|
||||
|
||||
typedef void (*refobject_free)(refobject_t self, void **userdata);
|
||||
typedef void (*refobject_free_t)(refobject_t self, void **userdata);
|
||||
|
||||
struct refobject_base_tag {
|
||||
size_t refc;
|
||||
mutex_t lock;
|
||||
void *userdata;
|
||||
refobject_free freecb;
|
||||
refobject_free_t freecb;
|
||||
char *name;
|
||||
refobject_t parent;
|
||||
};
|
||||
|
||||
refobject_t refobject_new(size_t len, refobject_free freecb, void *userdata);
|
||||
refobject_t refobject_new(size_t len, refobject_free_t freecb, void *userdata, const char *name, refobject_t parent);
|
||||
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);
|
||||
const char * refobject_get_name(refobject_t self);
|
||||
refobject_t refobject_get_parent(refobject_t self);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user