mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-23 23:42:32 +00:00
parent
64bfe233d7
commit
217f62b89d
50
repos/base/include/util/retry.h
Normal file
50
repos/base/include/util/retry.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* \brief Utility to execute a function repeatedly
|
||||||
|
* \author Norman Feske
|
||||||
|
* \author Stefan Kalkowski
|
||||||
|
* \date 2015-04-29
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _INCLUDE__UTIL__RETRY_H_
|
||||||
|
#define _INCLUDE__UTIL__RETRY_H_
|
||||||
|
|
||||||
|
namespace Genode {
|
||||||
|
|
||||||
|
template <typename EXC, typename FUNC, typename HANDLER>
|
||||||
|
auto retry(FUNC func, HANDLER handler,
|
||||||
|
unsigned attempts = ~0U) -> decltype(func());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repeatedly try to execute a function 'func'
|
||||||
|
*
|
||||||
|
* If the function 'func' throws an exception of type 'EXC', the 'handler'
|
||||||
|
* is called and the function call is retried.
|
||||||
|
*
|
||||||
|
* \param EXC exception type to handle
|
||||||
|
* \param func functor to execute
|
||||||
|
* \param handler exception handler executed if 'func' raised an exception
|
||||||
|
* of type 'EXC'
|
||||||
|
* \param attempts number of attempts to execute 'func' before giving up
|
||||||
|
* and reflecting the exception 'EXC' to the caller. If not
|
||||||
|
* specified, attempt infinitely.
|
||||||
|
*/
|
||||||
|
template <typename EXC, typename FUNC, typename HANDLER>
|
||||||
|
auto Genode::retry(FUNC func, HANDLER handler,
|
||||||
|
unsigned attempts = ~0U) -> decltype(func())
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; attempts == ~0U || i < attempts; i++)
|
||||||
|
try { return func(); }
|
||||||
|
catch (EXC) { handler(); }
|
||||||
|
|
||||||
|
throw EXC();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _INCLUDE__UTIL__RETRY_H_ */
|
26
repos/base/src/base/env/platform_env_common.h
vendored
26
repos/base/src/base/env/platform_env_common.h
vendored
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <base/env.h>
|
#include <base/env.h>
|
||||||
#include <util/arg_string.h>
|
#include <util/arg_string.h>
|
||||||
|
#include <util/retry.h>
|
||||||
#include <parent/client.h>
|
#include <parent/client.h>
|
||||||
#include <ram_session/client.h>
|
#include <ram_session/client.h>
|
||||||
#include <rm_session/client.h>
|
#include <rm_session/client.h>
|
||||||
@ -35,31 +36,6 @@ namespace Genode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Repeatedly try to execute a function 'func'
|
|
||||||
*
|
|
||||||
* If the function 'func' throws an exception of type 'EXC', the 'handler'
|
|
||||||
* is called and the function call is retried.
|
|
||||||
*
|
|
||||||
* \param EXC exception type to handle
|
|
||||||
* \param func functor to execute
|
|
||||||
* \param handler exception handler executed if 'func' raised an exception
|
|
||||||
* of type 'EXC'
|
|
||||||
* \param attempts number of attempts to execute 'func' before giving up
|
|
||||||
* and reflecting the exception 'EXC' to the caller. If not
|
|
||||||
* specified, attempt infinitely.
|
|
||||||
*/
|
|
||||||
template <typename EXC, typename FUNC, typename HANDLER>
|
|
||||||
auto retry(FUNC func, HANDLER handler, unsigned attempts = ~0U) -> decltype(func())
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; attempts == ~0U || i < attempts; i++)
|
|
||||||
try { return func(); }
|
|
||||||
catch (EXC) { handler(); }
|
|
||||||
|
|
||||||
throw EXC();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client object for a session that may get its session quota upgraded
|
* Client object for a session that may get its session quota upgraded
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user