save works
This commit is contained in:
parent
acfbec875b
commit
3f74f14687
38 changed files with 751 additions and 448 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include <errno.h>
|
||||
#include <rtti.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
@ -16,10 +17,9 @@ static struct {
|
|||
} xstring_table;
|
||||
|
||||
typedef struct {
|
||||
mylock_t lock;
|
||||
uint64_t refcount;
|
||||
uint32_t hashcode;
|
||||
size_t len;
|
||||
atomic_ulong refcount;
|
||||
uint32_t hashcode;
|
||||
size_t len;
|
||||
} xstring_private_t;
|
||||
|
||||
static typeinfo_t xstring_type;
|
||||
|
|
@ -78,7 +78,6 @@ static int xstring_init(meta_obj_t* obj, va_list ap)
|
|||
|
||||
strcpy(dest, src);
|
||||
|
||||
mylock_init(&(priv->lock));
|
||||
priv->refcount = 1;
|
||||
priv->hashcode = hash_string(src);
|
||||
priv->len = strlen(src);
|
||||
|
|
@ -90,7 +89,6 @@ static void xstring_destroy(meta_obj_t* obj)
|
|||
{
|
||||
xstring_private_t* priv = (xstring_private_t*)RTTI_OBJ_TO_PRIV(obj);
|
||||
|
||||
mylock_fini(&(priv->lock));
|
||||
memset(priv, 0x0, sizeof(*priv));
|
||||
|
||||
return;
|
||||
|
|
@ -100,9 +98,7 @@ static int xstring_reference(meta_obj_t* obj)
|
|||
{
|
||||
xstring_private_t* priv = (xstring_private_t*)RTTI_OBJ_TO_PRIV(obj);
|
||||
|
||||
mylock_lock(&(priv->lock));
|
||||
priv->refcount++;
|
||||
mylock_unlock(&(priv->lock));
|
||||
atomic_fetch_add(&(priv->refcount), 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -113,13 +109,9 @@ static void xstring_dereference(meta_obj_t* obj)
|
|||
char* v = RTTI_OBJ_TO_DATA(char, obj);
|
||||
uint64_t count;
|
||||
|
||||
mylock_lock(&(priv->lock));
|
||||
priv->refcount--;
|
||||
count = atomic_fetch_sub(&(priv->refcount), 1);
|
||||
|
||||
count = priv->refcount;
|
||||
mylock_unlock(&(priv->lock));
|
||||
|
||||
if (count == 0) {
|
||||
if (count == 1) {
|
||||
mylock_lock(&(xstring_table.lock));
|
||||
key_del(xstring_table.xstr_table, v);
|
||||
mylock_unlock(&(xstring_table.lock));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue