From c0c21f6ca7154b0b731af2fc4e975405e5dd130c Mon Sep 17 00:00:00 2001 From: deischen Date: Wed, 3 Aug 2005 00:48:13 +0000 Subject: [PATCH] Add a cancellation point for usleep(). --- lib/libkse/thread/thr_sleep.c | 17 ++++++++++++++++- lib/libpthread/thread/thr_sleep.c | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/libkse/thread/thr_sleep.c b/lib/libkse/thread/thr_sleep.c index 7547e60674a1..682c76403213 100644 --- a/lib/libkse/thread/thr_sleep.c +++ b/lib/libkse/thread/thr_sleep.c @@ -33,9 +33,11 @@ #include #include "thr_private.h" -extern unsigned int __sleep(unsigned int); +extern unsigned int __sleep(unsigned int); +extern int __usleep(useconds_t); __weak_reference(_sleep, sleep); +__weak_reference(_usleep, usleep); unsigned int _sleep(unsigned int seconds) @@ -49,3 +51,16 @@ _sleep(unsigned int seconds) return (ret); } + +int +_usleep(useconds_t useconds) +{ + struct pthread *curthread = _get_curthread(); + unsigned int ret; + + _thr_cancel_enter(curthread); + ret = __usleep(useconds); + _thr_cancel_leave(curthread, 1); + + return (ret); +} diff --git a/lib/libpthread/thread/thr_sleep.c b/lib/libpthread/thread/thr_sleep.c index 7547e60674a1..682c76403213 100644 --- a/lib/libpthread/thread/thr_sleep.c +++ b/lib/libpthread/thread/thr_sleep.c @@ -33,9 +33,11 @@ #include #include "thr_private.h" -extern unsigned int __sleep(unsigned int); +extern unsigned int __sleep(unsigned int); +extern int __usleep(useconds_t); __weak_reference(_sleep, sleep); +__weak_reference(_usleep, usleep); unsigned int _sleep(unsigned int seconds) @@ -49,3 +51,16 @@ _sleep(unsigned int seconds) return (ret); } + +int +_usleep(useconds_t useconds) +{ + struct pthread *curthread = _get_curthread(); + unsigned int ret; + + _thr_cancel_enter(curthread); + ret = __usleep(useconds); + _thr_cancel_leave(curthread, 1); + + return (ret); +}