base: rename 'Volatile_object' to 'Reconstructible'

Fixes #2151
This commit is contained in:
Norman Feske
2016-12-01 17:37:08 +01:00
parent 6fa87e62dd
commit 25a7ea3d40
76 changed files with 421 additions and 383 deletions

View File

@ -14,7 +14,7 @@
#ifndef _INCLUDE__BASE__ATTACHED_ROM_DATASPACE_H_
#define _INCLUDE__BASE__ATTACHED_ROM_DATASPACE_H_
#include <util/volatile_object.h>
#include <util/reconstructible.h>
#include <util/xml_node.h>
#include <base/attached_dataspace.h>
#include <rom_session/connection.h>
@ -35,7 +35,7 @@ class Genode::Attached_rom_dataspace
* always be valid once constructed, a 'Attached_rom_dataspace' has
* to handle the validity of the dataspace.
*/
Lazy_volatile_object<Attached_dataspace> _ds;
Constructible<Attached_dataspace> _ds;
/**
* Try to attach the ROM module, ignore invalid dataspaces

View File

@ -311,7 +311,7 @@ class Genode::Child : protected Rpc_object<Parent>,
Env_connection<Rom_connection> _binary { _policy,
_id_space, Parent::Env::binary(), _policy.binary_name() };
Lazy_volatile_object<Env_connection<Rom_connection> > _linker { _policy,
Constructible<Env_connection<Rom_connection> > _linker { _policy,
_id_space, Parent::Env::linker(), _policy.linker_name() };
/* call 'Child_policy::init' methods for the environment sessions */

View File

@ -14,7 +14,7 @@
#ifndef _INCLUDE__BASE__ENTRYPOINT_H_
#define _INCLUDE__BASE__ENTRYPOINT_H_
#include <util/volatile_object.h>
#include <util/reconstructible.h>
#include <util/noncopyable.h>
#include <base/rpc_server.h>
#include <base/signal.h>
@ -68,12 +68,12 @@ class Genode::Entrypoint : Genode::Noncopyable
Env &_env;
Volatile_object<Rpc_entrypoint> _rpc_ep;
Reconstructible<Rpc_entrypoint> _rpc_ep;
Signal_proxy_component _signal_proxy {*this};
Capability<Signal_proxy> _signal_proxy_cap = _rpc_ep->manage(&_signal_proxy);
Volatile_object<Signal_receiver> _sig_rec;
Reconstructible<Signal_receiver> _sig_rec;
void (*_suspended_callback) () = nullptr;
void (*_resumed_callback) () = nullptr;
@ -85,13 +85,13 @@ class Genode::Entrypoint : Genode::Noncopyable
* resume mechanism.
*/
void _handle_suspend() { }
Lazy_volatile_object<Genode::Signal_handler<Entrypoint>> _suspend_dispatcher;
Constructible<Genode::Signal_handler<Entrypoint>> _suspend_dispatcher;
void _dispatch_signal(Signal &sig);
void _process_incoming_signals();
Lazy_volatile_object<Signal_proxy_thread> _signal_proxy_thread;
Constructible<Signal_proxy_thread> _signal_proxy_thread;
friend class Startup;

View File

@ -15,7 +15,7 @@
#define _INCLUDE__BASE__HEAP_H_
#include <util/list.h>
#include <util/volatile_object.h>
#include <util/reconstructible.h>
#include <ram_session/ram_session.h>
#include <region_map/region_map.h>
#include <base/allocator_avl.h>
@ -71,7 +71,7 @@ class Genode::Heap : public Allocator
};
Lock _lock;
Volatile_object<Allocator_avl> _alloc; /* local allocator */
Reconstructible<Allocator_avl> _alloc; /* local allocator */
Dataspace_pool _ds_pool; /* list of dataspaces */
size_t _quota_limit;
size_t _quota_used;

View File

@ -83,7 +83,7 @@ class Genode::Local_connection : Local_connection_base
typedef typename CONNECTION::Session_type SESSION;
Lazy_volatile_object <typename SESSION::Client> _client;
Constructible <typename SESSION::Client> _client;
public:

View File

@ -16,7 +16,7 @@
#include <util/xml_generator.h>
#include <util/list.h>
#include <util/volatile_object.h>
#include <util/reconstructible.h>
#include <session/capability.h>
#include <base/id_space.h>
#include <base/env.h>
@ -60,17 +60,17 @@ class Genode::Session_state : public Parent::Client, public Parent::Server,
Factory *_factory = nullptr;
Volatile_object<Id_space<Parent::Client>::Element> _id_at_client;
Reconstructible<Id_space<Parent::Client>::Element> _id_at_client;
Args _args;
Affinity _affinity;
public:
Lazy_volatile_object<Id_space<Parent::Server>::Element> id_at_server;
Constructible<Id_space<Parent::Server>::Element> id_at_server;
/* ID for session requests towards the parent */
Lazy_volatile_object<Id_space<Parent::Client>::Element> id_at_parent;
Constructible<Id_space<Parent::Client>::Element> id_at_parent;
Parent::Client parent_client;

View File

@ -0,0 +1,171 @@
/*
* \brief Utility for in-place (re-)construction of objects
* \author Norman Feske
* \date 2014-01-10
*/
/*
* Copyright (C) 2014 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__RECONSTRUCTIBLE_H_
#define _INCLUDE__UTIL__RECONSTRUCTIBLE_H_
#include <util/construct_at.h>
#include <base/stdint.h>
#include <util/noncopyable.h>
namespace Genode {
template<typename> class Reconstructible;
template<typename> class Constructible;
}
/**
* Place holder for an object to be repeatedly constructed and destructed
*
* This class template acts as a smart pointer that refers to an object
* contained within the smart pointer itself. The contained object may be
* repeatedly constructed and destructed while staying in the same place. This
* is useful for replacing aggregated members during the lifetime of a compound
* object.
*
* \param MT type
*/
template <typename MT>
class Genode::Reconstructible : Noncopyable
{
private:
/**
* Static reservation of memory for the embedded object
*/
char _space[sizeof(MT)] __attribute__((aligned(sizeof(addr_t))));
/**
* True if the volatile object contains a constructed object
*/
bool _constructed = false;
template <typename... ARGS> void _do_construct(ARGS &&... args)
{
construct_at<MT>(_space, args...);
_constructed = true;
}
MT *_ptr() { return reinterpret_cast<MT *>(_space); }
MT const *_const_ptr() const { return reinterpret_cast<MT const *>(_space); }
void _check_constructed() const
{
if (!_constructed)
throw Deref_unconstructed_object();
}
protected:
/**
* Dummy type used as a hook for 'Constructible' to bypass the
* default constructor by invoking the 'Reconstructible(Lazy *)'
* constructor.
*/
struct Lazy { };
/**
* Constructor that omits the initial construction of the object
*/
Reconstructible(Lazy *) { }
public:
class Deref_unconstructed_object { };
/**
* Constructor
*
* The arguments are forwarded to the constructor of the embedded
* object.
*/
template <typename... ARGS>
Reconstructible(ARGS &&... args)
{
_do_construct(args...);
}
~Reconstructible() { destruct(); }
/**
* Construct new object in place
*
* If the 'Reconstructible' already hosts a constructed object, the old
* object will be destructed first.
*/
template <typename... ARGS>
void construct(ARGS &&... args)
{
destruct();
_do_construct(args...);
}
/**
* Destruct object
*/
void destruct()
{
if (!_constructed)
return;
/* invoke destructor */
_ptr()->~MT();
_constructed = false;
}
/**
* Return true of volatile object contains a constructed object
*/
bool constructed() const { return _constructed; }
/**
* Return true of volatile object contains a constructed object
*
* \deprecated use 'constructed' instead
*/
bool is_constructed() const { return constructed(); }
/**
* Access contained object
*/
MT *operator -> () { _check_constructed(); return _ptr(); }
MT const *operator -> () const { _check_constructed(); return _const_ptr(); }
MT &operator * () { _check_constructed(); return *_ptr(); }
MT const &operator * () const { _check_constructed(); return *_const_ptr(); }
void print(Output &out) const
{
if (_constructed)
_const_ptr()->print(out);
else
out.out_string("<unconstructed>");
}
};
/**
* Reconstructible object that holds no initially constructed object
*/
template <typename MT>
struct Genode::Constructible : Reconstructible<MT>
{
template <typename... ARGS>
Constructible(ARGS &&... args)
:
Reconstructible<MT>((typename Reconstructible<MT>::Lazy *)nullptr)
{ }
};
#endif /* _INCLUDE__UTIL__RECONSTRUCTIBLE_H_ */

View File

@ -2,6 +2,8 @@
* \brief Utility for manual in-place construction of objects
* \author Norman Feske
* \date 2014-01-10
*
* \deprecated use 'util/reconstructible.h' instead
*/
/*
@ -14,158 +16,23 @@
#ifndef _INCLUDE__UTIL__VOLATILE_OBJECT_H_
#define _INCLUDE__UTIL__VOLATILE_OBJECT_H_
#include <util/construct_at.h>
#include <base/stdint.h>
#include <util/noncopyable.h>
#include <util/reconstructible.h>
#warning "'util/volatile_object.h' is deprecated, use 'util/reconstructible.h' instead (see https://github.com/genodelabs/genode/issues/2151)"
namespace Genode {
template<typename> class Volatile_object;
template<typename> class Lazy_volatile_object;
template <typename T>
struct Volatile_object : Reconstructible<T>
{
using Reconstructible<T>::Reconstructible;
};
template <typename T>
struct Lazy_volatile_object : Constructible<T>
{
using Constructible<T>::Constructible;
};
}
/**
* Place holder for an object to be repeatedly constructed and destructed
*
* This class template acts as a smart pointer that refers to an object
* contained within the smart pointer itself. The contained object may be
* repeatedly constructed and destructed while staying in the same place. This
* is useful for replacing aggregated members during the lifetime of a compound
* object.
*
* \param MT type
*/
template <typename MT>
class Genode::Volatile_object : Noncopyable
{
private:
/**
* Static reservation of memory for the embedded object
*/
char _space[sizeof(MT)] __attribute__((aligned(sizeof(addr_t))));
/**
* True if the volatile object contains a constructed object
*/
bool _constructed = false;
template <typename... ARGS> void _do_construct(ARGS &&... args)
{
construct_at<MT>(_space, args...);
_constructed = true;
}
MT *_ptr() { return reinterpret_cast<MT *>(_space); }
MT const *_const_ptr() const { return reinterpret_cast<MT const *>(_space); }
void _check_constructed() const
{
if (!_constructed)
throw Deref_unconstructed_object();
}
protected:
/**
* Dummy type used as a hook for 'Lazy_volatile_object' to bypass the
* default constructor by invoking the 'Volatile_object(Lazy *)'
* constructor.
*/
struct Lazy { };
/**
* Constructor that omits the initial construction of the object
*/
Volatile_object(Lazy *) { }
public:
class Deref_unconstructed_object { };
/**
* Constructor
*
* The arguments are forwarded to the constructor of the embedded
* object.
*/
template <typename... ARGS>
Volatile_object(ARGS &&... args)
{
_do_construct(args...);
}
~Volatile_object() { destruct(); }
/**
* Construct new object in place
*
* If the 'Volatile_object' already hosts a constructed object, the old
* object will be destructed first.
*/
template <typename... ARGS>
void construct(ARGS &&... args)
{
destruct();
_do_construct(args...);
}
/**
* Destruct object
*/
void destruct()
{
if (!_constructed)
return;
/* invoke destructor */
_ptr()->~MT();
_constructed = false;
}
/**
* Return true of volatile object contains a constructed object
*/
bool constructed() const { return _constructed; }
/**
* Return true of volatile object contains a constructed object
*
* \deprecated use 'constructed' instead
*/
bool is_constructed() const { return constructed(); }
/**
* Access contained object
*/
MT *operator -> () { _check_constructed(); return _ptr(); }
MT const *operator -> () const { _check_constructed(); return _const_ptr(); }
MT &operator * () { _check_constructed(); return *_ptr(); }
MT const &operator * () const { _check_constructed(); return *_const_ptr(); }
void print(Output &out) const
{
if (_constructed)
_const_ptr()->print(out);
else
out.out_string("<unconstructed>");
}
};
/**
* Volatile object that holds no initially constructed object
*/
template <typename MT>
struct Genode::Lazy_volatile_object : Volatile_object<MT>
{
template <typename... ARGS>
Lazy_volatile_object(ARGS &&... args)
:
Volatile_object<MT>((typename Volatile_object<MT>::Lazy *)0)
{ }
};
#endif /* _INCLUDE__UTIL__VOLATILE_OBJECT_H_ */