mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-15 13:48:17 +00:00
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository. To adapt existing components to fix violations of the best practices suggested by "Effective C++" as reported by the -Weffc++ compiler argument. The changes follow the patterns outlined below: * A class with virtual functions can no longer publicly inherit base classed without a vtable. The inherited object may either be moved to a member variable, or inherited privately. The latter would be used for classes that inherit 'List::Element' or 'Avl_node'. In order to enable the 'List' and 'Avl_tree' to access the meta data, the 'List' must become a friend. * Instead of adding a virtual destructor to abstract base classes, we inherit the new 'Interface' class, which contains a virtual destructor. This way, single-line abstract base classes can stay as compact as they are now. The 'Interface' utility resides in base/include/util/interface.h. * With the new warnings enabled, all member variables must be explicitly initialized. Basic types may be initialized with '='. All other types are initialized with braces '{ ... }' or as class initializers. If basic types and non-basic types appear in a row, it is nice to only use the brace syntax (also for basic types) and align the braces. * If a class contains pointers as members, it must now also provide a copy constructor and assignment operator. In the most cases, one would make them private, effectively disallowing the objects to be copied. Unfortunately, this warning cannot be fixed be inheriting our existing 'Noncopyable' class (the compiler fails to detect that the inheriting class cannot be copied and still gives the error). For now, we have to manually add declarations for both the copy constructor and assignment operator as private class members. Those declarations should be prepended with a comment like this: /* * Noncopyable */ Thread(Thread const &); Thread &operator = (Thread const &); In the future, we should revisit these places and try to replace the pointers with references. In the presence of at least one reference member, the compiler would no longer implicitly generate a copy constructor. So we could remove the manual declaration. Issue #465
This commit is contained in:
committed by
Christian Helmuth
parent
2a33d9aa76
commit
eba9c15746
@ -61,7 +61,7 @@ static inline bool ipc_error(l4_msgtag_t tag, bool print)
|
||||
}
|
||||
|
||||
|
||||
enum { INVALID_BADGE = ~0UL };
|
||||
static constexpr unsigned long INVALID_BADGE = ~0UL;
|
||||
|
||||
|
||||
/**
|
||||
@ -86,7 +86,7 @@ static unsigned long extract_msg_from_utcb(l4_msgtag_t tag,
|
||||
{
|
||||
unsigned num_msg_words = l4_msgtag_words(tag);
|
||||
|
||||
l4_mword_t const *msg_words = (l4_mword_t const *)l4_utcb_mr();
|
||||
l4_umword_t const *msg_words = (l4_umword_t const *)l4_utcb_mr();
|
||||
|
||||
/* each message has at least the protocol word and the capability count */
|
||||
if (num_msg_words < 2)
|
||||
@ -96,7 +96,7 @@ static unsigned long extract_msg_from_utcb(l4_msgtag_t tag,
|
||||
unsigned long const protocol_word = *msg_words++;
|
||||
|
||||
/* read number of capability arguments from second message word */
|
||||
unsigned long const num_caps = min(*msg_words, Msgbuf_base::MAX_CAPS_PER_MSG);
|
||||
size_t const num_caps = min(*msg_words, Msgbuf_base::MAX_CAPS_PER_MSG);
|
||||
msg_words++;
|
||||
|
||||
num_msg_words -= 2;
|
||||
@ -259,7 +259,7 @@ static l4_msgtag_t copy_msgbuf_to_utcb(Msgbuf_base &snd_msg,
|
||||
|
||||
Rpc_exception_code Genode::ipc_call(Native_capability dst,
|
||||
Msgbuf_base &snd_msg, Msgbuf_base &rcv_msg,
|
||||
size_t rcv_caps)
|
||||
size_t)
|
||||
{
|
||||
Receive_window rcv_window;
|
||||
rcv_window.init();
|
||||
@ -269,7 +269,7 @@ Rpc_exception_code Genode::ipc_call(Native_capability dst,
|
||||
l4_msgtag_t const call_tag = copy_msgbuf_to_utcb(snd_msg, dst.local_name());
|
||||
|
||||
addr_t rcv_cap_sel = rcv_window.rcv_cap_sel_base();
|
||||
for (int i = 0; i < Msgbuf_base::MAX_CAPS_PER_MSG; i++) {
|
||||
for (size_t i = 0; i < Msgbuf_base::MAX_CAPS_PER_MSG; i++) {
|
||||
l4_utcb_br()->br[i] = rcv_cap_sel | L4_RCV_ITEM_SINGLE_CAP;
|
||||
rcv_cap_sel += L4_CAP_SIZE;
|
||||
}
|
||||
@ -300,7 +300,7 @@ static bool badge_matches_label(unsigned long badge, unsigned long label)
|
||||
}
|
||||
|
||||
|
||||
void Genode::ipc_reply(Native_capability caller, Rpc_exception_code exc,
|
||||
void Genode::ipc_reply(Native_capability, Rpc_exception_code exc,
|
||||
Msgbuf_base &snd_msg)
|
||||
{
|
||||
l4_msgtag_t tag = copy_msgbuf_to_utcb(snd_msg, exc.value);
|
||||
@ -311,7 +311,7 @@ void Genode::ipc_reply(Native_capability caller, Rpc_exception_code exc,
|
||||
}
|
||||
|
||||
|
||||
Genode::Rpc_request Genode::ipc_reply_wait(Reply_capability const &last_caller,
|
||||
Genode::Rpc_request Genode::ipc_reply_wait(Reply_capability const &,
|
||||
Rpc_exception_code exc,
|
||||
Msgbuf_base &reply_msg,
|
||||
Msgbuf_base &request_msg)
|
||||
@ -324,7 +324,7 @@ Genode::Rpc_request Genode::ipc_reply_wait(Reply_capability const &last_caller,
|
||||
|
||||
/* prepare receive window in UTCB */
|
||||
addr_t rcv_cap_sel = rcv_window.rcv_cap_sel_base();
|
||||
for (int i = 0; i < Msgbuf_base::MAX_CAPS_PER_MSG; i++) {
|
||||
for (size_t i = 0; i < Msgbuf_base::MAX_CAPS_PER_MSG; i++) {
|
||||
l4_utcb_br()->br[i] = rcv_cap_sel | L4_RCV_ITEM_SINGLE_CAP;
|
||||
rcv_cap_sel += L4_CAP_SIZE;
|
||||
}
|
||||
|
@ -34,12 +34,12 @@ using namespace Genode;
|
||||
|
||||
Signal_source_client::Signal_source_client(Capability<Signal_source> cap)
|
||||
:
|
||||
Rpc_client<Foc_signal_source>(static_cap_cast<Foc_signal_source>(cap))
|
||||
{
|
||||
using namespace Fiasco;
|
||||
Rpc_client<Foc_signal_source>(static_cap_cast<Foc_signal_source>(cap)),
|
||||
|
||||
/* request mapping of semaphore capability selector */
|
||||
_sem = call<Rpc_request_semaphore>();
|
||||
_sem(call<Rpc_request_semaphore>())
|
||||
{
|
||||
using namespace Fiasco;
|
||||
|
||||
Foc_native_cpu_client cpu_client(env_deprecated()->cpu_session()->native_cpu());
|
||||
Native_capability thread_cap = cpu_client.native_cap(Thread::myself()->cap());
|
||||
|
Reference in New Issue
Block a user