Changeset 15 in flair-src for trunk/lib/FlairCore/src/Thread.cpp


Ignore:
Timestamp:
Apr 8, 2016, 3:40:57 PM (5 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Thread.cpp

    r2 r15  
    2727using std::string;
    2828
    29 namespace flair
    30 {
    31 namespace core
    32 {
     29namespace flair {
     30namespace core {
    3331
    34 Thread::Thread(const Object* parent,string name,uint8_t priority): Object(parent,name,"Thread")
    35 {
    36      pimpl_=new Thread_impl(this,priority);
     32Thread::Thread(const Object *parent, string name, uint8_t priority)
     33    : Object(parent, name, "Thread") {
     34  pimpl_ = new Thread_impl(this, priority);
    3735}
    3836
    39 Thread::~Thread()
    40 {
    41     delete pimpl_;
    42 }
     37Thread::~Thread() { delete pimpl_; }
    4338
    44 void Thread::Start(void)
    45 {
    46     pimpl_->Start();
    47 }
     39void Thread::Start(void) { pimpl_->Start(); }
    4840
    49 void Thread::SafeStop(void)
    50 {
    51     pimpl_->SafeStop();
    52 }
     41void Thread::SafeStop(void) { pimpl_->SafeStop(); }
    5342
    54 bool Thread::ToBeStopped(void) const
    55 {
    56     return pimpl_->ToBeStopped();
    57 }
     43bool Thread::ToBeStopped(void) const { return pimpl_->ToBeStopped(); }
    5844
    5945#ifdef __XENO__
    60 void Thread::WarnUponSwitches(bool value)
    61 {
    62     // Ask Xenomai to warn us upon switches to secondary mode.
    63     if(value==true)
    64     {
    65         rt_task_set_mode(0, T_WARNSW, NULL);
    66     }
    67     else
    68     {
    69         rt_task_set_mode(T_WARNSW, 0, NULL);
    70     }
     46void Thread::WarnUponSwitches(bool value) {
     47  // Ask Xenomai to warn us upon switches to secondary mode.
     48  if (value == true) {
     49    rt_task_set_mode(0, T_WARNSW, NULL);
     50  } else {
     51    rt_task_set_mode(T_WARNSW, 0, NULL);
     52  }
    7153}
    7254#else
    73 void Thread::WarnUponSwitches(bool value)
    74 {
    75     //Warn("Not applicable in non real time\n");
     55void Thread::WarnUponSwitches(bool value) {
     56  // Warn("Not applicable in non real time\n");
    7657}
    7758#endif
    7859
    79 void Thread::Join(void)
    80 {
    81     pimpl_->Join();
     60void Thread::Join(void) { pimpl_->Join(); }
     61
     62void Thread::SetPeriodUS(uint32_t period) { pimpl_->SetPeriodUS(period); }
     63
     64uint32_t Thread::GetPeriodUS(void) const { return pimpl_->GetPeriodUS(); }
     65
     66void Thread::SetPeriodMS(uint32_t period) { pimpl_->SetPeriodMS(period); }
     67
     68uint32_t Thread::GetPeriodMS(void) const { return pimpl_->GetPeriodMS(); }
     69
     70bool Thread::IsPeriodSet(void) { return pimpl_->period_set; }
     71
     72void Thread::WaitPeriod(void) const { pimpl_->WaitPeriod(); }
     73
     74void Thread::Suspend(void) { pimpl_->Suspend(); }
     75
     76bool Thread::SuspendUntil(Time date) { return pimpl_->SuspendUntil(date); }
     77
     78bool Thread::IsSuspended(void) const { return pimpl_->IsSuspended(); }
     79
     80void Thread::Resume(void) { pimpl_->Resume(); }
     81
     82int Thread::WaitUpdate(const IODevice *device) {
     83  return pimpl_->WaitUpdate(device);
    8284}
    8385
    84 void Thread::SetPeriodUS(uint32_t period) {
    85     pimpl_->SetPeriodUS(period);
    86 }
    87 
    88 uint32_t Thread::GetPeriodUS(void) const {
    89     return pimpl_->GetPeriodUS();
    90 }
    91 
    92 void Thread::SetPeriodMS(uint32_t period) {
    93     pimpl_->SetPeriodMS(period);
    94 }
    95 
    96 uint32_t Thread::GetPeriodMS(void) const {
    97     return pimpl_->GetPeriodMS();
    98 }
    99 
    100 
    101 bool Thread::IsPeriodSet(void)
    102 {
    103     return pimpl_->period_set;
    104 }
    105 
    106 void Thread::WaitPeriod(void) const
    107 {
    108     pimpl_->WaitPeriod();
    109 }
    110 
    111 void Thread::Suspend(void)
    112 {
    113     pimpl_->Suspend();
    114 }
    115 
    116 bool Thread::SuspendUntil(Time date){
    117     return pimpl_->SuspendUntil(date);
    118 }
    119 
    120 bool Thread::IsSuspended(void) const
    121 {
    122     return pimpl_->IsSuspended();
    123 }
    124 
    125 void Thread::Resume(void)
    126 {
    127     pimpl_->Resume();
    128 }
    129 
    130 int Thread::WaitUpdate(const IODevice* device)
    131 {
    132     return pimpl_->WaitUpdate(device);
    133 }
    134 
    135 void Thread::SleepUntil(Time time) const
    136 {
     86void Thread::SleepUntil(Time time) const {
    13787#ifdef __XENO__
    138     int status=rt_task_sleep_until(time);
    139     if(status!=0) Err("%s, error rt_task_sleep_until (%s), resume time: %lld, actual time: %lld\n",
    140                       ObjectName().c_str(),
    141                       strerror(-status),
    142                       time,
    143                       GetTime());
    144     //Printf("rt_task_sleep_until, resume time: %lld, actual time: %lld\n",time,GetTime());
     88  int status = rt_task_sleep_until(time);
     89  if (status != 0)
     90    Err("%s, error rt_task_sleep_until (%s), resume time: %lld, actual time: "
     91        "%lld\n",
     92        ObjectName().c_str(), strerror(-status), time, GetTime());
     93// Printf("rt_task_sleep_until, resume time: %lld, actual time:
     94// %lld\n",time,GetTime());
    14595#else
    146     Time current=GetTime();
    147     if(current<time)
    148     {
    149         usleep((time-current)/1000);
    150     }
     96  Time current = GetTime();
     97  if (current < time) {
     98    usleep((time - current) / 1000);
     99  }
    151100#endif
    152101}
    153102
    154 void Thread::SleepMS(uint32_t time) const
    155 {
     103void Thread::SleepMS(uint32_t time) const {
    156104#ifdef __XENO__
    157     int status=rt_task_sleep(time*1000*1000);
    158     if(status!=0) Err("erreur rt_task_sleep (%s)\n",strerror(-status));
     105  int status = rt_task_sleep(time * 1000 * 1000);
     106  if (status != 0)
     107    Err("erreur rt_task_sleep (%s)\n", strerror(-status));
    159108#else
    160     usleep(time*1000);
     109  usleep(time * 1000);
    161110#endif
    162111}
    163112
    164 void Thread::SleepUS(uint32_t time) const
    165 {
     113void Thread::SleepUS(uint32_t time) const {
    166114#ifdef __XENO__
    167     int status=rt_task_sleep(time*1000);
    168     if(status!=0) Err("erreur rt_task_sleep (%s)\n",strerror(-status));
     115  int status = rt_task_sleep(time * 1000);
     116  if (status != 0)
     117    Err("erreur rt_task_sleep (%s)\n", strerror(-status));
    169118#else
    170     usleep(time);
     119  usleep(time);
    171120#endif
    172121}
Note: See TracChangeset for help on using the changeset viewer.