From 74604ed9c419ab380cacaaeb78e4c26f9f37e0ad Mon Sep 17 00:00:00 2001 From: davidxu Date: Sat, 25 Sep 2010 01:57:47 +0000 Subject: To support stack unwinding for cancellation points, add -fexceptions flag for them, two functions _pthread_cancel_enter and _pthread_cancel_leave are added to let thread enter and leave a cancellation point, it also makes it possible that other functions can be cancellation points in libraries without having to be rewritten in libthr. --- lib/librt/Makefile | 5 +++-- lib/librt/mq.c | 21 +++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) (limited to 'lib/librt') diff --git a/lib/librt/Makefile b/lib/librt/Makefile index f98d94e..86be751 100644 --- a/lib/librt/Makefile +++ b/lib/librt/Makefile @@ -3,14 +3,15 @@ LIB=rt SHLIB_MAJOR= 1 CFLAGS+=-I${.CURDIR}/../libc/include -I${.CURDIR} +.ifndef NO_THREAD_STACK_UNWIND +CFLAGS+=-fexceptions +.endif CFLAGS+=-Winline -Wall -g DPADD= ${LIBPTHREAD} LDADD= -lpthread WARNS?= 2 -#MAN= libthr.3 - SRCS+= aio.c mq.c sigev_thread.c timer.c PRECIOUSLIB= diff --git a/lib/librt/mq.c b/lib/librt/mq.c index f2e01ca..750e969 100644 --- a/lib/librt/mq.c +++ b/lib/librt/mq.c @@ -39,6 +39,7 @@ #include #include "sigev_thread.h" #include "un-namespace.h" +#include "libc_private.h" extern int __sys_kmq_notify(int, const struct sigevent *); extern int __sys_kmq_open(const char *, int, mode_t, @@ -200,12 +201,11 @@ ssize_t __mq_timedreceive_cancel(mqd_t mqd, char *buf, size_t len, unsigned *prio, const struct timespec *timeout) { - int oldtype; int ret; - _pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); + _pthread_cancel_enter(1); ret = __sys_kmq_timedreceive(mqd->oshandle, buf, len, prio, timeout); - _pthread_setcanceltype(oldtype, NULL); + _pthread_cancel_leave(ret == -1); return (ret); } @@ -219,12 +219,11 @@ __mq_receive(mqd_t mqd, char *buf, size_t len, unsigned *prio) ssize_t __mq_receive_cancel(mqd_t mqd, char *buf, size_t len, unsigned *prio) { - int oldtype; int ret; - _pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); + _pthread_cancel_enter(1); ret = __sys_kmq_timedreceive(mqd->oshandle, buf, len, prio, NULL); - _pthread_setcanceltype(oldtype, NULL); + _pthread_cancel_leave(ret == -1); return (ret); } ssize_t @@ -239,12 +238,11 @@ ssize_t __mq_timedsend_cancel(mqd_t mqd, char *buf, size_t len, unsigned prio, const struct timespec *timeout) { - int oldtype; int ret; - _pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); + _pthread_cancel_enter(1); ret = __sys_kmq_timedsend(mqd->oshandle, buf, len, prio, timeout); - _pthread_setcanceltype(oldtype, NULL); + _pthread_cancel_leave(ret == -1); return (ret); } @@ -259,12 +257,11 @@ __mq_send(mqd_t mqd, char *buf, size_t len, unsigned prio) ssize_t __mq_send_cancel(mqd_t mqd, char *buf, size_t len, unsigned prio) { - int oldtype; int ret; - _pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); + _pthread_cancel_enter(1); ret = __sys_kmq_timedsend(mqd->oshandle, buf, len, prio, NULL); - _pthread_setcanceltype(oldtype, NULL); + _pthread_cancel_leave(ret == -1); return (ret); } -- cgit v1.1