use stdatomic (#1317)

This commit is contained in:
云风
2021-01-11 10:54:34 +08:00
committed by GitHub
parent 284df5430b
commit b164e3a8a9
12 changed files with 201 additions and 138 deletions

View File

@@ -40,7 +40,7 @@ struct node {
struct state {
int dirty;
int ref;
ATOM_INT ref;
struct table * root;
};
@@ -383,7 +383,7 @@ convert_stringmap(struct context *ctx, struct table *tbl) {
lua_pushvalue(L, 1);
struct state * s = lua_newuserdatauv(L, sizeof(*s), 1);
s->dirty = 0;
s->ref = 0;
ATOM_INIT(&s->ref , 0);
s->root = tbl;
lua_replace(L, 1);
lua_replace(L, -2);
@@ -665,7 +665,7 @@ releaseobj(lua_State *L) {
struct ctrl *c = lua_touserdata(L, 1);
struct table *tbl = c->root;
struct state *s = lua_touserdata(tbl->L, 1);
ATOM_DEC(&s->ref);
ATOM_FDEC(&s->ref);
c->root = NULL;
c->update = NULL;
@@ -676,7 +676,7 @@ static int
lboxconf(lua_State *L) {
struct table * tbl = get_table(L,1);
struct state * s = lua_touserdata(tbl->L, 1);
ATOM_INC(&s->ref);
ATOM_FINC(&s->ref);
struct ctrl * c = lua_newuserdatauv(L, sizeof(*c), 1);
c->root = tbl;
@@ -712,7 +712,7 @@ static int
lgetref(lua_State *L) {
struct table *tbl = get_table(L,1);
struct state * s = lua_touserdata(tbl->L, 1);
lua_pushinteger(L , s->ref);
lua_pushinteger(L , ATOM_LOAD(&s->ref));
return 1;
}
@@ -721,7 +721,7 @@ static int
lincref(lua_State *L) {
struct table *tbl = get_table(L,1);
struct state * s = lua_touserdata(tbl->L, 1);
int ref = ATOM_INC(&s->ref);
int ref = ATOM_FINC(&s->ref)+1;
lua_pushinteger(L , ref);
return 1;
@@ -731,7 +731,7 @@ static int
ldecref(lua_State *L) {
struct table *tbl = get_table(L,1);
struct state * s = lua_touserdata(tbl->L, 1);
int ref = ATOM_DEC(&s->ref);
int ref = ATOM_FDEC(&s->ref)-1;
lua_pushinteger(L , ref);
return 1;