Implement '_nanosleep()'
This patch provides an implementation of the '_nanosleep()' libc function, which blocks on a timed semaphore for the given time, but at least 10ms. This should result in better performance than creating a timer connection on every call (for thread-safety), but could still be improved. Fixes #158.
This commit is contained in:
parent
983ee6321a
commit
12e1ae9d72
|
@ -12,7 +12,7 @@ LIBS += timed_semaphore cxx
|
||||||
SRC_CC = atexit.cc dummies.cc rlimit.cc sysctl.cc readlink.cc munmap.cc \
|
SRC_CC = atexit.cc dummies.cc rlimit.cc sysctl.cc readlink.cc munmap.cc \
|
||||||
issetugid.cc errno.cc gai_strerror.cc clock_gettime.cc \
|
issetugid.cc errno.cc gai_strerror.cc clock_gettime.cc \
|
||||||
gettimeofday.cc malloc.cc progname.cc fd_alloc.cc file_operations.cc \
|
gettimeofday.cc malloc.cc progname.cc fd_alloc.cc file_operations.cc \
|
||||||
plugin.cc plugin_registry.cc select.cc exit.cc environ.cc
|
plugin.cc plugin_registry.cc select.cc exit.cc environ.cc nanosleep.cc
|
||||||
|
|
||||||
#
|
#
|
||||||
# Files from string library that are not included in libc-raw_string because
|
# Files from string library that are not included in libc-raw_string because
|
||||||
|
|
|
@ -86,7 +86,6 @@ DUMMY(-1, mkfifo)
|
||||||
DUMMY(-1, mknod)
|
DUMMY(-1, mknod)
|
||||||
DUMMY(-1, mprotect)
|
DUMMY(-1, mprotect)
|
||||||
DUMMY(-1, nanosleep)
|
DUMMY(-1, nanosleep)
|
||||||
DUMMY(-1, _nanosleep)
|
|
||||||
DUMMY(-1, __nsdefaultsrc)
|
DUMMY(-1, __nsdefaultsrc)
|
||||||
DUMMY(-1, _nsdispatch)
|
DUMMY(-1, _nsdispatch)
|
||||||
DUMMY(-1, _openat)
|
DUMMY(-1, _openat)
|
||||||
|
|
41
libports/src/lib/libc/nanosleep.cc
Normal file
41
libports/src/lib/libc/nanosleep.cc
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* \brief C-library back end
|
||||||
|
* \author Christian Prochaska
|
||||||
|
* \date 2012-03-20
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2008-2012 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU General Public License version 2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <os/timed_semaphore.h>
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
using namespace Genode;
|
||||||
|
|
||||||
|
extern "C" __attribute__((weak))
|
||||||
|
int _nanosleep(const struct timespec *req, struct timespec *rem)
|
||||||
|
{
|
||||||
|
Genode::Alarm::Time sleep_msec = (req->tv_sec * 1000) + (req->tv_nsec / 1000000);
|
||||||
|
|
||||||
|
/* Timed_semaphore does not support timeouts < 10ms */
|
||||||
|
if (sleep_msec < 10)
|
||||||
|
sleep_msec = 10;
|
||||||
|
|
||||||
|
Timed_semaphore sem(0);
|
||||||
|
try {
|
||||||
|
sem.down(sleep_msec);
|
||||||
|
} catch(Timeout_exception) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rem) {
|
||||||
|
rem->tv_sec = 0;
|
||||||
|
rem->tv_nsec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user