diff options
Diffstat (limited to 'src')
24 files changed, 102 insertions, 83 deletions
diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index e481ab5a..615af708 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -38,6 +38,25 @@ struct pthread { pthread_attr_t attr; }; +#define __SU (sizeof(size_t)/sizeof(int)) + +#define _a_stacksize __u.__s[0] +#define _a_guardsize __u.__s[1] +#define _a_detach __u.__i[2*__SU+0] +#define _m_type __u.__i[0] +#define _m_lock __u.__i[1] +#define _m_waiters __u.__i[2] +#define _m_owner __u.__i[3] +#define _c_block __u.__i[0] +#define _rw_wrlock __u.__i[0] +#define _rw_readers __u.__i[1] +#define _rw_waiters __u.__i[2] +#define _rw_owner __u.__i[3] +#define _b_count __u.__i[0] +#define _b_limit __u.__i[1] +#define _b_left __u.__i[2] +#define _b_waiters __u.__i[3] + #include "pthread_arch.h" #define SIGCANCEL 32 diff --git a/src/thread/pthread_attr_getdetachstate.c b/src/thread/pthread_attr_getdetachstate.c index 9cd49536..de65c25f 100644 --- a/src/thread/pthread_attr_getdetachstate.c +++ b/src/thread/pthread_attr_getdetachstate.c @@ -2,6 +2,6 @@ int pthread_attr_getdetachstate(pthread_attr_t *a, int *state) { - *state = a->__detach; + *state = a->_a_detach; return 0; } diff --git a/src/thread/pthread_attr_getguardsize.c b/src/thread/pthread_attr_getguardsize.c index 3f089c8c..e6b9ee2a 100644 --- a/src/thread/pthread_attr_getguardsize.c +++ b/src/thread/pthread_attr_getguardsize.c @@ -2,6 +2,6 @@ int pthread_attr_getguardsize(pthread_attr_t *a, size_t *size) { - *size = a->__guardsize + DEFAULT_GUARD_SIZE; + *size = a->_a_guardsize + DEFAULT_GUARD_SIZE; return 0; } diff --git a/src/thread/pthread_attr_getstacksize.c b/src/thread/pthread_attr_getstacksize.c index 40bbf186..900dc9f5 100644 --- a/src/thread/pthread_attr_getstacksize.c +++ b/src/thread/pthread_attr_getstacksize.c @@ -2,6 +2,6 @@ int pthread_attr_getstacksize(pthread_attr_t *a, size_t *size) { - *size = a->__stacksize + DEFAULT_STACK_SIZE; + *size = a->_a_stacksize + DEFAULT_STACK_SIZE; return 0; } diff --git a/src/thread/pthread_attr_setdetachstate.c b/src/thread/pthread_attr_setdetachstate.c index d23b4778..bfffba8c 100644 --- a/src/thread/pthread_attr_setdetachstate.c +++ b/src/thread/pthread_attr_setdetachstate.c @@ -2,6 +2,6 @@ int pthread_attr_setdetachstate(pthread_attr_t *a, int state) { - a->__detach = state; + a->_a_detach = state; return 0; } diff --git a/src/thread/pthread_attr_setguardsize.c b/src/thread/pthread_attr_setguardsize.c index e0e8d3fb..9f21d247 100644 --- a/src/thread/pthread_attr_setguardsize.c +++ b/src/thread/pthread_attr_setguardsize.c @@ -3,6 +3,6 @@ int pthread_attr_setguardsize(pthread_attr_t *a, size_t size) { if (size > SIZE_MAX/8) return EINVAL; - a->__guardsize = size - DEFAULT_GUARD_SIZE; + a->_a_guardsize = size - DEFAULT_GUARD_SIZE; return 0; } diff --git a/src/thread/pthread_attr_setstacksize.c b/src/thread/pthread_attr_setstacksize.c index 58f4bb18..df16b980 100644 --- a/src/thread/pthread_attr_setstacksize.c +++ b/src/thread/pthread_attr_setstacksize.c @@ -3,6 +3,6 @@ int pthread_attr_setstacksize(pthread_attr_t *a, size_t size) { if (size-PAGE_SIZE > SIZE_MAX/4) return EINVAL; - a->__stacksize = size - DEFAULT_STACK_SIZE; + a->_a_stacksize = size - DEFAULT_STACK_SIZE; return 0; } diff --git a/src/thread/pthread_barrier_init.c b/src/thread/pthread_barrier_init.c index 2cc67ed5..736d1014 100644 --- a/src/thread/pthread_barrier_init.c +++ b/src/thread/pthread_barrier_init.c @@ -3,6 +3,6 @@ int pthread_barrier_init(pthread_barrier_t *b, const pthread_barrierattr_t *a, unsigned count) { if (!count) return EINVAL; - *b = (pthread_barrier_t){ .__limit = count-1 }; + *b = (pthread_barrier_t){ ._b_limit = count-1 }; return 0; } diff --git a/src/thread/pthread_barrier_wait.c b/src/thread/pthread_barrier_wait.c index 02c252ad..7bfadb95 100644 --- a/src/thread/pthread_barrier_wait.c +++ b/src/thread/pthread_barrier_wait.c @@ -5,27 +5,27 @@ int pthread_barrier_wait(pthread_barrier_t *b) int cur; /* Trivial case: count was set at 1 */ - if (!b->__limit) return PTHREAD_BARRIER_SERIAL_THREAD; + if (!b->_b_limit) return PTHREAD_BARRIER_SERIAL_THREAD; /* Wait for anyone still suspended at previous use of barrier */ - while ((cur=b->__left)) - __wait(&b->__left, &b->__waiters, cur, 0); + while ((cur=b->_b_left)) + __wait(&b->_b_left, &b->_b_waiters, cur, 0); /* If we are the last to reach barrier, reset it and wake others */ - if (a_fetch_add(&b->__count, 1) == b->__limit) { - b->__left = b->__limit; - b->__count = 0; - __wake(&b->__count, -1, 0); + if (a_fetch_add(&b->_b_count, 1) == b->_b_limit) { + b->_b_left = b->_b_limit; + b->_b_count = 0; + __wake(&b->_b_count, -1, 0); return PTHREAD_BARRIER_SERIAL_THREAD; } /* Wait for our peers to reach the barrier */ - while ((cur=b->__count)) - __wait(&b->__count, 0, cur, 0); + while ((cur=b->_b_count)) + __wait(&b->_b_count, 0, cur, 0); /* If we're the last to wake up and barrier is awaiting reuse */ - if (a_fetch_add(&b->__left, -1) == 1 && b->__waiters) - __wake(&b->__left, -1, 0); + if (a_fetch_add(&b->_b_left, -1) == 1 && b->_b_waiters) + __wake(&b->_b_left, -1, 0); return 0; } diff --git a/src/thread/pthread_cond_broadcast.c b/src/thread/pthread_cond_broadcast.c index 7a023b85..1d378c0b 100644 --- a/src/thread/pthread_cond_broadcast.c +++ b/src/thread/pthread_cond_broadcast.c @@ -2,7 +2,7 @@ int pthread_cond_broadcast(pthread_cond_t *c) { - c->__block = 0; - __wake(&c->__block, -1, 0); + c->_c_block = 0; + __wake(&c->_c_block, -1, 0); return 0; } diff --git a/src/thread/pthread_cond_signal.c b/src/thread/pthread_cond_signal.c index 0dd9416b..574f5c79 100644 --- a/src/thread/pthread_cond_signal.c +++ b/src/thread/pthread_cond_signal.c @@ -2,7 +2,7 @@ int pthread_cond_signal(pthread_cond_t *c) { - c->__block = 0; - __wake(&c->__block, 1, 0); + c->_c_block = 0; + __wake(&c->_c_block, 1, 0); return 0; } diff --git a/src/thread/pthread_cond_timedwait.c b/src/thread/pthread_cond_timedwait.c index b67dded4..b0214b40 100644 --- a/src/thread/pthread_cond_timedwait.c +++ b/src/thread/pthread_cond_timedwait.c @@ -11,11 +11,11 @@ int pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, const struct t CANCELPT(0); pthread_cleanup_push(relock, m); - c->__block = 1; + c->_c_block = 1; if ((r=pthread_mutex_unlock(m))) return r; CANCELPT(1); - e = __timedwait(&c->__block, 1, CLOCK_REALTIME, ts, 0); + e = __timedwait(&c->_c_block, 1, CLOCK_REALTIME, ts, 0); CANCELPT(0); pthread_cleanup_pop(0); diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index af6ccf07..b6c475d0 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -173,8 +173,8 @@ int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(vo if (!init && ++init) init_threads(); if (!attr) attr = &default_attr; - guard = ROUND(attr->__guardsize + DEFAULT_GUARD_SIZE); - size = guard + ROUND(attr->__stacksize + DEFAULT_STACK_SIZE); + guard = ROUND(attr->_a_guardsize + DEFAULT_GUARD_SIZE); + size = guard + ROUND(attr->_a_stacksize + DEFAULT_STACK_SIZE); size += __pthread_tsd_size; map = mmap(0, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0); if (!map) return EAGAIN; @@ -190,7 +190,7 @@ int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(vo new->start_arg = arg; new->self = new; new->tsd = (void *)tsd; - new->detached = attr->__detach; + new->detached = attr->_a_detach; new->attr = *attr; memcpy(new->tlsdesc, self->tlsdesc, sizeof new->tlsdesc); new->tlsdesc[1] = (uintptr_t)new; diff --git a/src/thread/pthread_mutex_lock.c b/src/thread/pthread_mutex_lock.c index 6696f17a..15ede3f5 100644 --- a/src/thread/pthread_mutex_lock.c +++ b/src/thread/pthread_mutex_lock.c @@ -4,6 +4,6 @@ int pthread_mutex_lock(pthread_mutex_t *m) { int r; while ((r=pthread_mutex_trylock(m)) == EBUSY) - __wait(&m->__lock, &m->__waiters, 1, 0); + __wait(&m->_m_lock, &m->_m_waiters, 1, 0); return r; } diff --git a/src/thread/pthread_mutex_timedlock.c b/src/thread/pthread_mutex_timedlock.c index 5dfad94f..20ce0128 100644 --- a/src/thread/pthread_mutex_timedlock.c +++ b/src/thread/pthread_mutex_timedlock.c @@ -4,12 +4,12 @@ int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *at) { int r, w=0; while ((r=pthread_mutex_trylock(m)) == EBUSY) { - if (!w) a_inc(&m->__waiters), w++; - if (__timedwait(&m->__lock, 1, CLOCK_REALTIME, at, 0) == ETIMEDOUT) { - if (w) a_dec(&m->__waiters); + if (!w) a_inc(&m->_m_waiters), w++; + if (__timedwait(&m->_m_lock, 1, CLOCK_REALTIME, at, 0) == ETIMEDOUT) { + if (w) a_dec(&m->_m_waiters); return ETIMEDOUT; } } - if (w) a_dec(&m->__waiters); + if (w) a_dec(&m->_m_waiters); return r; } diff --git a/src/thread/pthread_mutex_trylock.c b/src/thread/pthread_mutex_trylock.c index 1e3817bb..29268fdb 100644 --- a/src/thread/pthread_mutex_trylock.c +++ b/src/thread/pthread_mutex_trylock.c @@ -2,27 +2,27 @@ int pthread_mutex_trylock(pthread_mutex_t *m) { - if (m->__type == PTHREAD_MUTEX_RECURSIVE) { + if (m->_m_type == PTHREAD_MUTEX_RECURSIVE) { pthread_t self = pthread_self(); - if (m->__owner == self) { - if ((unsigned)m->__lock >= INT_MAX) return EAGAIN; - a_inc(&m->__lock); + if (m->_m_owner == self->tid) { + if ((unsigned)m->_m_lock >= INT_MAX) return EAGAIN; + a_inc(&m->_m_lock); return 0; } - if (a_fetch_add(&m->__lock, 1)) { - if (a_fetch_add(&m->__lock, -1)==1 && m->__waiters) - __wake(&m->__lock, 1, 0); + if (a_fetch_add(&m->_m_lock, 1)) { + if (a_fetch_add(&m->_m_lock, -1)==1 && m->_m_waiters) + __wake(&m->_m_lock, 1, 0); return EBUSY; } - m->__owner = self; + m->_m_owner = self->tid; return 0; } - if (a_xchg(&m->__lock, 1)) - if (m->__type == PTHREAD_MUTEX_ERRORCHECK - && m->__owner == pthread_self()) return EDEADLK; + if (a_xchg(&m->_m_lock, 1)) + if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK + && m->_m_owner == pthread_self()->tid) return EDEADLK; else return EBUSY; - if (m->__type == PTHREAD_MUTEX_ERRORCHECK) - m->__owner = pthread_self(); + if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK) + m->_m_owner = pthread_self()->tid; return 0; } diff --git a/src/thread/pthread_mutex_unlock.c b/src/thread/pthread_mutex_unlock.c index 23e64ac8..0275eb52 100644 --- a/src/thread/pthread_mutex_unlock.c +++ b/src/thread/pthread_mutex_unlock.c @@ -2,18 +2,18 @@ int pthread_mutex_unlock(pthread_mutex_t *m) { - if (m->__type == PTHREAD_MUTEX_RECURSIVE) { - if (a_fetch_add(&m->__lock, -1)==1 && m->__waiters) - __wake(&m->__lock, 1, 0); + if (m->_m_type == PTHREAD_MUTEX_RECURSIVE) { + if (a_fetch_add(&m->_m_lock, -1)==1 && m->_m_waiters) + __wake(&m->_m_lock, 1, 0); return 0; } - if (m->__type == PTHREAD_MUTEX_ERRORCHECK - && m->__owner != pthread_self()) + if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK + && m->_m_owner != pthread_self()->tid) return EPERM; - m->__owner = 0; - m->__lock = 0; - if (m->__waiters) __wake(&m->__lock, 1, 0); + m->_m_owner = 0; + m->_m_lock = 0; + if (m->_m_waiters) __wake(&m->_m_lock, 1, 0); return 0; } diff --git a/src/thread/pthread_rwlock_rdlock.c b/src/thread/pthread_rwlock_rdlock.c index 6bcdb815..29863507 100644 --- a/src/thread/pthread_rwlock_rdlock.c +++ b/src/thread/pthread_rwlock_rdlock.c @@ -3,6 +3,6 @@ int pthread_rwlock_rdlock(pthread_rwlock_t *rw) { while (pthread_rwlock_tryrdlock(rw)) - __wait(&rw->__wrlock, &rw->__waiters, 1, 0); + __wait(&rw->_rw_wrlock, &rw->_rw_waiters, 1, 0); return 0; } diff --git a/src/thread/pthread_rwlock_timedrdlock.c b/src/thread/pthread_rwlock_timedrdlock.c index 290327de..1e76a8e1 100644 --- a/src/thread/pthread_rwlock_timedrdlock.c +++ b/src/thread/pthread_rwlock_timedrdlock.c @@ -4,12 +4,12 @@ int pthread_rwlock_timedrdlock(pthread_rwlock_t *rw, const struct timespec *at) { int w=0; while (pthread_rwlock_tryrdlock(rw)) { - if (!w) a_inc(&rw->__waiters), w++; - if (__timedwait(&rw->__wrlock, 1, CLOCK_REALTIME, at, 0)==ETIMEDOUT) { - if (w) a_dec(&rw->__waiters); + if (!w) a_inc(&rw->_rw_waiters), w++; + if (__timedwait(&rw->_rw_wrlock, 1, CLOCK_REALTIME, at, 0)==ETIMEDOUT) { + if (w) a_dec(&rw->_rw_waiters); return ETIMEDOUT; } } - if (w) a_dec(&rw->__waiters); + if (w) a_dec(&rw->_rw_waiters); return 0; } diff --git a/src/thread/pthread_rwlock_timedwrlock.c b/src/thread/pthread_rwlock_timedwrlock.c index 9f749648..96827749 100644 --- a/src/thread/pthread_rwlock_timedwrlock.c +++ b/src/thread/pthread_rwlock_timedwrlock.c @@ -4,14 +4,14 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t *rw, const struct timespec *at) { int nr, *p, w=0; while (pthread_rwlock_trywrlock(rw)==EAGAIN) { - if (!w) a_inc(&rw->__waiters), w++; - if ((nr=rw->__readers)) p = &rw->__readers; - else nr=1, p = &rw->__wrlock; + if (!w) a_inc(&rw->_rw_waiters), w++; + if ((nr=rw->_rw_readers)) p = &rw->_rw_readers; + else nr=1, p = &rw->_rw_wrlock; if (__timedwait(p, nr, CLOCK_REALTIME, at, 0)==ETIMEDOUT) { - if (w) a_dec(&rw->__waiters); + if (w) a_dec(&rw->_rw_waiters); return ETIMEDOUT; } } - if (w) a_dec(&rw->__waiters); + if (w) a_dec(&rw->_rw_waiters); return 0; } diff --git a/src/thread/pthread_rwlock_tryrdlock.c b/src/thread/pthread_rwlock_tryrdlock.c index f59fbbdd..fc1d5328 100644 --- a/src/thread/pthread_rwlock_tryrdlock.c +++ b/src/thread/pthread_rwlock_tryrdlock.c @@ -2,11 +2,11 @@ int pthread_rwlock_tryrdlock(pthread_rwlock_t *rw) { - a_inc(&rw->__readers); - if (rw->__wrlock) { - a_dec(&rw->__readers); - if (rw->__waiters && !rw->__readers) - __wake(&rw->__readers, 1, 0); + a_inc(&rw->_rw_readers); + if (rw->_rw_wrlock) { + a_dec(&rw->_rw_readers); + if (rw->_rw_waiters && !rw->_rw_readers) + __wake(&rw->_rw_readers, 1, 0); return EAGAIN; } return 0; diff --git a/src/thread/pthread_rwlock_trywrlock.c b/src/thread/pthread_rwlock_trywrlock.c index c029b874..1bcf7c99 100644 --- a/src/thread/pthread_rwlock_trywrlock.c +++ b/src/thread/pthread_rwlock_trywrlock.c @@ -2,12 +2,12 @@ int pthread_rwlock_trywrlock(pthread_rwlock_t *rw) { - if (a_xchg(&rw->__wrlock, 1)) + if (a_xchg(&rw->_rw_wrlock, 1)) return EAGAIN; - if (rw->__readers) { - a_store(&rw->__wrlock, 0); + if (rw->_rw_readers) { + a_store(&rw->_rw_wrlock, 0); return EAGAIN; } - rw->__owner = pthread_self()->tid; + rw->_rw_owner = pthread_self()->tid; return 0; } diff --git a/src/thread/pthread_rwlock_unlock.c b/src/thread/pthread_rwlock_unlock.c index f39117e7..060e3fe1 100644 --- a/src/thread/pthread_rwlock_unlock.c +++ b/src/thread/pthread_rwlock_unlock.c @@ -3,15 +3,15 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rw) { struct pthread *self = pthread_self(); - if (rw->__owner == self->tid) { - rw->__owner = 0; - a_store(&rw->__wrlock, 0); - if (rw->__waiters) - __wake(&rw->__wrlock, -1, 0); + if (rw->_rw_owner == self->tid) { + rw->_rw_owner = 0; + a_store(&rw->_rw_wrlock, 0); + if (rw->_rw_waiters) + __wake(&rw->_rw_wrlock, -1, 0); return 0; } - a_dec(&rw->__readers); - if (rw->__waiters && !rw->__readers) - __wake(&rw->__readers, 1, 0); + a_dec(&rw->_rw_readers); + if (rw->_rw_waiters && !rw->_rw_readers) + __wake(&rw->_rw_readers, 1, 0); return 0; } diff --git a/src/thread/pthread_rwlock_wrlock.c b/src/thread/pthread_rwlock_wrlock.c index 219e924a..8fd9ad1d 100644 --- a/src/thread/pthread_rwlock_wrlock.c +++ b/src/thread/pthread_rwlock_wrlock.c @@ -4,10 +4,10 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *rw) { int nr; while (pthread_rwlock_trywrlock(rw)==EAGAIN) { - if ((nr=rw->__readers)) - __wait(&rw->__readers, &rw->__waiters, nr, 0); + if ((nr=rw->_rw_readers)) + __wait(&rw->_rw_readers, &rw->_rw_waiters, nr, 0); else - __wait(&rw->__wrlock, &rw->__waiters, 1, 0); + __wait(&rw->_rw_wrlock, &rw->_rw_waiters, 1, 0); } return 0; } |