thr_nanosleep.c (123312) | thr_nanosleep.c (155962) |
---|---|
1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * | 1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * |
32 * $FreeBSD: head/lib/libkse/thread/thr_nanosleep.c 123312 2003-12-09 02:20:56Z davidxu $ | 32 * $FreeBSD: head/lib/libkse/thread/thr_nanosleep.c 155962 2006-02-23 21:34:08Z deischen $ |
33 */ 34#include <stdio.h> 35#include <errno.h> 36#include <pthread.h> 37#include "thr_private.h" 38 39__weak_reference(__nanosleep, nanosleep); 40 41int 42_nanosleep(const struct timespec *time_to_sleep, 43 struct timespec *time_remaining) 44{ 45 struct pthread *curthread = _get_curthread(); 46 int ret = 0; 47 struct timespec ts, ts1; 48 struct timespec remaining_time; | 33 */ 34#include <stdio.h> 35#include <errno.h> 36#include <pthread.h> 37#include "thr_private.h" 38 39__weak_reference(__nanosleep, nanosleep); 40 41int 42_nanosleep(const struct timespec *time_to_sleep, 43 struct timespec *time_remaining) 44{ 45 struct pthread *curthread = _get_curthread(); 46 int ret = 0; 47 struct timespec ts, ts1; 48 struct timespec remaining_time; |
49 struct timespec wakeup_time; |
|
49 50 /* Check if the time to sleep is legal: */ 51 if ((time_to_sleep == NULL) || (time_to_sleep->tv_sec < 0) || 52 (time_to_sleep->tv_nsec < 0) || 53 (time_to_sleep->tv_nsec >= 1000000000)) { 54 /* Return an EINVAL error : */ 55 errno = EINVAL; 56 ret = -1; 57 } else { 58 if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) 59 return (__sys_nanosleep(time_to_sleep, time_remaining)); 60 61 KSE_GET_TOD(curthread->kse, &ts); 62 63 /* Calculate the time for the current thread to wake up: */ | 50 51 /* Check if the time to sleep is legal: */ 52 if ((time_to_sleep == NULL) || (time_to_sleep->tv_sec < 0) || 53 (time_to_sleep->tv_nsec < 0) || 54 (time_to_sleep->tv_nsec >= 1000000000)) { 55 /* Return an EINVAL error : */ 56 errno = EINVAL; 57 ret = -1; 58 } else { 59 if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) 60 return (__sys_nanosleep(time_to_sleep, time_remaining)); 61 62 KSE_GET_TOD(curthread->kse, &ts); 63 64 /* Calculate the time for the current thread to wake up: */ |
64 TIMESPEC_ADD(&curthread->wakeup_time, &ts, time_to_sleep); | 65 TIMESPEC_ADD(&wakeup_time, &ts, time_to_sleep); |
65 66 THR_LOCK_SWITCH(curthread); 67 curthread->interrupted = 0; | 66 67 THR_LOCK_SWITCH(curthread); 68 curthread->interrupted = 0; |
69 curthread->wakeup_time = wakeup_time; |
|
68 THR_SET_STATE(curthread, PS_SLEEP_WAIT); 69 70 /* Reschedule the current thread to sleep: */ 71 _thr_sched_switch_unlocked(curthread); 72 73 /* Calculate the remaining time to sleep: */ 74 KSE_GET_TOD(curthread->kse, &ts1); 75 remaining_time.tv_sec = time_to_sleep->tv_sec --- 54 unchanged lines hidden --- | 70 THR_SET_STATE(curthread, PS_SLEEP_WAIT); 71 72 /* Reschedule the current thread to sleep: */ 73 _thr_sched_switch_unlocked(curthread); 74 75 /* Calculate the remaining time to sleep: */ 76 KSE_GET_TOD(curthread->kse, &ts1); 77 remaining_time.tv_sec = time_to_sleep->tv_sec --- 54 unchanged lines hidden --- |