Changeset 15 in flair-src for trunk/lib/FlairCore/src/Thread.cpp
- Timestamp:
- 04/08/16 15:40:57 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/Thread.cpp
r2 r15 27 27 using std::string; 28 28 29 namespace flair 30 { 31 namespace core 32 { 29 namespace flair { 30 namespace core { 33 31 34 Thread::Thread(const Object * parent,string name,uint8_t priority): Object(parent,name,"Thread")35 {36 pimpl_=new Thread_impl(this,priority);32 Thread::Thread(const Object *parent, string name, uint8_t priority) 33 : Object(parent, name, "Thread") { 34 pimpl_ = new Thread_impl(this, priority); 37 35 } 38 36 39 Thread::~Thread() 40 { 41 delete pimpl_; 42 } 37 Thread::~Thread() { delete pimpl_; } 43 38 44 void Thread::Start(void) 45 { 46 pimpl_->Start(); 47 } 39 void Thread::Start(void) { pimpl_->Start(); } 48 40 49 void Thread::SafeStop(void) 50 { 51 pimpl_->SafeStop(); 52 } 41 void Thread::SafeStop(void) { pimpl_->SafeStop(); } 53 42 54 bool Thread::ToBeStopped(void) const 55 { 56 return pimpl_->ToBeStopped(); 57 } 43 bool Thread::ToBeStopped(void) const { return pimpl_->ToBeStopped(); } 58 44 59 45 #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 } 46 void 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 } 71 53 } 72 54 #else 73 void Thread::WarnUponSwitches(bool value) 74 { 75 //Warn("Not applicable in non real time\n"); 55 void Thread::WarnUponSwitches(bool value) { 56 // Warn("Not applicable in non real time\n"); 76 57 } 77 58 #endif 78 59 79 void Thread::Join(void) 80 { 81 pimpl_->Join(); 60 void Thread::Join(void) { pimpl_->Join(); } 61 62 void Thread::SetPeriodUS(uint32_t period) { pimpl_->SetPeriodUS(period); } 63 64 uint32_t Thread::GetPeriodUS(void) const { return pimpl_->GetPeriodUS(); } 65 66 void Thread::SetPeriodMS(uint32_t period) { pimpl_->SetPeriodMS(period); } 67 68 uint32_t Thread::GetPeriodMS(void) const { return pimpl_->GetPeriodMS(); } 69 70 bool Thread::IsPeriodSet(void) { return pimpl_->period_set; } 71 72 void Thread::WaitPeriod(void) const { pimpl_->WaitPeriod(); } 73 74 void Thread::Suspend(void) { pimpl_->Suspend(); } 75 76 bool Thread::SuspendUntil(Time date) { return pimpl_->SuspendUntil(date); } 77 78 bool Thread::IsSuspended(void) const { return pimpl_->IsSuspended(); } 79 80 void Thread::Resume(void) { pimpl_->Resume(); } 81 82 int Thread::WaitUpdate(const IODevice *device) { 83 return pimpl_->WaitUpdate(device); 82 84 } 83 85 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 { 86 void Thread::SleepUntil(Time time) const { 137 87 #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()); 145 95 #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 } 151 100 #endif 152 101 } 153 102 154 void Thread::SleepMS(uint32_t time) const 155 { 103 void Thread::SleepMS(uint32_t time) const { 156 104 #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)); 159 108 #else 160 usleep(time*1000);109 usleep(time * 1000); 161 110 #endif 162 111 } 163 112 164 void Thread::SleepUS(uint32_t time) const 165 { 113 void Thread::SleepUS(uint32_t time) const { 166 114 #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)); 169 118 #else 170 119 usleep(time); 171 120 #endif 172 121 }
Note:
See TracChangeset
for help on using the changeset viewer.