summaryrefslogtreecommitdiff
path: root/cpukit/librtemscxx/thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/librtemscxx/thread.cpp')
-rw-r--r--cpukit/librtemscxx/thread.cpp224
1 files changed, 112 insertions, 112 deletions
diff --git a/cpukit/librtemscxx/thread.cpp b/cpukit/librtemscxx/thread.cpp
index 7ef9d6ac30..bfc2b84925 100644
--- a/cpukit/librtemscxx/thread.cpp
+++ b/cpukit/librtemscxx/thread.cpp
@@ -39,11 +39,11 @@
#include <rtems.h>
#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
#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[1] = 'O';
@@ -58,58 +58,58 @@ namespace rtems
namespace thread
{
void
- system_error_check (int ec, const char* what)
+ system_error_check(int ec, const char* what)
{
if (ec != 0) {
- throw std::system_error (ec, std::system_category(), what);
+ throw std::system_error(ec, std::system_category(), what);
}
}
- attributes::attributes ()
- : priority (-1),
- stack_size (RTEMS_MINIMUM_STACK_SIZE),
- attr (sched_inherit),
- policy (sched_fifo)
+ attributes::attributes()
+ : priority(-1),
+ stack_size(RTEMS_MINIMUM_STACK_SIZE),
+ attr(sched_inherit),
+ policy(sched_fifo)
{
- update ();
+ update();
}
- attributes::attributes (const attributes& attr)
- : name (attr.name),
- priority (attr.priority),
- stack_size (attr.stack_size),
- scheduler (attr.scheduler),
- attr (attr.attr),
- policy (attr.policy)
+ attributes::attributes(const attributes& attr)
+ : name(attr.name),
+ priority(attr.priority),
+ stack_size(attr.stack_size),
+ scheduler(attr.scheduler),
+ attr(attr.attr),
+ policy(attr.policy)
{
}
void
- attributes::set_name (const std::string& name_)
+ attributes::set_name(const std::string& name_)
{
name = name_;
}
void
- attributes::set_name (const char* name_)
+ attributes::set_name(const char* name_)
{
name = name_;
}
const std::string&
- attributes::get_name () const
+ attributes::get_name() const
{
return name;
}
void
- attributes::set_priority (int priority_)
+ attributes::set_priority(int priority_)
{
priority = priority_;
}
int
- attributes::get_priority () const
+ attributes::get_priority() const
{
return priority;
}
@@ -121,63 +121,63 @@ namespace rtems
}
size_t
- attributes::get_stack_size () const
+ attributes::get_stack_size() const
{
return stack_size;
}
void
- attributes::set_scheduler (const std::string& scheduler_)
+ attributes::set_scheduler(const std::string& scheduler_)
{
scheduler = scheduler_;
}
void
- attributes::set_scheduler (const char* scheduler_)
+ attributes::set_scheduler(const char* scheduler_)
{
scheduler = scheduler_;
}
const std::string&
- attributes::get_scheduler ()
+ attributes::get_scheduler()
{
return scheduler;
}
attributes::sched_attr
- attributes::get_scheduler_attr () const
+ attributes::get_scheduler_attr() const
{
return attr;
}
void
- attributes::set_scheduler_policy (sched_policy policy_)
+ attributes::set_scheduler_policy(sched_policy policy_)
{
attr = sched_explicit;
policy = policy_;
}
attributes::sched_policy
- attributes::get_scheduler_policy () const
+ attributes::get_scheduler_policy() const
{
return policy;
}
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 ()),
- "getting name");
+ system_error_check(::pthread_setname_np(pid, name.c_str()),
+ "getting name");
int spolicy;
struct sched_param sched_param;
- system_error_check (::pthread_getschedparam (::pthread_self (),
- &spolicy,
- &sched_param),
- "getting scheduler parameters");
+ system_error_check(::pthread_getschedparam(::pthread_self(),
+ &spolicy,
+ &sched_param),
+ "getting scheduler parameters");
switch (policy) {
case sched_other:
@@ -193,33 +193,33 @@ namespace rtems
spolicy = SCHED_SPORADIC;
break;
default:
- system_error_check (EINVAL, "get scheduler policy");
+ system_error_check(EINVAL, "get scheduler policy");
break;
}
sched_param.sched_priority = priority;
- system_error_check (::pthread_setschedparam (::pthread_self (),
- spolicy,
- &sched_param),
- "getting scheduler parameters");
+ system_error_check(::pthread_setschedparam(::pthread_self(),
+ spolicy,
+ &sched_param),
+ "getting scheduler parameters");
- if (!scheduler.empty ()) {
+ if (!scheduler.empty()) {
char sname[4] = { ' ', ' ', ' ', ' ' };
- for (size_t c = 0; c < sizeof (sname); ++c) {
- if (c >= scheduler.length ()) {
+ for (size_t c = 0; c < sizeof(sname); ++c) {
+ if (c >= scheduler.length()) {
break;
}
sname[c] = scheduler[c];
}
- rtems_name scheduler_name = rtems_build_name (sname[0],
- sname[1],
- sname[2],
- sname[3]);
+ rtems_name scheduler_name = rtems_build_name(sname[0],
+ sname[1],
+ sname[2],
+ sname[3]);
rtems_id scheduler_id;
- runtime_error_check (::rtems_scheduler_ident (scheduler_name,
- &scheduler_id),
- "get scheduler id");
+ runtime_error_check(::rtems_scheduler_ident(scheduler_name,
+ &scheduler_id),
+ "get scheduler id");
// runtime_error_check (::rtems_task_set_scheduler (RTEMS_SELF,
// scheduler_id,
// 1),
@@ -228,21 +228,21 @@ namespace rtems
}
void
- attributes::update ()
+ attributes::update()
{
char buf[32];
- system_error_check (::pthread_getname_np (::pthread_self (),
- buf,
- sizeof (buf)),
- "getting name");
+ system_error_check(::pthread_getname_np(::pthread_self(),
+ buf,
+ sizeof (buf)),
+ "getting name");
name = buf;
int spolicy;
struct sched_param sched_param;
- system_error_check (::pthread_getschedparam (::pthread_self (),
- &spolicy,
- &sched_param),
- "getting scheduler parameters");
+ system_error_check(::pthread_getschedparam(::pthread_self(),
+ &spolicy,
+ &sched_param),
+ "getting scheduler parameters");
switch (spolicy) {
case SCHED_OTHER:
@@ -258,19 +258,19 @@ namespace rtems
policy = sched_sporadic;
break;
default:
- system_error_check (EINVAL, "get scheduler policy");
+ system_error_check(EINVAL, "get scheduler policy");
break;
}
priority = sched_param.sched_priority;
pthread_attr_t pattr;
- system_error_check (::pthread_getattr_np (::pthread_self (), &pattr),
- "getting thread attributes");
- system_error_check (::pthread_attr_getstacksize (&pattr, &stack_size),
- "getting stack size");
+ system_error_check(::pthread_getattr_np(::pthread_self(), &pattr),
+ "getting thread attributes");
+ system_error_check(::pthread_attr_getstacksize(&pattr, &stack_size),
+ "getting stack size");
int inheritsched = 0;
- system_error_check (::pthread_attr_getinheritsched (&pattr, &inheritsched),
- "getting inherited sheduler attribute");
+ system_error_check(::pthread_attr_getinheritsched(&pattr, &inheritsched),
+ "getting inherited sheduler attribute");
switch (inheritsched) {
case PTHREAD_INHERIT_SCHED:
attr = sched_inherit;
@@ -279,23 +279,23 @@ namespace rtems
attr = sched_explicit;
break;
default:
- system_error_check (EINVAL, "get scheduler attribute");
+ system_error_check(EINVAL, "get scheduler attribute");
break;
}
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
char name[5];
- if (!get_scheduler_name (scheduler_id, &name[0])) {
- system_error_check (ENOENT, "get scheduler name");
+ if (!get_scheduler_name(scheduler_id, &name[0])) {
+ system_error_check(ENOENT, "get scheduler name");
}
scheduler = name;
#endif
}
attributes&
- attributes::operator= (const attributes& other)
+ attributes::operator=(const attributes& other)
{
name = other.name;
priority = other.priority;
@@ -306,7 +306,7 @@ namespace rtems
}
bool
- attributes::operator== (const attributes& other) const
+ attributes::operator==(const attributes& other) const
{
return
name == other.name &&
@@ -317,22 +317,22 @@ namespace rtems
}
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 {
- s->run ();
+ s->run();
} catch (...) {
- std::terminate ();
+ std::terminate();
}
return nullptr;
}
thread&
- thread::operator= (thread&& thread_)
+ thread::operator=(thread&& thread_)
{
- if (joinable ()) {
- std::terminate ();
+ if (joinable()) {
+ std::terminate();
}
swap(thread_);
return *this;
@@ -354,9 +354,9 @@ namespace rtems
thread::join()
{
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();
}
@@ -364,31 +364,31 @@ namespace rtems
thread::detach()
{
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();
}
- thread::state_base::~state_base () = default;
+ thread::state_base::~state_base() = default;
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;
- system_error_check (::pthread_attr_init (&pattr),
- "attribute init");
+ system_error_check(::pthread_attr_init(&pattr),
+ "attribute init");
struct sched_param param;
- param.sched_priority = attr.get_priority ();
- system_error_check (::pthread_attr_setschedparam (&pattr, &param),
- "set sched param");
+ param.sched_priority = attr.get_priority();
+ system_error_check(::pthread_attr_setschedparam(&pattr, &param),
+ "set sched param");
int spolicy;
- switch (attr.get_scheduler_policy ()) {
+ switch (attr.get_scheduler_policy()) {
case attributes::sched_other:
spolicy = SCHED_OTHER;
break;
@@ -402,37 +402,37 @@ namespace rtems
spolicy = SCHED_FIFO;
break;
}
- system_error_check (::pthread_attr_setschedpolicy (&pattr, spolicy),
- "set scheduler policy");
+ system_error_check(::pthread_attr_setschedpolicy(&pattr, spolicy),
+ "set scheduler policy");
- if (attr.get_scheduler_attr () == attributes::sched_inherit) {
- ::pthread_attr_setinheritsched (&pattr, PTHREAD_INHERIT_SCHED);
+ if (attr.get_scheduler_attr() == attributes::sched_inherit) {
+ ::pthread_attr_setinheritsched(&pattr, PTHREAD_INHERIT_SCHED);
}
else {
- ::pthread_attr_setinheritsched (&pattr, PTHREAD_EXPLICIT_SCHED);
+ ::pthread_attr_setinheritsched(&pattr, PTHREAD_EXPLICIT_SCHED);
}
- system_error_check (::pthread_attr_setstacksize(&pattr,
- attr.get_stack_size ()),
- "set stack size");
+ system_error_check(::pthread_attr_setstacksize(&pattr,
+ attr.get_stack_size()),
+ "set stack size");
/*
* Hold the new thread in the state's run handler until the rest
* of the thread is set up after the create call.
*/
- system_error_check (::pthread_create (&id_.id_,
- &pattr,
- thread_generic_entry,
- s.get ()),
- "create thread");
+ system_error_check(::pthread_create(&id_.id_,
+ &pattr,
+ thread_generic_entry,
+ s.get()),
+ "create thread");
- system_error_check (::pthread_setname_np (id_.id_,
- attr.get_name ().c_str ()),
- "setting thread name");
+ system_error_check(::pthread_setname_np(id_.id_,
+ attr.get_name().c_str()),
+ "setting thread name");
- ::pthread_attr_destroy (&pattr);
+ ::pthread_attr_destroy(&pattr);
- s.release ();
+ s.release();
};
};
};