我基于 gcc 的原子内置函数开发了一个可重入函数。不幸的是,我收到关于“计算但未使用”值的神秘警告:
$ gcc -c -Wall ss.c
ss.c: In function ‘ss_wrapper’:
ss.c:87:3: warning: value computed is not used [-Wunused-value]
__atomic_exchange_n(&ss_top, hit, __ATOMIC_SEQ_CST);
^
ss.c:91:5: warning: value computed is not used [-Wunused-value]
__atomic_exchange_n(&ss_top, bkp->next, __ATOMIC_SEQ_CST); // release the lock, find out if there is new element
^
这是我的功能:
static void ss_wrapper(int signum, siginfo_t* siginfo, void *ucontext) {
// currently top element on the signal stack
static struct ss_hit* ss_top = NULL;
struct ss_hit* hit = ss_newhit(signum, siginfo, (ucontext_t*)ucontext);
struct ss_hit* bkp;
again:
bkp = hit;
__atomic_exchange_n(&ss_top, hit, __ATOMIC_SEQ_CST);
if (!hit) { // we got the lock, we are the master
ss_fire(bkp);
// release the lock, find out if there is new element
__atomic_exchange_n(&ss_top, bkp->next, __ATOMIC_SEQ_CST);
if (bkp->next) { // there IS
hit = bkp;
free(bkp);
goto again;
} else
free(bkp);
} else { // we didn't got the lock, but we got the top in hit
__atomic_store(&hit->next, &bkp, __ATOMIC_SEQ_CST);
}
}
为什么会这样?__atomic_exchange_n
不应该计算任何东西,它只交换两个变量的内容。