save works

This commit is contained in:
Rongsong Shen 2026-03-04 18:18:53 +08:00
parent acfbec875b
commit 3f74f14687
38 changed files with 751 additions and 448 deletions

View file

@ -1,6 +1,7 @@
#include <errno.h>
#include <rtti.h>
#include <stdarg.h>
#include <stdatomic.h>
#include <stdlib.h>
#include <string.h>
@ -10,8 +11,8 @@
#include "xstring.h"
typedef struct {
my_rwlock_t lock;
uint64_t refcount;
my_rwlock_t lock;
atomic_ulong refcount;
} queue_private_t;
static size_t queue_datasize(va_list ap)
@ -42,6 +43,7 @@ static int queue_init(meta_obj_t* obj, va_list ap)
MOVE_PTR(dst->queue.hosts, src->hosts);
dst->queue.nthresholds = src->nthresholds;
MOVE_PTR(dst->queue.thresholds, src->thresholds);
src->nthresholds = 0;
MOVE_PTR(dst->queue.runwindow, src->runwindow);
MOVE_PTR(dst->queue.dispatchwindow, src->dispatchwindow);
@ -95,9 +97,7 @@ static int queue_reference(meta_obj_t* obj)
{
queue_private_t* priv = (queue_private_t*)RTTI_OBJ_TO_PRIV(obj);
my_rwlock_wlock(&(priv->lock));
priv->refcount++;
my_rwlock_unlock(&(priv->lock));
atomic_fetch_add(&(priv->refcount), 1);
return 1;
}
@ -108,12 +108,9 @@ static void queue_dereference(meta_obj_t* obj)
queue_t* w = RTTI_OBJ_TO_DATA(queue_t, obj);
uint64_t count = 0;
my_rwlock_wlock(&(priv->lock));
priv->refcount--;
count = priv->refcount;
my_rwlock_unlock(&(priv->lock));
count = atomic_fetch_sub(&(priv->refcount), 1);
if (count == 0) {
if (count == 1) {
destroy_(w, (obj_destroy_fn_t)queue_destroy);
}
@ -163,12 +160,13 @@ static typeinfo_t queue_type = {
.unlock = (unlock_fn_t)queue_unlock } }
};
queue_t* makeQueue(var qmgr, xce_queue_t* q)
static queue_t* makeQueue_(var qmgr, xce_queue_t* q)
{
queue_t* queue = NULL;
int rc = 0;
rc = key_find(qmgr, (void*)q->queue, (void**)&queue);
if ((rc < 0) && (rc != -ENOENT)) {
errno = -rc;
return NULL;
@ -181,8 +179,8 @@ queue_t* makeQueue(var qmgr, xce_queue_t* q)
queue = makeInstance(&queue_type, q);
if (queue != NULL) {
reference(queue);
rc = key_add(qmgr, (void*)q->queue, (void*)queue);
if (rc < 0) {
destroy(queue);
@ -193,3 +191,17 @@ queue_t* makeQueue(var qmgr, xce_queue_t* q)
return queue;
}
queue_t* makeQueue(var qmgr, xce_queue_t* q)
{
queue_t* queue = NULL;
int rc;
lock(qmgr, RTTI_LOCK_WRITE);
queue = makeQueue_(qmgr, q);
rc = errno;
unlock(qmgr);
errno = rc;
return queue;
}