From de083845d3b359644125ab6201957d0ca04f6b42 Mon Sep 17 00:00:00 2001 From: Juergen Keil Date: Thu, 6 Sep 2001 13:29:18 +0000 Subject: Add xine_usec_sleep, a thread safe "sleep" with usec resolution CVS patchset: 575 CVS date: 2001/09/06 13:29:18 --- src/xine-engine/utils.c | 20 +++++++++++++++++++- src/xine-engine/utils.h | 7 ++++++- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/xine-engine/utils.c b/src/xine-engine/utils.c index 50d5cc482..3f45e909c 100644 --- a/src/xine-engine/utils.c +++ b/src/xine-engine/utils.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: utils.c,v 1.2 2001/06/21 17:34:24 guenter Exp $ + * $Id: utils.c,v 1.3 2001/09/06 13:29:18 jkeil Exp $ * */ #define _POSIX_PTHREAD_SEMANTICS 1 /* for 5-arg getpwuid_r on solaris */ @@ -32,6 +32,7 @@ #include #include #include +#include #include /* @@ -125,3 +126,20 @@ char *chomp(char *str) { return pbuf; } + + +/* + * A thread-safe usecond sleep + */ +void xine_usec_sleep(unsigned usec) { +#if HAVE_NANOSLEEP + /* nanosleep is prefered on solaris, because it's mt-safe */ + struct timespec ts; + + ts.tv_sec = usec / 1000000; + ts.tv_nsec = (usec % 1000000) * 1000; + nanosleep(&ts, NULL); +#else + usleep(usec); +#endif +} diff --git a/src/xine-engine/utils.h b/src/xine-engine/utils.h index f45a41dc6..ddc130871 100644 --- a/src/xine-engine/utils.h +++ b/src/xine-engine/utils.h @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: utils.h,v 1.2 2001/07/18 21:38:17 f1rmb Exp $ + * $Id: utils.h,v 1.3 2001/09/06 13:29:18 jkeil Exp $ * */ #ifndef HAVE_UTILS_H @@ -40,6 +40,11 @@ const char *get_homedir(void); char *chomp (char *str); +/* + * A thread-safe usecond sleep + */ +void xine_usec_sleep(unsigned usec); + #ifdef __cplusplus } #endif -- cgit v1.2.3