forked from Imagelibrary/rtems
librtemscxx: Fix white space to match the coding standard
This commit is contained in:
@@ -50,19 +50,19 @@ namespace rtems
|
|||||||
{
|
{
|
||||||
const rtems_status_code sc;
|
const rtems_status_code sc;
|
||||||
public:
|
public:
|
||||||
runtime_error (const rtems_status_code sc);
|
runtime_error(const rtems_status_code sc);
|
||||||
runtime_error (const rtems_status_code sc, const std::string& what);
|
runtime_error(const rtems_status_code sc, const std::string& what);
|
||||||
runtime_error (const rtems_status_code sc, const char* what);
|
runtime_error(const rtems_status_code sc, const char* what);
|
||||||
~runtime_error ();
|
~runtime_error();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw a rtems::runtime_error exception if the RTEMS status code is
|
* Throw a rtems::runtime_error exception if the RTEMS status code is
|
||||||
* not RTEMS_SUCCESSFUL.
|
* not RTEMS_SUCCESSFUL.
|
||||||
*/
|
*/
|
||||||
void runtime_error_check (const rtems_status_code sc);
|
void runtime_error_check(const rtems_status_code sc);
|
||||||
void runtime_error_check (const rtems_status_code sc, const std::string& what);
|
void runtime_error_check(const rtems_status_code sc, const std::string& what);
|
||||||
void runtime_error_check (const rtems_status_code sc, const char* what);
|
void runtime_error_check(const rtems_status_code sc, const char* what);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -83,14 +83,14 @@ namespace rtems
|
|||||||
* executing thread. The stack size is set to the configured minimum
|
* executing thread. The stack size is set to the configured minimum
|
||||||
* stack size.
|
* stack size.
|
||||||
*/
|
*/
|
||||||
attributes ();
|
attributes();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy construct the thread attributes.
|
* Copy construct the thread attributes.
|
||||||
*
|
*
|
||||||
* @param attr The attributes to copy.
|
* @param attr The attributes to copy.
|
||||||
*/
|
*/
|
||||||
attributes (const attributes& attr);
|
attributes(const attributes& attr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the name of the thread. The thread is a classic API thread and
|
* Set the name of the thread. The thread is a classic API thread and
|
||||||
@@ -98,7 +98,7 @@ namespace rtems
|
|||||||
*
|
*
|
||||||
* @param name The name as a string.
|
* @param name The name as a string.
|
||||||
*/
|
*/
|
||||||
void set_name (const std::string& name);
|
void set_name(const std::string& name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the name of the thread. The thread is a classic API thread and
|
* Set the name of the thread. The thread is a classic API thread and
|
||||||
@@ -106,28 +106,28 @@ namespace rtems
|
|||||||
*
|
*
|
||||||
* @param name The name as a string.
|
* @param name The name as a string.
|
||||||
*/
|
*/
|
||||||
void set_name (const char* name);
|
void set_name(const char* name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the thread.
|
* Get the name of the thread.
|
||||||
*
|
*
|
||||||
* @retval const std::string& The name of the thread.
|
* @retval const std::string& The name of the thread.
|
||||||
*/
|
*/
|
||||||
const std::string& get_name () const;
|
const std::string& get_name() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the priority of the thread.
|
* Set the priority of the thread.
|
||||||
*
|
*
|
||||||
* @param priority The POSIX API priority of the thread.
|
* @param priority The POSIX API priority of the thread.
|
||||||
*/
|
*/
|
||||||
void set_priority (int priority);
|
void set_priority(int priority);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the POSIX API priority of the thread.
|
* Get the POSIX API priority of the thread.
|
||||||
*
|
*
|
||||||
* @retval int The POSIX API thread priority.
|
* @retval int The POSIX API thread priority.
|
||||||
*/
|
*/
|
||||||
int get_priority () const;
|
int get_priority() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the stack size. If the size is less than the configured minimum
|
* Set the stack size. If the size is less than the configured minimum
|
||||||
@@ -135,38 +135,38 @@ namespace rtems
|
|||||||
*
|
*
|
||||||
* @param size The stack size in bytes.
|
* @param size The stack size in bytes.
|
||||||
*/
|
*/
|
||||||
void set_stack_size (size_t size);
|
void set_stack_size(size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the stack size.
|
* Get the stack size.
|
||||||
*
|
*
|
||||||
* @retval size_t The stack size in bytes.
|
* @retval size_t The stack size in bytes.
|
||||||
*/
|
*/
|
||||||
size_t get_stack_size () const;
|
size_t get_stack_size() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the scheduler name. If not set no scheduler is set.
|
* Set the scheduler name. If not set no scheduler is set.
|
||||||
*
|
*
|
||||||
* @parrm scheduler The name of the scheduler.
|
* @parrm scheduler The name of the scheduler.
|
||||||
*/
|
*/
|
||||||
void set_scheduler (const std::string& scheduler);
|
void set_scheduler(const std::string& scheduler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the scheduler name. If not set no scheduler is set.
|
* Set the scheduler name. If not set no scheduler is set.
|
||||||
*/
|
*/
|
||||||
void set_scheduler (const char* scheduler);
|
void set_scheduler(const char* scheduler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get scheduler name.
|
* Get scheduler name.
|
||||||
*/
|
*/
|
||||||
const std::string& get_scheduler ();
|
const std::string& get_scheduler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the attributes' scheduler attribute for the thread.
|
* Get the attributes' scheduler attribute for the thread.
|
||||||
*
|
*
|
||||||
* @return sched_attr The attributes' scheduler attribute
|
* @return sched_attr The attributes' scheduler attribute
|
||||||
*/
|
*/
|
||||||
sched_attr get_scheduler_attr () const;
|
sched_attr get_scheduler_attr() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the scheduler policy for the thread. This call sets the
|
* Set the scheduler policy for the thread. This call sets the
|
||||||
@@ -174,12 +174,12 @@ namespace rtems
|
|||||||
*
|
*
|
||||||
* @param policy The scheduler policy.
|
* @param policy The scheduler policy.
|
||||||
*/
|
*/
|
||||||
void set_scheduler_policy (sched_policy policy);
|
void set_scheduler_policy(sched_policy policy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the scheduler policy for the thread.
|
* Get the scheduler policy for the thread.
|
||||||
*/
|
*/
|
||||||
sched_policy get_scheduler_policy () const;
|
sched_policy get_scheduler_policy() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commit any changes to the executing thread.
|
* Commit any changes to the executing thread.
|
||||||
@@ -187,7 +187,7 @@ namespace rtems
|
|||||||
* @note only the priority and attribute of a thread can be changed. The
|
* @note only the priority and attribute of a thread can be changed. The
|
||||||
* name and stack size are ignored.
|
* name and stack size are ignored.
|
||||||
*/
|
*/
|
||||||
void commit ();
|
void commit();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the attribute values from the executing thread. The attributes
|
* Update the attribute values from the executing thread. The attributes
|
||||||
@@ -197,18 +197,18 @@ namespace rtems
|
|||||||
* this method is called. Except for the name and stack size any local
|
* this method is called. Except for the name and stack size any local
|
||||||
* changes made will lost then the update call is made.
|
* changes made will lost then the update call is made.
|
||||||
*/
|
*/
|
||||||
void update ();
|
void update();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy operator.
|
* Copy operator.
|
||||||
*/
|
*/
|
||||||
attributes& operator= (const attributes& attr);
|
attributes& operator=(const attributes& attr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The comparison operator does not check the name or stack size
|
* The comparison operator does not check the name or stack size
|
||||||
* of a thread.
|
* of a thread.
|
||||||
*/
|
*/
|
||||||
bool operator== (const attributes& attr) const;
|
bool operator==(const attributes& attr) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name; /**< Name of the thread */
|
std::string name; /**< Name of the thread */
|
||||||
@@ -243,7 +243,7 @@ namespace rtems
|
|||||||
*/
|
*/
|
||||||
class thread
|
class thread
|
||||||
{
|
{
|
||||||
friend void* thread_generic_entry (void* arg);
|
friend void* thread_generic_entry(void* arg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base state class to interface to derived template of the thread
|
* Base state class to interface to derived template of the thread
|
||||||
@@ -251,9 +251,9 @@ namespace rtems
|
|||||||
*/
|
*/
|
||||||
struct state_base
|
struct state_base
|
||||||
{
|
{
|
||||||
virtual ~state_base ();
|
virtual ~state_base();
|
||||||
virtual const attributes get_attributes () = 0;
|
virtual const attributes get_attributes() = 0;
|
||||||
virtual void run () = 0;
|
virtual void run() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -278,23 +278,23 @@ namespace rtems
|
|||||||
*/
|
*/
|
||||||
class id {
|
class id {
|
||||||
public:
|
public:
|
||||||
id () noexcept : id_ (0) { }
|
id() noexcept : id_(0) { }
|
||||||
explicit id (pthread_t id_) : id_ (id_) { }
|
explicit id(pthread_t id_) : id_(id_) { }
|
||||||
private:
|
private:
|
||||||
pthread_t id_;
|
pthread_t id_;
|
||||||
|
|
||||||
friend class thread;
|
friend class thread;
|
||||||
friend bool operator== (thread::id l, thread::id r) noexcept;
|
friend bool operator==(thread::id l, thread::id r) noexcept;
|
||||||
|
|
||||||
template<class CharT, class Traits>
|
template<class CharT, class Traits>
|
||||||
friend std::basic_ostream<CharT, Traits>&
|
friend std::basic_ostream<CharT, Traits>&
|
||||||
operator<< (std::basic_ostream<CharT, Traits>& out, thread::id id_);
|
operator<<(std::basic_ostream<CharT, Traits>& out, thread::id id_);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default thread constructions.
|
* The default thread constructions.
|
||||||
*/
|
*/
|
||||||
thread () noexcept = default;
|
thread() noexcept = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The std::thread equivalent constructor. The attributes will be the
|
* The std::thread equivalent constructor. The attributes will be the
|
||||||
@@ -302,7 +302,7 @@ namespace rtems
|
|||||||
* configured minimum stack size.
|
* configured minimum stack size.
|
||||||
*/
|
*/
|
||||||
template<typename F, typename... Args>
|
template<typename F, typename... Args>
|
||||||
explicit thread (F&& func, Args&&... args);
|
explicit thread(F&& func, Args&&... args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a thread with the provided attributes. The entry point and
|
* Create a thread with the provided attributes. The entry point and
|
||||||
@@ -310,12 +310,12 @@ namespace rtems
|
|||||||
*/
|
*/
|
||||||
template <typename A, typename F, typename ...Args,
|
template <typename A, typename F, typename ...Args,
|
||||||
class = enable_if_attributes<A>>
|
class = enable_if_attributes<A>>
|
||||||
explicit thread (A&& attr, F&& func, Args&&... args);
|
explicit thread(A&& attr, F&& func, Args&&... args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the thread id to this instance.
|
* Move the thread id to this instance.
|
||||||
*/
|
*/
|
||||||
thread& operator= (thread&& thread_);
|
thread& operator=(thread&& thread_);
|
||||||
|
|
||||||
void swap(thread& thread_) noexcept;
|
void swap(thread& thread_) noexcept;
|
||||||
|
|
||||||
@@ -328,10 +328,10 @@ namespace rtems
|
|||||||
/*
|
/*
|
||||||
* Constrain use. These are not available.
|
* Constrain use. These are not available.
|
||||||
*/
|
*/
|
||||||
thread (thread&) = delete;
|
thread(thread&) = delete;
|
||||||
thread (const thread&) = delete;
|
thread(const thread&) = delete;
|
||||||
thread (const thread&&) = delete;
|
thread(const thread&&) = delete;
|
||||||
thread& operator= (const thread&) = delete;
|
thread& operator=(const thread&) = delete;
|
||||||
|
|
||||||
std::thread::id get_id() const noexcept;
|
std::thread::id get_id() const noexcept;
|
||||||
|
|
||||||
@@ -349,20 +349,20 @@ namespace rtems
|
|||||||
Parms p;
|
Parms p;
|
||||||
|
|
||||||
template<size_t Index>
|
template<size_t Index>
|
||||||
static std::__tuple_element_t<Index, Parms>&& declval ();
|
static std::__tuple_element_t<Index, Parms>&& declval();
|
||||||
|
|
||||||
template<size_t... Ind>
|
template<size_t... Ind>
|
||||||
auto invoke (std::_Index_tuple<Ind...>)
|
auto invoke(std::_Index_tuple<Ind...>)
|
||||||
noexcept (noexcept (std::invoke (declval<Ind>()...)))
|
noexcept(noexcept(std::invoke(declval<Ind>()...)))
|
||||||
-> decltype (std::invoke (declval<Ind> ()...)) {
|
-> decltype(std::invoke(declval<Ind>()...)) {
|
||||||
return std::invoke (std::get<Ind> (std::move (p))...);
|
return std::invoke(std::get<Ind>(std::move(p))...);
|
||||||
}
|
}
|
||||||
|
|
||||||
using indices =
|
using indices =
|
||||||
typename std::_Build_index_tuple<std::tuple_size<Parms>::value>::__type;
|
typename std::_Build_index_tuple<std::tuple_size<Parms>::value>::__type;
|
||||||
|
|
||||||
void run () {
|
void run() {
|
||||||
invoke (indices ());
|
invoke(indices());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -376,17 +376,17 @@ namespace rtems
|
|||||||
const attributes attr;
|
const attributes attr;
|
||||||
Invoker i;
|
Invoker i;
|
||||||
|
|
||||||
state (const attributes& attr, Invoker&& i)
|
state(const attributes& attr, Invoker&& i)
|
||||||
: attr (attr),
|
: attr(attr),
|
||||||
i (std::forward<Invoker> (i)) {
|
i(std::forward<Invoker>(i)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const attributes get_attributes () override {
|
const attributes get_attributes() override {
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void run () override {
|
void run() override {
|
||||||
i.run ();
|
i.run();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -396,9 +396,9 @@ namespace rtems
|
|||||||
*/
|
*/
|
||||||
template<typename Invoker>
|
template<typename Invoker>
|
||||||
static state_ptr
|
static state_ptr
|
||||||
make_state (const attributes& attr, Invoker&& i) {
|
make_state(const attributes& attr, Invoker&& i) {
|
||||||
using state_impl = state<Invoker>;
|
using state_impl = state<Invoker>;
|
||||||
return state_ptr{ new state_impl (attr, std::forward<Invoker> (i)) };
|
return state_ptr{ new state_impl(attr, std::forward<Invoker>(i)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -413,11 +413,11 @@ namespace rtems
|
|||||||
*/
|
*/
|
||||||
template<typename F, typename... Args>
|
template<typename F, typename... Args>
|
||||||
static invoker<decayed_tuple<F, Args...>>
|
static invoker<decayed_tuple<F, Args...>>
|
||||||
make_invoker (F&& func, Args&&... args)
|
make_invoker(F&& func, Args&&... args)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
decayed_tuple<F, Args...> {
|
decayed_tuple<F, Args...> {
|
||||||
std::forward<F> (func), std::forward<Args> (args)...
|
std::forward<F>(func), std::forward<Args>(args)...
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -425,55 +425,55 @@ namespace rtems
|
|||||||
/**
|
/**
|
||||||
* Create and start the thread.
|
* Create and start the thread.
|
||||||
*/
|
*/
|
||||||
void start_thread (state_ptr s);
|
void start_thread(state_ptr s);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline typename std::decay<T>::type
|
inline typename std::decay<T>::type
|
||||||
decay_copy (T&& t) {
|
decay_copy(T&& t) {
|
||||||
return std::forward<T> (t);
|
return std::forward<T>(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename F, typename... Args>
|
template<typename F, typename... Args>
|
||||||
thread::thread (F&& func, Args&&... args)
|
thread::thread(F&& func, Args&&... args)
|
||||||
: id_ (0) {
|
: id_(0) {
|
||||||
attributes attr;
|
attributes attr;
|
||||||
start_thread (
|
start_thread(
|
||||||
make_state (attr,
|
make_state(attr,
|
||||||
make_invoker (decay_copy (std::forward<F> (func)),
|
make_invoker(decay_copy(std::forward<F>(func)),
|
||||||
decay_copy (std::forward<Args> (args))...))
|
decay_copy(std::forward<Args>(args))...))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename A, typename F, typename... Args,
|
template<typename A, typename F, typename... Args,
|
||||||
class = thread::enable_if_attributes<A>>
|
class = thread::enable_if_attributes<A>>
|
||||||
thread::thread (A&& attr, F&& func, Args&&... args)
|
thread::thread(A&& attr, F&& func, Args&&... args)
|
||||||
: id_ (0) {
|
: id_(0) {
|
||||||
start_thread (
|
start_thread(
|
||||||
make_state (attr,
|
make_state(attr,
|
||||||
make_invoker (decay_copy (std::forward<F> (func)),
|
make_invoker(decay_copy(std::forward<F>(func)),
|
||||||
decay_copy (std::forward<Args> (args))...))
|
decay_copy(std::forward<Args>(args))...))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::thread::id thread::get_id() const noexcept {
|
inline std::thread::id thread::get_id() const noexcept {
|
||||||
return std::thread::id (id_.id_);
|
return std::thread::id(id_.id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
operator== (thread::id l, thread::id r) noexcept {
|
operator==(thread::id l, thread::id r) noexcept {
|
||||||
return l.id_ == r.id_;
|
return l.id_ == r.id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
operator!= (thread::id l, thread::id r) noexcept {
|
operator!=(thread::id l, thread::id r) noexcept {
|
||||||
return !(l == r);
|
return !(l == r);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class C, class T>
|
template<class C, class T>
|
||||||
inline std::basic_ostream<C, T>&
|
inline std::basic_ostream<C, T>&
|
||||||
operator<< (std::basic_ostream<C, T>& out, thread::id id_) {
|
operator<<(std::basic_ostream<C, T>& out, thread::id id_) {
|
||||||
return out << std::thread::id (id_.id_);
|
return out << std::thread::id(id_.id_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,23 +29,23 @@
|
|||||||
|
|
||||||
namespace rtems
|
namespace rtems
|
||||||
{
|
{
|
||||||
runtime_error::runtime_error (const rtems_status_code sc)
|
runtime_error::runtime_error(const rtems_status_code sc)
|
||||||
: std::runtime_error (::rtems_status_text (sc)),
|
: std::runtime_error(::rtems_status_text(sc)),
|
||||||
sc (sc)
|
sc(sc)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime_error::runtime_error (const rtems_status_code sc,
|
runtime_error::runtime_error(const rtems_status_code sc,
|
||||||
const std::string& what)
|
const std::string& what)
|
||||||
: std::runtime_error (what + ": " + ::rtems_status_text (sc)),
|
: std::runtime_error(what + ": " + ::rtems_status_text(sc)),
|
||||||
sc (sc)
|
sc(sc)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime_error::runtime_error (const rtems_status_code sc,
|
runtime_error::runtime_error(const rtems_status_code sc,
|
||||||
const char* what)
|
const char* what)
|
||||||
: std::runtime_error (std::string (what) + ": " + ::rtems_status_text (sc)),
|
: std::runtime_error(std::string(what) + ": " + ::rtems_status_text(sc)),
|
||||||
sc (sc)
|
sc(sc)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,26 +54,26 @@ namespace rtems
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
runtime_error_check (const rtems_status_code sc)
|
runtime_error_check(const rtems_status_code sc)
|
||||||
{
|
{
|
||||||
if (sc != RTEMS_SUCCESSFUL) {
|
if (sc != RTEMS_SUCCESSFUL) {
|
||||||
throw runtime_error (sc);
|
throw runtime_error(sc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
runtime_error_check (const rtems_status_code sc, const std::string& what)
|
runtime_error_check(const rtems_status_code sc, const std::string& what)
|
||||||
{
|
{
|
||||||
if (sc != RTEMS_SUCCESSFUL) {
|
if (sc != RTEMS_SUCCESSFUL) {
|
||||||
throw runtime_error (sc, what);
|
throw runtime_error(sc, what);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
runtime_error_check (const rtems_status_code sc, const char* what)
|
runtime_error_check(const rtems_status_code sc, const char* what)
|
||||||
{
|
{
|
||||||
if (sc != RTEMS_SUCCESSFUL) {
|
if (sc != RTEMS_SUCCESSFUL) {
|
||||||
throw runtime_error (sc, what);
|
throw runtime_error(sc, what);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,11 +39,11 @@
|
|||||||
#include <rtems.h>
|
#include <rtems.h>
|
||||||
|
|
||||||
#if HAVE_GET_SCHEDULER_NAME
|
#if HAVE_GET_SCHEDULER_NAME
|
||||||
extern "C" bool get_scheduler_name (rtems_id sid, char* name);
|
extern "C" bool get_scheduler_name(rtems_id sid, char* name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_GET_SCHEDULER_NAME
|
#if HAVE_GET_SCHEDULER_NAME
|
||||||
bool get_scheduler_name (rtems_id sid, char* name)
|
bool get_scheduler_name(rtems_id sid, char* name)
|
||||||
{
|
{
|
||||||
name[0] = 'N';
|
name[0] = 'N';
|
||||||
name[1] = 'O';
|
name[1] = 'O';
|
||||||
@@ -58,58 +58,58 @@ namespace rtems
|
|||||||
namespace thread
|
namespace thread
|
||||||
{
|
{
|
||||||
void
|
void
|
||||||
system_error_check (int ec, const char* what)
|
system_error_check(int ec, const char* what)
|
||||||
{
|
{
|
||||||
if (ec != 0) {
|
if (ec != 0) {
|
||||||
throw std::system_error (ec, std::system_category(), what);
|
throw std::system_error(ec, std::system_category(), what);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes::attributes ()
|
attributes::attributes()
|
||||||
: priority (-1),
|
: priority(-1),
|
||||||
stack_size (RTEMS_MINIMUM_STACK_SIZE),
|
stack_size(RTEMS_MINIMUM_STACK_SIZE),
|
||||||
attr (sched_inherit),
|
attr(sched_inherit),
|
||||||
policy (sched_fifo)
|
policy(sched_fifo)
|
||||||
{
|
{
|
||||||
update ();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes::attributes (const attributes& attr)
|
attributes::attributes(const attributes& attr)
|
||||||
: name (attr.name),
|
: name(attr.name),
|
||||||
priority (attr.priority),
|
priority(attr.priority),
|
||||||
stack_size (attr.stack_size),
|
stack_size(attr.stack_size),
|
||||||
scheduler (attr.scheduler),
|
scheduler(attr.scheduler),
|
||||||
attr (attr.attr),
|
attr(attr.attr),
|
||||||
policy (attr.policy)
|
policy(attr.policy)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
attributes::set_name (const std::string& name_)
|
attributes::set_name(const std::string& name_)
|
||||||
{
|
{
|
||||||
name = name_;
|
name = name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
attributes::set_name (const char* name_)
|
attributes::set_name(const char* name_)
|
||||||
{
|
{
|
||||||
name = name_;
|
name = name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string&
|
const std::string&
|
||||||
attributes::get_name () const
|
attributes::get_name() const
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
attributes::set_priority (int priority_)
|
attributes::set_priority(int priority_)
|
||||||
{
|
{
|
||||||
priority = priority_;
|
priority = priority_;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
attributes::get_priority () const
|
attributes::get_priority() const
|
||||||
{
|
{
|
||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
@@ -121,63 +121,63 @@ namespace rtems
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
attributes::get_stack_size () const
|
attributes::get_stack_size() const
|
||||||
{
|
{
|
||||||
return stack_size;
|
return stack_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
attributes::set_scheduler (const std::string& scheduler_)
|
attributes::set_scheduler(const std::string& scheduler_)
|
||||||
{
|
{
|
||||||
scheduler = scheduler_;
|
scheduler = scheduler_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
attributes::set_scheduler (const char* scheduler_)
|
attributes::set_scheduler(const char* scheduler_)
|
||||||
{
|
{
|
||||||
scheduler = scheduler_;
|
scheduler = scheduler_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string&
|
const std::string&
|
||||||
attributes::get_scheduler ()
|
attributes::get_scheduler()
|
||||||
{
|
{
|
||||||
return scheduler;
|
return scheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes::sched_attr
|
attributes::sched_attr
|
||||||
attributes::get_scheduler_attr () const
|
attributes::get_scheduler_attr() const
|
||||||
{
|
{
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
attributes::set_scheduler_policy (sched_policy policy_)
|
attributes::set_scheduler_policy(sched_policy policy_)
|
||||||
{
|
{
|
||||||
attr = sched_explicit;
|
attr = sched_explicit;
|
||||||
policy = policy_;
|
policy = policy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes::sched_policy
|
attributes::sched_policy
|
||||||
attributes::get_scheduler_policy () const
|
attributes::get_scheduler_policy() const
|
||||||
{
|
{
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
attributes::commit ()
|
attributes::commit()
|
||||||
{
|
{
|
||||||
pthread_t pid = ::pthread_self ();
|
pthread_t pid = ::pthread_self();
|
||||||
|
|
||||||
system_error_check (::pthread_setname_np (pid, name.c_str ()),
|
system_error_check(::pthread_setname_np(pid, name.c_str()),
|
||||||
"getting name");
|
"getting name");
|
||||||
|
|
||||||
int spolicy;
|
int spolicy;
|
||||||
struct sched_param sched_param;
|
struct sched_param sched_param;
|
||||||
|
|
||||||
system_error_check (::pthread_getschedparam (::pthread_self (),
|
system_error_check(::pthread_getschedparam(::pthread_self(),
|
||||||
&spolicy,
|
&spolicy,
|
||||||
&sched_param),
|
&sched_param),
|
||||||
"getting scheduler parameters");
|
"getting scheduler parameters");
|
||||||
|
|
||||||
switch (policy) {
|
switch (policy) {
|
||||||
case sched_other:
|
case sched_other:
|
||||||
@@ -193,33 +193,33 @@ namespace rtems
|
|||||||
spolicy = SCHED_SPORADIC;
|
spolicy = SCHED_SPORADIC;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
system_error_check (EINVAL, "get scheduler policy");
|
system_error_check(EINVAL, "get scheduler policy");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sched_param.sched_priority = priority;
|
sched_param.sched_priority = priority;
|
||||||
|
|
||||||
system_error_check (::pthread_setschedparam (::pthread_self (),
|
system_error_check(::pthread_setschedparam(::pthread_self(),
|
||||||
spolicy,
|
spolicy,
|
||||||
&sched_param),
|
&sched_param),
|
||||||
"getting scheduler parameters");
|
"getting scheduler parameters");
|
||||||
|
|
||||||
if (!scheduler.empty ()) {
|
if (!scheduler.empty()) {
|
||||||
char sname[4] = { ' ', ' ', ' ', ' ' };
|
char sname[4] = { ' ', ' ', ' ', ' ' };
|
||||||
for (size_t c = 0; c < sizeof (sname); ++c) {
|
for (size_t c = 0; c < sizeof(sname); ++c) {
|
||||||
if (c >= scheduler.length ()) {
|
if (c >= scheduler.length()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sname[c] = scheduler[c];
|
sname[c] = scheduler[c];
|
||||||
}
|
}
|
||||||
rtems_name scheduler_name = rtems_build_name (sname[0],
|
rtems_name scheduler_name = rtems_build_name(sname[0],
|
||||||
sname[1],
|
sname[1],
|
||||||
sname[2],
|
sname[2],
|
||||||
sname[3]);
|
sname[3]);
|
||||||
rtems_id scheduler_id;
|
rtems_id scheduler_id;
|
||||||
runtime_error_check (::rtems_scheduler_ident (scheduler_name,
|
runtime_error_check(::rtems_scheduler_ident(scheduler_name,
|
||||||
&scheduler_id),
|
&scheduler_id),
|
||||||
"get scheduler id");
|
"get scheduler id");
|
||||||
// runtime_error_check (::rtems_task_set_scheduler (RTEMS_SELF,
|
// runtime_error_check (::rtems_task_set_scheduler (RTEMS_SELF,
|
||||||
// scheduler_id,
|
// scheduler_id,
|
||||||
// 1),
|
// 1),
|
||||||
@@ -228,21 +228,21 @@ namespace rtems
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
attributes::update ()
|
attributes::update()
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
system_error_check (::pthread_getname_np (::pthread_self (),
|
system_error_check(::pthread_getname_np(::pthread_self(),
|
||||||
buf,
|
buf,
|
||||||
sizeof (buf)),
|
sizeof (buf)),
|
||||||
"getting name");
|
"getting name");
|
||||||
name = buf;
|
name = buf;
|
||||||
|
|
||||||
int spolicy;
|
int spolicy;
|
||||||
struct sched_param sched_param;
|
struct sched_param sched_param;
|
||||||
system_error_check (::pthread_getschedparam (::pthread_self (),
|
system_error_check(::pthread_getschedparam(::pthread_self(),
|
||||||
&spolicy,
|
&spolicy,
|
||||||
&sched_param),
|
&sched_param),
|
||||||
"getting scheduler parameters");
|
"getting scheduler parameters");
|
||||||
|
|
||||||
switch (spolicy) {
|
switch (spolicy) {
|
||||||
case SCHED_OTHER:
|
case SCHED_OTHER:
|
||||||
@@ -258,19 +258,19 @@ namespace rtems
|
|||||||
policy = sched_sporadic;
|
policy = sched_sporadic;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
system_error_check (EINVAL, "get scheduler policy");
|
system_error_check(EINVAL, "get scheduler policy");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
priority = sched_param.sched_priority;
|
priority = sched_param.sched_priority;
|
||||||
|
|
||||||
pthread_attr_t pattr;
|
pthread_attr_t pattr;
|
||||||
system_error_check (::pthread_getattr_np (::pthread_self (), &pattr),
|
system_error_check(::pthread_getattr_np(::pthread_self(), &pattr),
|
||||||
"getting thread attributes");
|
"getting thread attributes");
|
||||||
system_error_check (::pthread_attr_getstacksize (&pattr, &stack_size),
|
system_error_check(::pthread_attr_getstacksize(&pattr, &stack_size),
|
||||||
"getting stack size");
|
"getting stack size");
|
||||||
int inheritsched = 0;
|
int inheritsched = 0;
|
||||||
system_error_check (::pthread_attr_getinheritsched (&pattr, &inheritsched),
|
system_error_check(::pthread_attr_getinheritsched(&pattr, &inheritsched),
|
||||||
"getting inherited sheduler attribute");
|
"getting inherited sheduler attribute");
|
||||||
switch (inheritsched) {
|
switch (inheritsched) {
|
||||||
case PTHREAD_INHERIT_SCHED:
|
case PTHREAD_INHERIT_SCHED:
|
||||||
attr = sched_inherit;
|
attr = sched_inherit;
|
||||||
@@ -279,23 +279,23 @@ namespace rtems
|
|||||||
attr = sched_explicit;
|
attr = sched_explicit;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
system_error_check (EINVAL, "get scheduler attribute");
|
system_error_check(EINVAL, "get scheduler attribute");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtems_id scheduler_id;
|
rtems_id scheduler_id;
|
||||||
runtime_error_check (::rtems_task_get_scheduler (RTEMS_SELF, &scheduler_id));
|
runtime_error_check(::rtems_task_get_scheduler(RTEMS_SELF, &scheduler_id));
|
||||||
#if HAVE_GET_SCHEDULER_NAME
|
#if HAVE_GET_SCHEDULER_NAME
|
||||||
char name[5];
|
char name[5];
|
||||||
if (!get_scheduler_name (scheduler_id, &name[0])) {
|
if (!get_scheduler_name(scheduler_id, &name[0])) {
|
||||||
system_error_check (ENOENT, "get scheduler name");
|
system_error_check(ENOENT, "get scheduler name");
|
||||||
}
|
}
|
||||||
scheduler = name;
|
scheduler = name;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes&
|
attributes&
|
||||||
attributes::operator= (const attributes& other)
|
attributes::operator=(const attributes& other)
|
||||||
{
|
{
|
||||||
name = other.name;
|
name = other.name;
|
||||||
priority = other.priority;
|
priority = other.priority;
|
||||||
@@ -306,7 +306,7 @@ namespace rtems
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
attributes::operator== (const attributes& other) const
|
attributes::operator==(const attributes& other) const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
name == other.name &&
|
name == other.name &&
|
||||||
@@ -317,22 +317,22 @@ namespace rtems
|
|||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
thread_generic_entry (void* arg)
|
thread_generic_entry(void* arg)
|
||||||
{
|
{
|
||||||
thread::state_ptr s{ static_cast<thread::state_base*> (arg) };
|
thread::state_ptr s{ static_cast<thread::state_base*>(arg) };
|
||||||
try {
|
try {
|
||||||
s->run ();
|
s->run();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::terminate ();
|
std::terminate();
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread&
|
thread&
|
||||||
thread::operator= (thread&& thread_)
|
thread::operator=(thread&& thread_)
|
||||||
{
|
{
|
||||||
if (joinable ()) {
|
if (joinable()) {
|
||||||
std::terminate ();
|
std::terminate();
|
||||||
}
|
}
|
||||||
swap(thread_);
|
swap(thread_);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -354,9 +354,9 @@ namespace rtems
|
|||||||
thread::join()
|
thread::join()
|
||||||
{
|
{
|
||||||
if (!joinable()) {
|
if (!joinable()) {
|
||||||
system_error_check (EINVAL, "join");
|
system_error_check(EINVAL, "join");
|
||||||
}
|
}
|
||||||
system_error_check (::pthread_join (id_.id_, nullptr), "join");
|
system_error_check(::pthread_join(id_.id_, nullptr), "join");
|
||||||
id_ = id();
|
id_ = id();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,31 +364,31 @@ namespace rtems
|
|||||||
thread::detach()
|
thread::detach()
|
||||||
{
|
{
|
||||||
if (!joinable()) {
|
if (!joinable()) {
|
||||||
system_error_check (EINVAL, "detach");
|
system_error_check(EINVAL, "detach");
|
||||||
}
|
}
|
||||||
system_error_check (::pthread_detach (id_.id_), "detach");
|
system_error_check(::pthread_detach(id_.id_), "detach");
|
||||||
id_ = id();
|
id_ = id();
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::state_base::~state_base () = default;
|
thread::state_base::~state_base() = default;
|
||||||
|
|
||||||
void
|
void
|
||||||
thread::start_thread (thread::state_ptr s)
|
thread::start_thread(thread::state_ptr s)
|
||||||
{
|
{
|
||||||
const attributes attr = s->get_attributes ();
|
const attributes attr = s->get_attributes();
|
||||||
|
|
||||||
pthread_attr_t pattr;
|
pthread_attr_t pattr;
|
||||||
|
|
||||||
system_error_check (::pthread_attr_init (&pattr),
|
system_error_check(::pthread_attr_init(&pattr),
|
||||||
"attribute init");
|
"attribute init");
|
||||||
|
|
||||||
struct sched_param param;
|
struct sched_param param;
|
||||||
param.sched_priority = attr.get_priority ();
|
param.sched_priority = attr.get_priority();
|
||||||
system_error_check (::pthread_attr_setschedparam (&pattr, ¶m),
|
system_error_check(::pthread_attr_setschedparam(&pattr, ¶m),
|
||||||
"set sched param");
|
"set sched param");
|
||||||
|
|
||||||
int spolicy;
|
int spolicy;
|
||||||
switch (attr.get_scheduler_policy ()) {
|
switch (attr.get_scheduler_policy()) {
|
||||||
case attributes::sched_other:
|
case attributes::sched_other:
|
||||||
spolicy = SCHED_OTHER;
|
spolicy = SCHED_OTHER;
|
||||||
break;
|
break;
|
||||||
@@ -402,37 +402,37 @@ namespace rtems
|
|||||||
spolicy = SCHED_FIFO;
|
spolicy = SCHED_FIFO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
system_error_check (::pthread_attr_setschedpolicy (&pattr, spolicy),
|
system_error_check(::pthread_attr_setschedpolicy(&pattr, spolicy),
|
||||||
"set scheduler policy");
|
"set scheduler policy");
|
||||||
|
|
||||||
if (attr.get_scheduler_attr () == attributes::sched_inherit) {
|
if (attr.get_scheduler_attr() == attributes::sched_inherit) {
|
||||||
::pthread_attr_setinheritsched (&pattr, PTHREAD_INHERIT_SCHED);
|
::pthread_attr_setinheritsched(&pattr, PTHREAD_INHERIT_SCHED);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
::pthread_attr_setinheritsched (&pattr, PTHREAD_EXPLICIT_SCHED);
|
::pthread_attr_setinheritsched(&pattr, PTHREAD_EXPLICIT_SCHED);
|
||||||
}
|
}
|
||||||
|
|
||||||
system_error_check (::pthread_attr_setstacksize(&pattr,
|
system_error_check(::pthread_attr_setstacksize(&pattr,
|
||||||
attr.get_stack_size ()),
|
attr.get_stack_size()),
|
||||||
"set stack size");
|
"set stack size");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hold the new thread in the state's run handler until the rest
|
* Hold the new thread in the state's run handler until the rest
|
||||||
* of the thread is set up after the create call.
|
* of the thread is set up after the create call.
|
||||||
*/
|
*/
|
||||||
system_error_check (::pthread_create (&id_.id_,
|
system_error_check(::pthread_create(&id_.id_,
|
||||||
&pattr,
|
&pattr,
|
||||||
thread_generic_entry,
|
thread_generic_entry,
|
||||||
s.get ()),
|
s.get()),
|
||||||
"create thread");
|
"create thread");
|
||||||
|
|
||||||
system_error_check (::pthread_setname_np (id_.id_,
|
system_error_check(::pthread_setname_np(id_.id_,
|
||||||
attr.get_name ().c_str ()),
|
attr.get_name().c_str()),
|
||||||
"setting thread name");
|
"setting thread name");
|
||||||
|
|
||||||
::pthread_attr_destroy (&pattr);
|
::pthread_attr_destroy(&pattr);
|
||||||
|
|
||||||
s.release ();
|
s.release();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user