use librtti for worker/queue/resource
This commit is contained in:
parent
532c68e6e1
commit
2ee87d4ee6
23 changed files with 1078 additions and 396 deletions
114
src/lib/resobj.c
114
src/lib/resobj.c
|
|
@ -3,3 +3,117 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mylock.h"
|
||||
#include "resobj.h"
|
||||
#include "utils.h"
|
||||
#include "xstring.h"
|
||||
|
||||
typedef struct {
|
||||
mylock_t lock;
|
||||
uint64_t refcount;
|
||||
} resobj_private_t;
|
||||
|
||||
static size_t resobj_datasize(va_list ap)
|
||||
{
|
||||
size_t sz = sizeof(xce_resource_t);
|
||||
|
||||
return sz;
|
||||
}
|
||||
|
||||
static int resobj_init(meta_obj_t* obj, va_list ap)
|
||||
{
|
||||
xce_resource_t* dst = RTTI_OBJ_TO_DATA(xce_resource_t, obj);
|
||||
resobj_private_t* priv = (resobj_private_t*)RTTI_OBJ_TO_PRIV(obj);
|
||||
xce_resource_t* src = va_arg(ap, xce_resource_t*);
|
||||
|
||||
if (src == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memcpy(dst, src, sizeof(*dst));
|
||||
|
||||
dst->name = makeString(src->name);
|
||||
dst->desc = makeString(src->desc);
|
||||
|
||||
#if 0
|
||||
if (src->distributions != NULL) {
|
||||
MOVE_PTR(dst->distributions, src->distributions);
|
||||
}
|
||||
#else
|
||||
/* FIXME: */
|
||||
dst->distributions = NULL;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
MOVE_PTR(dst->hbased_defined, src->hbased_defined);
|
||||
#else
|
||||
/* FIXME: */
|
||||
dst->hbased_defined = NULL;
|
||||
#endif
|
||||
|
||||
mylock_init(&(priv->lock));
|
||||
priv->refcount = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void resobj_destroy(meta_obj_t* obj)
|
||||
{
|
||||
xce_resource_t* r = RTTI_OBJ_TO_DATA(xce_resource_t, obj);
|
||||
resobj_private_t* priv = (resobj_private_t*)RTTI_OBJ_TO_PRIV(obj);
|
||||
|
||||
dereference(r->name);
|
||||
dereference(r->desc);
|
||||
|
||||
mylock_fini(&(priv->lock));
|
||||
memset(priv, 0x0, sizeof(*priv));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int resobj_reference(meta_obj_t* obj)
|
||||
{
|
||||
resobj_private_t* priv = (resobj_private_t*)RTTI_OBJ_TO_PRIV(obj);
|
||||
|
||||
mylock_lock(&(priv->lock));
|
||||
priv->refcount++;
|
||||
mylock_unlock(&(priv->lock));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void resobj_dereference(meta_obj_t* obj)
|
||||
{
|
||||
resobj_private_t* priv = (resobj_private_t*)RTTI_OBJ_TO_PRIV(obj);
|
||||
xce_resource_t* w = RTTI_OBJ_TO_DATA(xce_resource_t, obj);
|
||||
uint64_t count = 0;
|
||||
|
||||
mylock_lock(&(priv->lock));
|
||||
priv->refcount--;
|
||||
count = priv->refcount;
|
||||
mylock_unlock(&(priv->lock));
|
||||
|
||||
if (count == 0) {
|
||||
destroy_(w, (obj_destroy_fn_t)resobj_destroy);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static typeinfo_t resobj_type
|
||||
= { .name = "xce resobj",
|
||||
.privateSize = sizeof(resobj_private_t),
|
||||
.dataSize = (datasize_fn_t)resobj_datasize,
|
||||
.init = (obj_init_fn_t)resobj_init,
|
||||
.destroy = NULL,
|
||||
.interfaces
|
||||
= { .reference = &(intf_reference_t) {
|
||||
.reference = (reference_fn_t)resobj_reference,
|
||||
.dereference = (dereference_fn_t)resobj_dereference } } };
|
||||
|
||||
xce_resource_t* makeResource(xce_resource_t* w)
|
||||
{
|
||||
xce_resource_t* resobj = makeInstance(&resobj_type, w);
|
||||
return resobj;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue