mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-29 10:08:53 +00:00
eba9c15746
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
165 lines
4.7 KiB
C++
165 lines
4.7 KiB
C++
/*
|
|
* \brief CPU thread interface
|
|
* \author Norman Feske
|
|
* \date 2016-05-10
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2016-2017 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
*/
|
|
|
|
#ifndef _INCLUDE__CPU_THREAD__CPU_THREAD_H_
|
|
#define _INCLUDE__CPU_THREAD__CPU_THREAD_H_
|
|
|
|
#include <base/stdint.h>
|
|
#include <base/exception.h>
|
|
#include <base/thread_state.h>
|
|
#include <base/signal.h>
|
|
#include <base/affinity.h>
|
|
#include <dataspace/capability.h>
|
|
|
|
namespace Genode { struct Cpu_thread; }
|
|
|
|
|
|
struct Genode::Cpu_thread : Interface
|
|
{
|
|
class State_access_failed : public Exception { };
|
|
|
|
/**
|
|
* Get dataspace of the thread's user-level thread-control block (UTCB)
|
|
*/
|
|
virtual Dataspace_capability utcb() = 0;
|
|
|
|
/**
|
|
* Modify instruction and stack pointer of thread - start the thread
|
|
*
|
|
* \param thread thread to start
|
|
* \param ip initial instruction pointer
|
|
* \param sp initial stack pointer
|
|
*/
|
|
virtual void start(addr_t ip, addr_t sp) = 0;
|
|
|
|
/**
|
|
* Pause the thread
|
|
*
|
|
* After calling this method, the execution of the thread can be
|
|
* continued by calling 'resume'.
|
|
*/
|
|
virtual void pause() = 0;
|
|
|
|
/**
|
|
* Resume the thread
|
|
*/
|
|
virtual void resume() = 0;
|
|
|
|
/**
|
|
* Cancel a currently blocking operation
|
|
*/
|
|
virtual void cancel_blocking() = 0;
|
|
|
|
/**
|
|
* Get the current thread state
|
|
*
|
|
* \return state of the targeted thread
|
|
* \throw State_access_failed
|
|
*/
|
|
virtual Thread_state state() = 0;
|
|
|
|
/**
|
|
* Override the current thread state
|
|
*
|
|
* \param state state that shall be applied
|
|
* \throw State_access_failed
|
|
*/
|
|
virtual void state(Thread_state const &state) = 0;
|
|
|
|
/**
|
|
* Register signal handler for exceptions of the thread
|
|
*
|
|
* On Linux, this exception is delivered when the process triggers
|
|
* a SIGCHLD. On other platforms, this exception is delivered on
|
|
* the occurrence of CPU exceptions such as division by zero.
|
|
*/
|
|
virtual void exception_sigh(Signal_context_capability handler) = 0;
|
|
|
|
/**
|
|
* Enable/disable single stepping
|
|
*
|
|
* Since this method is currently supported by a small number of
|
|
* platforms, we provide a default implementation
|
|
*
|
|
* \param enabled true = enable single-step mode; false = disable
|
|
*/
|
|
virtual void single_step(bool enabled) = 0;
|
|
|
|
/**
|
|
* Define affinity of thread to one or multiple CPU nodes
|
|
*
|
|
* In the normal case, a thread is assigned to a single CPU. Specifying
|
|
* more than one CPU node is supposed to principally allow a CPU service to
|
|
* balance the load of threads among multiple CPUs.
|
|
*
|
|
* \param location location within the affinity space of the thread's
|
|
* CPU session
|
|
*/
|
|
virtual void affinity(Affinity::Location location) = 0;
|
|
|
|
/**
|
|
* Request index within the trace control block of the thread's CPU session
|
|
*
|
|
* The trace control dataspace contains the control blocks for all threads
|
|
* of the CPU session. Each thread gets assigned a different index by the
|
|
* CPU service.
|
|
*/
|
|
virtual unsigned trace_control_index() = 0;
|
|
|
|
/**
|
|
* Request trace buffer for the thread
|
|
*
|
|
* The trace buffer is not accounted to the CPU session. It is owned by a
|
|
* TRACE session.
|
|
*/
|
|
virtual Dataspace_capability trace_buffer() = 0;
|
|
|
|
/**
|
|
* Request trace policy
|
|
*
|
|
* The trace policy buffer is not accounted to the CPU session. It is owned
|
|
* by a TRACE session.
|
|
*/
|
|
virtual Dataspace_capability trace_policy() = 0;
|
|
|
|
|
|
/*********************
|
|
** RPC declaration **
|
|
*********************/
|
|
|
|
GENODE_RPC(Rpc_utcb, Dataspace_capability, utcb);
|
|
GENODE_RPC(Rpc_start, void, start, addr_t, addr_t);
|
|
GENODE_RPC(Rpc_pause, void, pause);
|
|
GENODE_RPC(Rpc_resume, void, resume);
|
|
GENODE_RPC(Rpc_cancel_blocking, void, cancel_blocking);
|
|
GENODE_RPC_THROW(Rpc_get_state, Thread_state, state,
|
|
GENODE_TYPE_LIST(State_access_failed));
|
|
GENODE_RPC_THROW(Rpc_set_state, void, state,
|
|
GENODE_TYPE_LIST(State_access_failed),
|
|
Thread_state const &);
|
|
GENODE_RPC(Rpc_exception_sigh, void, exception_sigh, Signal_context_capability);
|
|
GENODE_RPC(Rpc_single_step, void, single_step, bool);
|
|
GENODE_RPC(Rpc_affinity, void, affinity, Affinity::Location);
|
|
GENODE_RPC(Rpc_trace_control_index, unsigned, trace_control_index);
|
|
GENODE_RPC(Rpc_trace_buffer, Dataspace_capability, trace_buffer);
|
|
GENODE_RPC(Rpc_trace_policy, Dataspace_capability, trace_policy);
|
|
|
|
GENODE_RPC_INTERFACE(Rpc_utcb, Rpc_start, Rpc_pause, Rpc_resume,
|
|
Rpc_cancel_blocking, Rpc_set_state, Rpc_get_state,
|
|
Rpc_exception_sigh, Rpc_single_step, Rpc_affinity,
|
|
Rpc_trace_control_index, Rpc_trace_buffer,
|
|
Rpc_trace_policy);
|
|
};
|
|
|
|
#endif /* _INCLUDE__CPU_THREAD__CPU_THREAD_H_ */
|