Files
genode/os/src/drivers/timer/linux/platform_timer.cc
Norman Feske 3049c1004c Turn 'Timer::Session' into asynchronous interface
The 'Timer::Session::msleep' function is one of the last occurrences of
long-blocking RPC calls. Synchronous blocking RPC interfaces turned out
to be constant source of trouble and code complexity. I.e., a timer
client that also wants to respond to non-timer events was forced to be a
multi-threaded process. This patch replaces the blocking 'msleep' call
by a mechanism for programming timeouts and receiving wakeup signals in
an asynchronous fashion. Thereby signals originating from the timer can
be handled along with signals from other signal sources by a single
thread.

The changed interface has been tested on Linux, L4/Fiasco, OKL4, NOVA,
L4ka::Pistachio, Codezero, Fiasco.OC, and hw_pbxa9. Furthermore, this
patch adds the timer test to autopilot.

Fixes #1
2013-02-14 10:36:06 +01:00

54 lines
1.1 KiB
C++

/*
* \brief Linux-specific sleep implementation
* \author Norman Feske
* \date 2006-08-15
*/
/*
* Copyright (C) 2006-2013 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.
*/
/* Linux syscall bindings */
#include <linux_syscalls.h>
/* local includes */
#include "timer_session_component.h"
/* Linux includes */
#include <linux_syscalls.h>
#include <sys/time.h>
inline int lx_gettimeofday(struct timeval *tv, struct timeval *tz)
{
return lx_syscall(SYS_gettimeofday, tv, tz);
}
unsigned long Platform_timer::max_timeout()
{
Genode::Lock::Guard lock_guard(_lock);
return 1000*1000;
}
unsigned long Platform_timer::curr_time() const
{
struct timeval tv;
lx_gettimeofday(&tv, 0);
return tv.tv_sec*1000*1000 + tv.tv_usec;
}
void Platform_timer::_usleep(unsigned long usecs)
{
struct timespec ts;
ts.tv_sec = usecs / (1000*1000);
ts.tv_nsec = (usecs % (1000*1000)) * 1000;
if (lx_nanosleep(&ts, &ts) != 0)
throw Genode::Blocking_canceled();
}