From owner-p4-projects@FreeBSD.ORG Sat Nov 20 05:01:58 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0BC8C16A4D0; Sat, 20 Nov 2004 05:01:58 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C42C116A4CE for ; Sat, 20 Nov 2004 05:01:57 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id A726D43D76 for ; Sat, 20 Nov 2004 05:01:57 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id iAK51ZsA013531 for ; Sat, 20 Nov 2004 05:01:35 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id iAK51YDD013528 for perforce@freebsd.org; Sat, 20 Nov 2004 05:01:34 GMT (envelope-from davidxu@freebsd.org) Date: Sat, 20 Nov 2004 05:01:34 GMT Message-Id: <200411200501.iAK51YDD013528@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to davidxu@freebsd.org using -f From: David Xu To: Perforce Change Reviews Subject: PERFORCE change 65526 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Nov 2004 05:01:58 -0000 http://perforce.freebsd.org/chv.cgi?CH=65526 Change 65526 by davidxu@davidxu_alona on 2004/11/20 05:00:42 __sys_nanosleep. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_nanosleep.c#3 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_nanosleep.c#3 (text+ko) ==== @@ -39,91 +39,22 @@ __weak_reference(__nanosleep, nanosleep); int -_nanosleep(const struct timespec *time_to_sleep, +__nanosleep(const struct timespec *time_to_sleep, struct timespec *time_remaining) { - struct pthread *curthread = _get_curthread(); - int ret = 0; - struct timespec ts, ts1; - struct timespec remaining_time; + struct pthread *curthread = _get_curthread(); + int ret; - /* Check if the time to sleep is legal: */ - if ((time_to_sleep == NULL) || (time_to_sleep->tv_sec < 0) || - (time_to_sleep->tv_nsec < 0) || - (time_to_sleep->tv_nsec >= 1000000000)) { - /* Return an EINVAL error : */ - errno = EINVAL; - ret = -1; - } else { - if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) - return (__sys_nanosleep(time_to_sleep, time_remaining)); - - KSE_GET_TOD(curthread->kse, &ts); - - /* Calculate the time for the current thread to wake up: */ - TIMESPEC_ADD(&curthread->wakeup_time, &ts, time_to_sleep); - - THR_LOCK_SWITCH(curthread); - curthread->interrupted = 0; - THR_SET_STATE(curthread, PS_SLEEP_WAIT); - - /* Reschedule the current thread to sleep: */ - _thr_sched_switch_unlocked(curthread); + _thr_cancel_enter(curthread); + ret = __sys_nanosleep(time_to_sleep, time_remaining); + _thr_cancel_leave(curthread, 1); - /* Calculate the remaining time to sleep: */ - KSE_GET_TOD(curthread->kse, &ts1); - remaining_time.tv_sec = time_to_sleep->tv_sec - + ts.tv_sec - ts1.tv_sec; - remaining_time.tv_nsec = time_to_sleep->tv_nsec - + ts.tv_nsec - ts1.tv_nsec; - - /* Check if the nanosecond field has underflowed: */ - if (remaining_time.tv_nsec < 0) { - /* Handle the underflow: */ - remaining_time.tv_sec -= 1; - remaining_time.tv_nsec += 1000000000; - } - /* Check if the nanosecond field has overflowed: */ - else if (remaining_time.tv_nsec >= 1000000000) { - /* Handle the overflow: */ - remaining_time.tv_sec += 1; - remaining_time.tv_nsec -= 1000000000; - } - - /* Check if the sleep was longer than the required time: */ - if (remaining_time.tv_sec < 0) { - /* Reset the time left: */ - remaining_time.tv_sec = 0; - remaining_time.tv_nsec = 0; - } - - /* Check if the time remaining is to be returned: */ - if (time_remaining != NULL) { - /* Return the actual time slept: */ - time_remaining->tv_sec = remaining_time.tv_sec; - time_remaining->tv_nsec = remaining_time.tv_nsec; - } - - /* Check if the sleep was interrupted: */ - if (curthread->interrupted) { - /* Return an EINTR error : */ - errno = EINTR; - ret = -1; - } - } return (ret); } int -__nanosleep(const struct timespec *time_to_sleep, +_nanosleep(const struct timespec *time_to_sleep, struct timespec *time_remaining) { - struct pthread *curthread = _get_curthread(); - int ret; - - _thr_cancel_enter(curthread); - ret = _nanosleep(time_to_sleep, time_remaining); - _thr_cancel_leave(curthread, 1); - - return (ret); + return (__sys_nanosleep(time_to_sleep, time_remaining)); }