summaryrefslogtreecommitdiffstats
path: root/lib/librt
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2010-09-25 01:57:47 +0000
committerdavidxu <davidxu@FreeBSD.org>2010-09-25 01:57:47 +0000
commit74604ed9c419ab380cacaaeb78e4c26f9f37e0ad (patch)
tree7b4cd520f700d5e2d7a21bc8175c8574d209a3ce /lib/librt
parentdf0d735bfefbd56b7c7cbca4590c651f83e3c831 (diff)
downloadFreeBSD-src-74604ed9c419ab380cacaaeb78e4c26f9f37e0ad.zip
FreeBSD-src-74604ed9c419ab380cacaaeb78e4c26f9f37e0ad.tar.gz
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.
Diffstat (limited to 'lib/librt')
-rw-r--r--lib/librt/Makefile5
-rw-r--r--lib/librt/mq.c21
2 files changed, 12 insertions, 14 deletions
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 <signal.h>
#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);
}
OpenPOWER on IntegriCloud