CAS expected should not be _Atomic type, #1317

This commit is contained in:
Cloud Wu
2021-01-11 17:10:26 +08:00
parent 1ed4fdf94d
commit bc2fba560f
3 changed files with 6 additions and 9 deletions

View File

@@ -521,15 +521,13 @@ snlua_signal(struct snlua *l, int signal) {
skynet_error(l->ctx, "recv a signal %d", signal);
if (signal == 0) {
if (ATOM_LOAD(&l->trap) == 0) {
ATOM_INT zero;
ATOM_INIT(&zero, 0);
int zero = 0;
// only one thread can set trap ( l->trap 0->1 )
if (!ATOM_CAS(&l->trap, zero, 1))
return;
ATOM_INT one;
ATOM_INIT(&one, 1);
lua_sethook (l->activeL, signal_hook, LUA_MASKCOUNT, 1);
// finish set ( l->trap 1 -> -1 )
int one = 1;
ATOM_CAS(&l->trap, one, -1);
}
} else if (signal == 1) {

View File

@@ -31,8 +31,7 @@ rwlock_rlock(struct rwlock *lock) {
static inline void
rwlock_wlock(struct rwlock *lock) {
ATOM_INT clear;
ATOM_INIT(&clear, 0);
int clear = 0;
while (!ATOM_CAS(&lock->write,clear,1)) {}
while(ATOM_LOAD(&lock->read)) {}
}

View File

@@ -595,8 +595,7 @@ cmd_logon(struct skynet_context * context, const char * param) {
if (lastf == NULL) {
f = skynet_log_open(context, handle);
if (f) {
ATOM_POINTER exp;
ATOM_INIT(&exp, 0);
uintptr_t exp = 0;
if (!ATOM_CAS_POINTER(&ctx->logfile, exp, f)) {
// logfile opens in other thread, close this one.
fclose(f);
@@ -618,7 +617,8 @@ cmd_logoff(struct skynet_context * context, const char * param) {
FILE * f = ATOM_LOAD(&ctx->logfile);
if (f) {
// logfile may close in other thread
if (ATOM_CAS_POINTER(&ctx->logfile, f, NULL)) {
uintptr_t fptr = (uintptr_t)f;
if (ATOM_CAS_POINTER(&ctx->logfile, fptr, NULL)) {
skynet_log_close(context, f, handle);
}
}