mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-19 07:38:28 +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
@ -35,7 +35,7 @@ enum { verbose_atexit = false };
|
||||
/**
|
||||
* Dummy for symbol that is normally provided by '_main.cc'
|
||||
*/
|
||||
int genode___cxa_atexit(void (*func)(void*), void *arg, void *dso)
|
||||
int genode___cxa_atexit(void (*)(void*), void *, void *)
|
||||
{
|
||||
if (verbose_atexit)
|
||||
Genode::raw("genode___cxa_atexit called, not implemented\n");
|
||||
@ -146,7 +146,9 @@ int main()
|
||||
|
||||
/* host libc includes */
|
||||
#define size_t __SIZE_TYPE__ /* see comment in 'linux_syscalls.h' */
|
||||
#pragma GCC diagnostic ignored "-Weffc++"
|
||||
#include <pthread.h>
|
||||
#pragma GCC diagnostic pop
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#undef size_t
|
||||
@ -161,7 +163,7 @@ static pthread_key_t tls_key()
|
||||
{
|
||||
struct Tls_key
|
||||
{
|
||||
pthread_key_t key;
|
||||
pthread_key_t key { };
|
||||
|
||||
Tls_key()
|
||||
{
|
||||
@ -188,29 +190,31 @@ namespace Genode {
|
||||
* 'Stack'. But the POSIX threads of hybrid programs have no 'Stack'
|
||||
* object. So we have to keep the meta data here.
|
||||
*/
|
||||
Native_thread native_thread;
|
||||
Native_thread native_thread { };
|
||||
|
||||
/**
|
||||
* Filled out by 'thread_start' function in the stack of the new
|
||||
* thread
|
||||
*/
|
||||
Thread * const thread_base;
|
||||
Thread &thread_base;
|
||||
|
||||
/**
|
||||
* POSIX thread handle
|
||||
*/
|
||||
pthread_t pt;
|
||||
pthread_t pt { };
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param thread associated 'Thread' object
|
||||
*/
|
||||
Meta_data(Thread *thread) : thread_base(thread)
|
||||
Meta_data(Thread *thread) : thread_base(*thread)
|
||||
{
|
||||
native_thread.meta_data = this;
|
||||
}
|
||||
|
||||
virtual ~Meta_data() { }
|
||||
|
||||
/**
|
||||
* Used to block the constructor until the new thread has initialized
|
||||
* 'id'
|
||||
@ -247,17 +251,17 @@ namespace Genode {
|
||||
* Used to block the constructor until the new thread has initialized
|
||||
* 'id'
|
||||
*/
|
||||
Barrier _construct_lock;
|
||||
Barrier _construct_lock { };
|
||||
|
||||
/**
|
||||
* Used to block the new thread until 'start' is called
|
||||
*/
|
||||
Barrier _start_lock;
|
||||
Barrier _start_lock { };
|
||||
|
||||
/**
|
||||
* Used to block the 'join()' function until the 'entry()' is done
|
||||
*/
|
||||
Barrier _join_lock;
|
||||
Barrier _join_lock { };
|
||||
|
||||
public:
|
||||
|
||||
@ -362,7 +366,7 @@ static void adopt_thread(Native_thread::Meta_data *meta_data)
|
||||
/*
|
||||
* Initialize thread meta data
|
||||
*/
|
||||
Native_thread &native_thread = meta_data->thread_base->native_thread();
|
||||
Native_thread &native_thread = meta_data->thread_base.native_thread();
|
||||
native_thread.tid = lx_gettid();
|
||||
native_thread.pid = lx_getpid();
|
||||
}
|
||||
@ -402,11 +406,11 @@ namespace {
|
||||
return true;
|
||||
}
|
||||
|
||||
void free(void *addr, size_t size) override { ::free(addr); }
|
||||
void free(void *addr, size_t) override { ::free(addr); }
|
||||
|
||||
bool need_size_for_free() const override { return false; }
|
||||
|
||||
size_t overhead(size_t size) const override { return 0; }
|
||||
size_t overhead(size_t) const override { return 0; }
|
||||
};
|
||||
}
|
||||
|
||||
@ -423,7 +427,7 @@ Thread *Thread::myself()
|
||||
void * const tls = pthread_getspecific(tls_key());
|
||||
|
||||
if (tls != 0)
|
||||
return ((Native_thread::Meta_data *)tls)->thread_base;
|
||||
return &((Native_thread::Meta_data *)tls)->thread_base;
|
||||
|
||||
bool const called_by_main_thread = (lx_getpid() == lx_gettid());
|
||||
if (called_by_main_thread)
|
||||
@ -457,7 +461,7 @@ Thread *Thread::myself()
|
||||
* Initialize 'Thread::_native_thread' to point to the default-
|
||||
* constructed 'Native_thread' (part of 'Meta_data').
|
||||
*/
|
||||
meta_data->thread_base->_native_thread = &meta_data->native_thread;
|
||||
meta_data->thread_base._native_thread = &meta_data->native_thread;
|
||||
adopt_thread(meta_data);
|
||||
|
||||
return thread;
|
||||
@ -482,9 +486,9 @@ void Thread::join()
|
||||
Native_thread &Thread::native_thread() { return *_native_thread; }
|
||||
|
||||
|
||||
Thread::Thread(size_t weight, const char *name, size_t stack_size,
|
||||
Type type, Cpu_session * cpu_sess, Affinity::Location)
|
||||
: _cpu_session(cpu_sess)
|
||||
Thread::Thread(size_t weight, const char *name, size_t /* stack size */,
|
||||
Type, Cpu_session * cpu_sess, Affinity::Location)
|
||||
: _cpu_session(cpu_sess), _affinity(), _join_lock()
|
||||
{
|
||||
Native_thread::Meta_data *meta_data =
|
||||
new (global_alloc()) Thread_meta_data_created(this);
|
||||
@ -513,7 +517,7 @@ Thread::Thread(size_t weight, const char *name, size_t stack_size,
|
||||
: Thread(weight, name, stack_size, type, &_env_ptr->cpu()) { }
|
||||
|
||||
|
||||
Thread::Thread(Env &env, Name const &name, size_t stack_size, Location location,
|
||||
Thread::Thread(Env &, Name const &name, size_t stack_size, Location location,
|
||||
Weight weight, Cpu_session &cpu)
|
||||
: Thread(weight.value, name.string(), stack_size, NORMAL,
|
||||
&cpu, location)
|
||||
|
Reference in New Issue
Block a user