From bc2fba560f4a8ca48d13992905315120a86450cb Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Mon, 11 Jan 2021 17:10:26 +0800 Subject: [PATCH] CAS expected should not be _Atomic type, #1317 --- service-src/service_snlua.c | 6 ++---- skynet-src/rwlock.h | 3 +-- skynet-src/skynet_server.c | 6 +++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/service-src/service_snlua.c b/service-src/service_snlua.c index 72c2f954..81a1604a 100644 --- a/service-src/service_snlua.c +++ b/service-src/service_snlua.c @@ -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) { diff --git a/skynet-src/rwlock.h b/skynet-src/rwlock.h index 56feebf7..28a49c24 100644 --- a/skynet-src/rwlock.h +++ b/skynet-src/rwlock.h @@ -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)) {} } diff --git a/skynet-src/skynet_server.c b/skynet-src/skynet_server.c index d0cc3fdd..d776cea8 100644 --- a/skynet-src/skynet_server.c +++ b/skynet-src/skynet_server.c @@ -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); } }