提交 e983aea0 编写于 作者: R Rich Felker

change sem_trywait algorithm so it never has to call __wake

上级 ec2e50d0
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
int sem_trywait(sem_t *sem) int sem_trywait(sem_t *sem)
{ {
if (a_fetch_add(sem->__val, -1) > 0) return 0; int val = sem->__val[0];
if (!a_fetch_add(sem->__val, 1) && sem->__val[1]) if (val>0 && a_cas(sem->__val, val, val-1)==val) return 0;
__wake(sem->__val, 1, 0);
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册