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:
parent
4bf50c9bc4
commit
e4bbf18b3f
@ -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 *localtime(const time_t *timer);
|
||||
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,
|
||||
const struct tm *tm);
|
||||
extern char *strptime(const char *buf, const char *format, struct tm *tm);
|
||||
|
@ -12,6 +12,7 @@ MergeObject posix_time.o :
|
||||
ctime.c
|
||||
difftime.c
|
||||
localtime.c
|
||||
nanosleep.c
|
||||
stime.c
|
||||
strftime.c
|
||||
strptime.c
|
||||
|
35
src/system/libroot/posix/time/nanosleep.c
Normal file
35
src/system/libroot/posix/time/nanosleep.c
Normal 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user