156698Sjasone/*
263364Sjasone * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
356698Sjasone * All rights reserved.
456698Sjasone *
556698Sjasone * Redistribution and use in source and binary forms, with or without
656698Sjasone * modification, are permitted provided that the following conditions
756698Sjasone * are met:
856698Sjasone * 1. Redistributions of source code must retain the above copyright
956698Sjasone *    notice(s), this list of conditions and the following disclaimer as
1056698Sjasone *    the first lines of this file unmodified other than the possible
1156698Sjasone *    addition of one or more copyright notices.
1256698Sjasone * 2. Redistributions in binary form must reproduce the above copyright
1356698Sjasone *    notice(s), this list of conditions and the following disclaimer in
1456698Sjasone *    the documentation and/or other materials provided with the
1556698Sjasone *    distribution.
1656698Sjasone *
1756698Sjasone * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
1856698Sjasone * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1956698Sjasone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2056698Sjasone * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
2156698Sjasone * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2256698Sjasone * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2356698Sjasone * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
2456698Sjasone * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2556698Sjasone * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2656698Sjasone * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
2756698Sjasone * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2856698Sjasone *
2956698Sjasone * $FreeBSD: releng/10.3/lib/libkse/thread/thr_sleep.c 174689 2007-12-16 23:29:57Z deischen $
3056698Sjasone */
3156698Sjasone
32174112Sdeischen#include "namespace.h"
3356698Sjasone#include <unistd.h>
3456698Sjasone#include <pthread.h>
35174112Sdeischen#include "un-namespace.h"
36103388Smini#include "thr_private.h"
3756698Sjasone
38148660Sdeischenextern unsigned int	__sleep(unsigned int);
39148660Sdeischenextern int		__usleep(useconds_t);
40119723Sdeischen
41174112Sdeischenunsigned int	_sleep(unsigned int seconds);
42174112Sdeischen
4375369Sdeischen__weak_reference(_sleep, sleep);
44148660Sdeischen__weak_reference(_usleep, usleep);
4571581Sdeischen
4656698Sjasoneunsigned int
4771581Sdeischen_sleep(unsigned int seconds)
4856698Sjasone{
49113658Sdeischen	struct pthread *curthread = _get_curthread();
5056698Sjasone	unsigned int	ret;
5156698Sjasone
52123312Sdavidxu	_thr_cancel_enter(curthread);
5356698Sjasone	ret = __sleep(seconds);
54123312Sdavidxu	_thr_cancel_leave(curthread, 1);
5556698Sjasone
56113658Sdeischen	return (ret);
5756698Sjasone}
58148660Sdeischen
59148660Sdeischenint
60148660Sdeischen_usleep(useconds_t useconds)
61148660Sdeischen{
62148660Sdeischen	struct pthread *curthread = _get_curthread();
63148660Sdeischen	unsigned int	ret;
64148660Sdeischen
65148660Sdeischen	_thr_cancel_enter(curthread);
66148660Sdeischen	ret = __usleep(useconds);
67148660Sdeischen	_thr_cancel_leave(curthread, 1);
68148660Sdeischen
69148660Sdeischen	return (ret);
70148660Sdeischen}
71