added an implementation for nanosleep() based on snooze()

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22311 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2007-09-25 19:18:27 +00:00
parent 4bf50c9bc4
commit e4bbf18b3f
3 changed files with 37 additions and 0 deletions

View File

@ -67,6 +67,7 @@ extern struct tm *gmtime(const time_t *timer);
extern struct tm *gmtime_r(const time_t *timer, struct tm *tm); extern struct tm *gmtime_r(const time_t *timer, struct tm *tm);
extern struct tm *localtime(const time_t *timer); extern struct tm *localtime(const time_t *timer);
extern struct tm *localtime_r(const time_t *timer, struct tm *tm); extern struct tm *localtime_r(const time_t *timer, struct tm *tm);
extern int nanosleep(const struct timespec *, struct timespec *);
extern size_t strftime(char *buffer, size_t maxSize, const char *format, extern size_t strftime(char *buffer, size_t maxSize, const char *format,
const struct tm *tm); const struct tm *tm);
extern char *strptime(const char *buf, const char *format, struct tm *tm); extern char *strptime(const char *buf, const char *format, struct tm *tm);

View File

@ -12,6 +12,7 @@ MergeObject posix_time.o :
ctime.c ctime.c
difftime.c difftime.c
localtime.c localtime.c
nanosleep.c
stime.c stime.c
strftime.c strftime.c
strptime.c strptime.c

View File

@ -0,0 +1,35 @@
/*
** Copyright 2007, Jérôme Duval. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <errno.h>
#include <time.h>
#include <OS.h>
int
nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
bigtime_t ms, begin_ms;
status_t err;
if (!rqtp) {
errno = EINVAL;
return -1;
}
// round up tv_nsec
ms = rqtp->tv_sec * 1000000LL + (rqtp->tv_nsec + 999) / 1000;
begin_ms = system_time();
err = snooze(ms);
if (err == B_INTERRUPTED) {
errno = EINTR;
if (rmtp) {
bigtime_t remain_ms = ms - system_time() + begin_ms;
rmtp->tv_sec = remain_ms / 1000000;
rmtp->tv_nsec = (remain_ms - rmtp->tv_sec) * 1000;
}
return -1;
}
return 0;
}