genode/os/include/timer_session/timer_session.h
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

80 lines
1.9 KiB
C++

/*
* \brief Timer session interface
* \author Norman Feske
* \author Markus Partheymueller
* \date 2006-08-15
*/
/*
* Copyright (C) 2006-2013 Genode Labs GmbH
* Copyright (C) 2012 Intel Corporation
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__TIMER_SESSION__TIMER_SESSION_H_
#define _INCLUDE__TIMER_SESSION__TIMER_SESSION_H_
#include <base/signal.h>
#include <session/session.h>
namespace Timer {
using namespace Genode;
struct Session : Genode::Session
{
static const char *service_name() { return "Timer"; }
virtual ~Session() { }
/**
* Program single timeout (in microseconds)
*/
virtual void trigger_once(unsigned us) = 0;
/**
* Program periodic timeout (in microseconds)
*/
virtual void trigger_periodic(unsigned us) = 0;
/**
* Register timeout signal handler
*/
virtual void sigh(Signal_context_capability sigh) = 0;
/**
* Return number of elapsed milliseconds since session creation
*/
virtual unsigned long elapsed_ms() const = 0;
/**
* Client-side convenience function for sleeping the specified number
* of milliseconds
*/
virtual void msleep(unsigned ms) = 0;
/**
* Client-side convenience function for sleeping the specified number
* of microseconds
*/
virtual void usleep(unsigned us) = 0;
/*********************
** RPC declaration **
*********************/
GENODE_RPC(Rpc_trigger_once, void, trigger_once, unsigned);
GENODE_RPC(Rpc_trigger_periodic, void, trigger_periodic, unsigned);
GENODE_RPC(Rpc_sigh, void, sigh, Genode::Signal_context_capability);
GENODE_RPC(Rpc_elapsed_ms, unsigned long, elapsed_ms);
GENODE_RPC_INTERFACE(Rpc_trigger_once, Rpc_trigger_periodic,
Rpc_sigh, Rpc_elapsed_ms);
};
}
#endif /* _INCLUDE__TIMER_SESSION__TIMER_SESSION_H_ */