Eliminate atomic operations in thread cancellation functions, it should

reduce overheads of cancellation points.
This commit is contained in:
David Xu 2006-11-24 09:57:38 +00:00
parent 0ff56caba8
commit f08e1bf682
12 changed files with 180 additions and 217 deletions

View file

@ -38,126 +38,120 @@ __weak_reference(_pthread_setcancelstate, pthread_setcancelstate);
__weak_reference(_pthread_setcanceltype, pthread_setcanceltype);
__weak_reference(_pthread_testcancel, pthread_testcancel);
static inline void
testcancel(struct pthread *curthread)
{
if (__predict_false(SHOULD_CANCEL(curthread) &&
!THR_IN_CRITICAL(curthread)))
_pthread_exit(PTHREAD_CANCELED);
}
void
_thr_testcancel(struct pthread *curthread)
{
testcancel(curthread);
}
int
_pthread_cancel(pthread_t pthread)
{
struct pthread *curthread = _get_curthread();
int oldval, newval = 0;
int oldtype;
int ret;
/*
* POSIX says _pthread_cancel should be async cancellation safe,
* so we temporarily disable async cancellation.
* POSIX says _pthread_cancel should be async cancellation safe.
* _thr_ref_add and _thr_ref_delete will enter and leave critical
* region automatically.
*/
_pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
if ((ret = _thr_ref_add(curthread, pthread, 0)) != 0) {
_pthread_setcanceltype(oldtype, NULL);
return (ret);
if ((ret = _thr_ref_add(curthread, pthread, 0)) == 0) {
THR_THREAD_LOCK(curthread, pthread);
if (!pthread->cancel_pending) {
pthread->cancel_pending = 1;
if (pthread->cancel_enable)
_thr_send_sig(pthread, SIGCANCEL);
}
THR_THREAD_UNLOCK(curthread, pthread);
_thr_ref_delete(curthread, pthread);
}
do {
oldval = pthread->cancelflags;
if (oldval & THR_CANCEL_NEEDED)
break;
newval = oldval | THR_CANCEL_NEEDED;
} while (!atomic_cmpset_acq_int(&pthread->cancelflags, oldval, newval));
if (!(oldval & THR_CANCEL_NEEDED) && SHOULD_ASYNC_CANCEL(newval))
_thr_send_sig(pthread, SIGCANCEL);
_thr_ref_delete(curthread, pthread);
_pthread_setcanceltype(oldtype, NULL);
return (0);
}
static inline void
testcancel(struct pthread *curthread)
{
int newval;
newval = curthread->cancelflags;
if (SHOULD_CANCEL(newval) && !THR_IN_CRITICAL(curthread))
_pthread_exit(PTHREAD_CANCELED);
return (ret);
}
int
_pthread_setcancelstate(int state, int *oldstate)
{
struct pthread *curthread = _get_curthread();
int oldval, ret;
int oldval;
oldval = curthread->cancelflags;
if (oldstate != NULL)
*oldstate = ((oldval & THR_CANCEL_DISABLE) ?
PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE);
oldval = curthread->cancel_enable;
switch (state) {
case PTHREAD_CANCEL_DISABLE:
atomic_set_int(&curthread->cancelflags, THR_CANCEL_DISABLE);
ret = 0;
THR_LOCK(curthread);
curthread->cancel_enable = 0;
THR_UNLOCK(curthread);
break;
case PTHREAD_CANCEL_ENABLE:
atomic_clear_int(&curthread->cancelflags, THR_CANCEL_DISABLE);
testcancel(curthread);
ret = 0;
THR_LOCK(curthread);
curthread->cancel_enable = 1;
THR_UNLOCK(curthread);
break;
default:
ret = EINVAL;
return (EINVAL);
}
return (ret);
if (oldstate) {
*oldstate = oldval ? PTHREAD_CANCEL_ENABLE :
PTHREAD_CANCEL_DISABLE;
}
return (0);
}
int
_pthread_setcanceltype(int type, int *oldtype)
{
struct pthread *curthread = _get_curthread();
int oldval, ret;
int oldval;
oldval = curthread->cancelflags;
if (oldtype != NULL)
*oldtype = ((oldval & THR_CANCEL_AT_POINT) ?
PTHREAD_CANCEL_ASYNCHRONOUS :
PTHREAD_CANCEL_DEFERRED);
oldval = curthread->cancel_async;
switch (type) {
case PTHREAD_CANCEL_ASYNCHRONOUS:
atomic_set_int(&curthread->cancelflags, THR_CANCEL_AT_POINT);
curthread->cancel_async = 1;
testcancel(curthread);
ret = 0;
break;
case PTHREAD_CANCEL_DEFERRED:
atomic_clear_int(&curthread->cancelflags, THR_CANCEL_AT_POINT);
ret = 0;
curthread->cancel_async = 0;
break;
default:
ret = EINVAL;
return (EINVAL);
}
return (ret);
if (oldtype) {
*oldtype = oldval ? PTHREAD_CANCEL_ASYNCHRONOUS :
PTHREAD_CANCEL_DEFERRED;
}
return (0);
}
void
_pthread_testcancel(void)
{
testcancel(_get_curthread());
}
struct pthread *curthread = _get_curthread();
int
_thr_cancel_enter(struct pthread *curthread)
{
int oldval;
oldval = curthread->cancelflags;
if (!(oldval & THR_CANCEL_AT_POINT)) {
atomic_set_int(&curthread->cancelflags, THR_CANCEL_AT_POINT);
testcancel(curthread);
}
return (oldval);
_thr_cancel_enter(curthread);
_thr_cancel_leave(curthread);
}
void
_thr_cancel_leave(struct pthread *curthread, int previous)
_thr_cancel_enter(struct pthread *curthread)
{
if (!(previous & THR_CANCEL_AT_POINT))
atomic_clear_int(&curthread->cancelflags, THR_CANCEL_AT_POINT);
if (curthread->cancel_enable) {
curthread->cancel_point++;
testcancel(curthread);
}
}
void
_thr_cancel_leave(struct pthread *curthread)
{
if (curthread->cancel_enable)
curthread->cancel_point--;
}

View file

@ -195,7 +195,6 @@ cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
struct cond_cancel_info info;
pthread_cond_t cv;
long seq, oldseq;
int oldcancel;
int ret = 0;
/*
@ -231,9 +230,9 @@ cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
if (cancel) {
THR_CLEANUP_PUSH(curthread, cond_cancel_handler, &info);
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = _thr_umtx_wait(&cv->c_seqno, seq, tsp);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
THR_CLEANUP_POP(curthread, 0);
} else {
ret = _thr_umtx_wait(&cv->c_seqno, seq, tsp);

View file

@ -105,8 +105,8 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
new_thread->magic = THR_MAGIC;
new_thread->start_routine = start_routine;
new_thread->arg = arg;
new_thread->cancelflags = PTHREAD_CANCEL_ENABLE |
PTHREAD_CANCEL_DEFERRED;
new_thread->cancel_enable = 1;
new_thread->cancel_async = 0;
/* Initialize the mutex queue: */
TAILQ_INIT(&new_thread->mutexq);
TAILQ_INIT(&new_thread->pp_mutexq);

View file

@ -87,7 +87,7 @@ _pthread_exit(void *status)
struct pthread *curthread = _get_curthread();
/* Check if this thread is already in the process of exiting: */
if ((curthread->cancelflags & THR_CANCEL_EXITING) != 0) {
if (curthread->cancelling) {
char msg[128];
snprintf(msg, sizeof(msg), "Thread %p has called "
"pthread_exit() from a destructor. POSIX 1003.1 "
@ -96,7 +96,7 @@ _pthread_exit(void *status)
}
/* Flag this thread as exiting. */
atomic_set_int(&curthread->cancelflags, THR_CANCEL_EXITING);
curthread->cancelling = 1;
_thr_exit_cleanup();

View file

@ -143,7 +143,7 @@ _fork(void)
if ((ret = __sys_fork()) == 0) {
/* Child process */
errsave = errno;
curthread->cancelflags &= ~THR_CANCEL_NEEDED;
curthread->cancel_pending = 0;
curthread->flags &= ~THR_FLAGS_NEED_SUSPEND;
/*

View file

@ -402,7 +402,8 @@ init_main_thread(struct pthread *thread)
*/
thread->magic = THR_MAGIC;
thread->cancelflags = PTHREAD_CANCEL_ENABLE | PTHREAD_CANCEL_DEFERRED;
thread->cancel_enable = 1;
thread->cancel_async = 0;
thr_set_name(thread->tid, "initial thread");
/* Initialize the mutex queue: */

View file

@ -76,7 +76,6 @@ join_common(pthread_t pthread, void **thread_return,
struct timespec ts, ts2, *tsp;
void *tmp;
long tid;
int oldcancel;
int ret = 0;
if (pthread == NULL)
@ -104,7 +103,7 @@ join_common(pthread_t pthread, void **thread_return,
THREAD_LIST_UNLOCK(curthread);
THR_CLEANUP_PUSH(curthread, backout_join, pthread);
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
tid = pthread->tid;
while (pthread->tid != TID_TERMINATED) {
@ -123,7 +122,7 @@ join_common(pthread_t pthread, void **thread_return,
break;
}
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
THR_CLEANUP_POP(curthread, 0);
if (ret == ETIMEDOUT) {

View file

@ -293,6 +293,7 @@ _thr_ref_add(struct pthread *curthread, struct pthread *thread,
THREAD_LIST_LOCK(curthread);
if ((ret = _thr_find_thread(curthread, thread, include_dead)) == 0) {
thread->refcount++;
THR_CRITICAL_ENTER(curthread);
}
THREAD_LIST_UNLOCK(curthread);
@ -309,7 +310,7 @@ _thr_ref_delete(struct pthread *curthread, struct pthread *thread)
}
void
_thr_ref_delete_unlocked(struct pthread *curthread __unused,
_thr_ref_delete_unlocked(struct pthread *curthread,
struct pthread *thread)
{
if (thread != NULL) {
@ -317,6 +318,7 @@ _thr_ref_delete_unlocked(struct pthread *curthread __unused,
if ((thread->refcount == 0) && thread->state == PS_DEAD &&
(thread->tlflags & TLFLAGS_DETACHED) != 0)
THR_GCLIST_ADD(thread);
THR_CRITICAL_LEAVE(curthread);
}
}

View file

@ -350,22 +350,25 @@ struct pthread {
void *arg;
struct pthread_attr attr;
/*
* Cancelability flags
*/
#define THR_CANCEL_DISABLE 0x0001
#define THR_CANCEL_EXITING 0x0002
#define THR_CANCEL_AT_POINT 0x0004
#define THR_CANCEL_NEEDED 0x0008
#define SHOULD_CANCEL(val) \
(((val) & (THR_CANCEL_DISABLE | THR_CANCEL_EXITING | \
THR_CANCEL_NEEDED)) == THR_CANCEL_NEEDED)
#define SHOULD_CANCEL(thr) \
((thr)->cancel_pending && \
((thr)->cancel_point || (thr)->cancel_async) && \
(thr)->cancel_enable && (thr)->cancelling == 0)
#define SHOULD_ASYNC_CANCEL(val) \
(((val) & (THR_CANCEL_DISABLE | THR_CANCEL_EXITING | \
THR_CANCEL_NEEDED | THR_CANCEL_AT_POINT)) == \
(THR_CANCEL_NEEDED | THR_CANCEL_AT_POINT))
int cancelflags;
/* Cancellation is enabled */
int cancel_enable;
/* Cancellation request is pending */
int cancel_pending;
/* Thread is at cancellation point */
int cancel_point;
/* Asynchronouse cancellation is enabled */
int cancel_async;
/* Cancellation is in progress */
int cancelling;
/* Thread temporary signal mask. */
sigset_t sigmask;
@ -620,8 +623,9 @@ void _thread_cleanupspecific(void) __hidden;
void _thread_dump_info(void) __hidden;
void _thread_printf(int, const char *, ...) __hidden;
void _thr_spinlock_init(void) __hidden;
int _thr_cancel_enter(struct pthread *) __hidden;
void _thr_cancel_leave(struct pthread *, int) __hidden;
void _thr_cancel_enter(struct pthread *) __hidden;
void _thr_cancel_leave(struct pthread *) __hidden;
void _thr_testcancel(struct pthread *) __hidden;
void _thr_signal_block(struct pthread *) __hidden;
void _thr_signal_unblock(struct pthread *) __hidden;
void _thr_signal_init(void) __hidden;

View file

@ -176,16 +176,16 @@ int
_sem_wait(sem_t *sem)
{
struct pthread *curthread;
int val, oldcancel, retval;
int val, retval;
if (sem_check_validity(sem) != 0)
return (-1);
curthread = _get_curthread();
if ((*sem)->syssem != 0) {
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
retval = ksem_wait((*sem)->semid);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (retval);
}
@ -195,9 +195,9 @@ _sem_wait(sem_t *sem)
if (atomic_cmpset_acq_int(&(*sem)->count, val, val - 1))
return (0);
}
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
retval = _thr_umtx_wait((umtx_t *)&(*sem)->count, 0, NULL);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
} while (retval == 0);
errno = retval;
return (-1);
@ -209,16 +209,16 @@ _sem_timedwait(sem_t * __restrict sem,
{
struct timespec ts, ts2;
struct pthread *curthread;
int val, oldcancel, retval;
int val, retval;
if (sem_check_validity(sem) != 0)
return (-1);
curthread = _get_curthread();
if ((*sem)->syssem != 0) {
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
retval = ksem_timedwait((*sem)->semid, abstime);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (retval);
}
@ -238,9 +238,9 @@ _sem_timedwait(sem_t * __restrict sem,
}
clock_gettime(CLOCK_REALTIME, &ts);
TIMESPEC_SUB(&ts2, abstime, &ts);
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
retval = _thr_umtx_wait((umtx_t *)&(*sem)->count, 0, &ts2);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
} while (retval == 0);
errno = retval;
return (-1);

View file

@ -68,9 +68,7 @@ void
_thr_ast(struct pthread *curthread)
{
if (!THR_IN_CRITICAL(curthread)) {
if (__predict_false(
SHOULD_ASYNC_CANCEL(curthread->cancelflags)))
_pthread_testcancel();
_thr_testcancel(curthread);
if (__predict_false((curthread->flags &
(THR_FLAGS_NEED_SUSPEND | THR_FLAGS_SUSPENDED))
== THR_FLAGS_NEED_SUSPEND))
@ -154,12 +152,11 @@ int
___pause(void)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __pause();
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -248,7 +245,6 @@ __sigsuspend(const sigset_t * set)
struct pthread *curthread = _get_curthread();
sigset_t newset;
const sigset_t *pset;
int oldcancel;
int ret;
if (SIGISMEMBER(*set, SIGCANCEL)) {
@ -258,9 +254,9 @@ __sigsuspend(const sigset_t * set)
} else
pset = set;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_sigsuspend(pset);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -294,7 +290,6 @@ __sigtimedwait(const sigset_t *set, siginfo_t *info,
struct pthread *curthread = _get_curthread();
sigset_t newset;
const sigset_t *pset;
int oldcancel;
int ret;
if (SIGISMEMBER(*set, SIGCANCEL)) {
@ -303,9 +298,9 @@ __sigtimedwait(const sigset_t *set, siginfo_t *info,
pset = &newset;
} else
pset = set;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_sigtimedwait(pset, info, timeout);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -333,7 +328,6 @@ __sigwaitinfo(const sigset_t *set, siginfo_t *info)
struct pthread *curthread = _get_curthread();
sigset_t newset;
const sigset_t *pset;
int oldcancel;
int ret;
if (SIGISMEMBER(*set, SIGCANCEL)) {
@ -343,9 +337,9 @@ __sigwaitinfo(const sigset_t *set, siginfo_t *info)
} else
pset = set;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_sigwaitinfo(pset, info);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -373,7 +367,6 @@ __sigwait(const sigset_t *set, int *sig)
struct pthread *curthread = _get_curthread();
sigset_t newset;
const sigset_t *pset;
int oldcancel;
int ret;
if (SIGISMEMBER(*set, SIGCANCEL)) {
@ -383,8 +376,8 @@ __sigwait(const sigset_t *set, int *sig)
} else
pset = set;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_sigwait(pset, sig);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}

View file

@ -160,13 +160,12 @@ int
__accept(int s, struct sockaddr *addr, socklen_t *addrlen)
{
struct pthread *curthread;
int oldcancel;
int ret;
curthread = _get_curthread();
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_accept(s, addr, addrlen);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -178,12 +177,11 @@ __aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
timespec *timeout)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_aio_suspend(iocbs, niocb, timeout);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -194,12 +192,11 @@ int
__close(int fd)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_close(fd);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -210,12 +207,11 @@ int
__connect(int fd, const struct sockaddr *name, socklen_t namelen)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_connect(fd, name, namelen);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -226,12 +222,11 @@ int
___creat(const char *path, mode_t mode)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __creat(path, mode);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -242,11 +237,10 @@ int
__fcntl(int fd, int cmd,...)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
va_list ap;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
va_start(ap, cmd);
switch (cmd) {
@ -266,7 +260,7 @@ __fcntl(int fd, int cmd,...)
}
va_end(ap);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -277,12 +271,11 @@ int
__fsync(int fd)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_fsync(fd);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -293,12 +286,11 @@ int
__msync(void *addr, size_t len, int flags)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_msync(addr, len, flags);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -310,12 +302,11 @@ __nanosleep(const struct timespec *time_to_sleep,
struct timespec *time_remaining)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_nanosleep(time_to_sleep, time_remaining);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -326,12 +317,11 @@ int
__open(const char *path, int flags,...)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
int mode = 0;
va_list ap;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
/* Check if the file is being created: */
if (flags & O_CREAT) {
@ -343,7 +333,7 @@ __open(const char *path, int flags,...)
ret = __sys_open(path, flags, mode);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -354,12 +344,11 @@ int
__poll(struct pollfd *fds, unsigned int nfds, int timeout)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_poll(fds, nfds, timeout);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -371,12 +360,11 @@ ___pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds,
const struct timespec *timo, const sigset_t *mask)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __pselect(count, rfds, wfds, efds, timo, mask);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -387,12 +375,11 @@ ssize_t
__read(int fd, void *buf, size_t nbytes)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
ssize_t ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_read(fd, buf, nbytes);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -403,12 +390,11 @@ ssize_t
__readv(int fd, const struct iovec *iov, int iovcnt)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
ssize_t ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_readv(fd, iov, iovcnt);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -420,12 +406,11 @@ __recvfrom(int s, void *b, size_t l, int f, struct sockaddr *from,
socklen_t *fl)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
ssize_t ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_recvfrom(s, b, l, f, from, fl);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -436,11 +421,10 @@ __recvmsg(int s, struct msghdr *m, int f)
{
struct pthread *curthread = _get_curthread();
ssize_t ret;
int oldcancel;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_recvmsg(s, m, f);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -451,12 +435,11 @@ __select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -467,11 +450,10 @@ __sendmsg(int s, const struct msghdr *m, int f)
{
struct pthread *curthread = _get_curthread();
ssize_t ret;
int oldcancel;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_sendmsg(s, m, f);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -483,11 +465,10 @@ __sendto(int s, const void *m, size_t l, int f, const struct sockaddr *t,
{
struct pthread *curthread = _get_curthread();
ssize_t ret;
int oldcancel;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_sendto(s, m, l, f, t, tl);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -497,12 +478,11 @@ unsigned int
___sleep(unsigned int seconds)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
unsigned int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sleep(seconds);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -513,12 +493,11 @@ int
___system(const char *string)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __system(string);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -529,12 +508,11 @@ int
___tcdrain(int fd)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __tcdrain(fd);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -545,12 +523,11 @@ int
___usleep(useconds_t useconds)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
int ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __usleep(useconds);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -569,12 +546,11 @@ pid_t
___wait(int *istat)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
pid_t ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __wait(istat);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -585,12 +561,11 @@ pid_t
__wait3(int *status, int options, struct rusage *rusage)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
pid_t ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = _wait4(WAIT_ANY, status, options, rusage);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return (ret);
}
@ -601,12 +576,11 @@ pid_t
__wait4(pid_t pid, int *status, int options, struct rusage *rusage)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
pid_t ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_wait4(pid, status, options, rusage);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -617,12 +591,11 @@ pid_t
___waitpid(pid_t wpid, int *status, int options)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
pid_t ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __waitpid(wpid, status, options);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -633,12 +606,11 @@ ssize_t
__write(int fd, const void *buf, size_t nbytes)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
ssize_t ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_write(fd, buf, nbytes);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}
@ -649,12 +621,11 @@ ssize_t
__writev(int fd, const struct iovec *iov, int iovcnt)
{
struct pthread *curthread = _get_curthread();
int oldcancel;
ssize_t ret;
oldcancel = _thr_cancel_enter(curthread);
_thr_cancel_enter(curthread);
ret = __sys_writev(fd, iov, iovcnt);
_thr_cancel_leave(curthread, oldcancel);
_thr_cancel_leave(curthread);
return ret;
}