Changeset 15 in flair-src for trunk/lib/FlairCore/src/ConditionVariable_impl.cpp
- Timestamp:
- Apr 8, 2016, 3:40:57 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/ConditionVariable_impl.cpp
r2 r15 24 24 using namespace flair::core; 25 25 26 ConditionVariable_impl::ConditionVariable_impl(ConditionVariable *self) {27 this->self=self;28 26 ConditionVariable_impl::ConditionVariable_impl(ConditionVariable *self) { 27 this->self = self; 28 int status; 29 29 30 30 #ifdef __XENO__ 31 status=rt_cond_create(&m_ResumeCond,NULL);31 status = rt_cond_create(&m_ResumeCond, NULL); 32 32 #else 33 status=pthread_cond_init(&m_ResumeCond, 0);33 status = pthread_cond_init(&m_ResumeCond, 0); 34 34 #endif 35 if(status!=0) self->Err("error creating condition variable (%s)\n",strerror(-status)); 35 if (status != 0) 36 self->Err("error creating condition variable (%s)\n", strerror(-status)); 36 37 } 37 38 38 39 ConditionVariable_impl::~ConditionVariable_impl() { 39 40 int status; 40 41 41 42 #ifdef __XENO__ 42 status=rt_cond_delete(&m_ResumeCond);43 status = rt_cond_delete(&m_ResumeCond); 43 44 #else 44 status=pthread_cond_destroy(&m_ResumeCond);45 status = pthread_cond_destroy(&m_ResumeCond); 45 46 #endif 46 if(status!=0) self->Err("error destroying condition variable (%s)\n",strerror(-status)); 47 if (status != 0) 48 self->Err("error destroying condition variable (%s)\n", strerror(-status)); 47 49 } 48 50 49 51 void ConditionVariable_impl::CondWait(void) { 50 52 int status; 51 53 #ifdef __XENO__ 52 status=rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex,TM_INFINITE); 54 status = 55 rt_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, TM_INFINITE); 53 56 #else 54 status=pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex);57 status = pthread_cond_wait(&m_ResumeCond, &self->Mutex::pimpl_->mutex); 55 58 #endif 56 if(status!=0) self->Err("error (%s)\n",strerror(-status)); 59 if (status != 0) 60 self->Err("error (%s)\n", strerror(-status)); 57 61 } 58 62 59 63 bool ConditionVariable_impl::CondWaitUntil(Time date) { 60 64 int status; 61 65 #ifdef __XENO__ 62 status=rt_cond_wait_until(&m_ResumeCond, &self->Mutex::pimpl_->mutex,date);66 status = rt_cond_wait_until(&m_ResumeCond, &self->Mutex::pimpl_->mutex, date); 63 67 #else 64 struct timespec restrict; 65 restrict.tv_sec=date/1000000000; 66 restrict.tv_nsec=date%1000000000; 67 status=pthread_cond_timedwait(&m_ResumeCond, &self->Mutex::pimpl_->mutex,&restrict); 68 struct timespec restrict; 69 restrict.tv_sec = date / 1000000000; 70 restrict.tv_nsec = date % 1000000000; 71 status = pthread_cond_timedwait(&m_ResumeCond, &self->Mutex::pimpl_->mutex, 72 &restrict); 68 73 #endif 69 if (status==0) return true; 70 if(status!=ETIMEDOUT) self->Err("error (%s)\n",strerror(-status)); 71 return false; 74 if (status == 0) 75 return true; 76 if (status != ETIMEDOUT) 77 self->Err("error (%s)\n", strerror(-status)); 78 return false; 72 79 } 73 80 74 81 void ConditionVariable_impl::CondSignal(void) { 75 82 int status; 76 83 #ifdef __XENO__ 77 status=rt_cond_signal(&m_ResumeCond);84 status = rt_cond_signal(&m_ResumeCond); 78 85 #else 79 status=pthread_cond_signal(&m_ResumeCond);86 status = pthread_cond_signal(&m_ResumeCond); 80 87 #endif 81 if(status!=0) self->Err("error (%s)\n",strerror(-status)); 88 if (status != 0) 89 self->Err("error (%s)\n", strerror(-status)); 82 90 }
Note:
See TracChangeset
for help on using the changeset viewer.