PERFORCE change 65526 for review

David Xu davidxu at FreeBSD.org
Fri Nov 19 21:01:58 PST 2004


http://perforce.freebsd.org/chv.cgi?CH=65526

Change 65526 by davidxu at 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));
 }


More information about the p4-projects mailing list