projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
drop use of pthread_once for aio thread stack size init
[musl]
/
src
/
thread
/
pthread_cond_timedwait.c
diff --git
a/src/thread/pthread_cond_timedwait.c
b/src/thread/pthread_cond_timedwait.c
index
f5fd08c
..
6b76145
100644
(file)
--- a/
src/thread/pthread_cond_timedwait.c
+++ b/
src/thread/pthread_cond_timedwait.c
@@
-1,10
+1,5
@@
#include "pthread_impl.h"
#include "pthread_impl.h"
-void __pthread_testcancel(void);
-int __pthread_mutex_lock(pthread_mutex_t *);
-int __pthread_mutex_unlock(pthread_mutex_t *);
-int __pthread_setcancelstate(int, int *);
-
/*
* struct waiter
*
/*
* struct waiter
*
@@
-29,8
+24,8
@@
int __pthread_setcancelstate(int, int *);
struct waiter {
struct waiter *prev, *next;
struct waiter {
struct waiter *prev, *next;
- int state, barrier;
- int *notify;
+
volatile
int state, barrier;
+
volatile
int *notify;
};
/* Self-synchronized-destruction-safe lock functions */
};
/* Self-synchronized-destruction-safe lock functions */
@@
-54,7
+49,7
@@
static inline void unlock_requeue(volatile int *l, volatile int *r, int w)
{
a_store(l, 0);
if (w) __wake(l, 1, 1);
{
a_store(l, 0);
if (w) __wake(l, 1, 1);
- else __syscall(SYS_futex, l, FUTEX_REQUEUE|
128
, 0, 1, r) != -ENOSYS
+ else __syscall(SYS_futex, l, FUTEX_REQUEUE|
FUTEX_PRIVATE
, 0, 1, r) != -ENOSYS
|| __syscall(SYS_futex, l, FUTEX_REQUEUE, 0, 1, r);
}
|| __syscall(SYS_futex, l, FUTEX_REQUEUE, 0, 1, r);
}
@@
-67,7
+62,8
@@
enum {
int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts)
{
struct waiter node = { 0 };
int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts)
{
struct waiter node = { 0 };
- int e, seq, *fut, clock = c->_c_clock, cs, shared=0, oldstate, tmp;
+ int e, seq, clock = c->_c_clock, cs, shared=0, oldstate, tmp;
+ volatile int *fut;
if ((m->_m_type&15) && (m->_m_lock&INT_MAX) != __pthread_self()->tid)
return EPERM;
if ((m->_m_type&15) && (m->_m_lock&INT_MAX) != __pthread_self()->tid)
return EPERM;
@@
-99,6
+95,7
@@
int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restri
__pthread_mutex_unlock(m);
__pthread_setcancelstate(PTHREAD_CANCEL_MASKED, &cs);
__pthread_mutex_unlock(m);
__pthread_setcancelstate(PTHREAD_CANCEL_MASKED, &cs);
+ if (cs == PTHREAD_CANCEL_DISABLE) __pthread_setcancelstate(cs, 0);
do e = __timedwait_cp(fut, seq, clock, ts, !shared);
while (*fut==seq && (!e || e==EINTR));
do e = __timedwait_cp(fut, seq, clock, ts, !shared);
while (*fut==seq && (!e || e==EINTR));
@@
-149,14
+146,18
@@
relock:
if (oldstate == WAITING) goto done;
if (oldstate == WAITING) goto done;
- if (!node.next) a_inc(&m->_m_waiters);
+ if (!node.next && !(m->_m_type & 8))
+ a_inc(&m->_m_waiters);
/* Unlock the barrier that's holding back the next waiter, and
* either wake it or requeue it to the mutex. */
/* Unlock the barrier that's holding back the next waiter, and
* either wake it or requeue it to the mutex. */
- if (node.prev)
- unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & 128);
- else
- a_dec(&m->_m_waiters);
+ if (node.prev) {
+ int val = m->_m_lock;
+ if (val>0) a_cas(&m->_m_lock, val, val|0x80000000);
+ unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & (8|128));
+ } else if (!(m->_m_type & 8)) {
+ a_dec(&m->_m_waiters);
+ }
/* Since a signal was consumed, cancellation is not permitted. */
if (e == ECANCELED) e = 0;
/* Since a signal was consumed, cancellation is not permitted. */
if (e == ECANCELED) e = 0;
@@
-175,7
+176,8
@@
done:
int __private_cond_signal(pthread_cond_t *c, int n)
{
struct waiter *p, *first=0;
int __private_cond_signal(pthread_cond_t *c, int n)
{
struct waiter *p, *first=0;
- int ref = 0, cur;
+ volatile int ref = 0;
+ int cur;
lock(&c->_c_lock);
for (p=c->_c_tail; n && p; p=p->prev) {
lock(&c->_c_lock);
for (p=c->_c_tail; n && p; p=p->prev) {