Changeset 126 in flair-src
- Timestamp:
- Jan 17, 2017, 10:47:02 AM (8 years ago)
- Location:
- trunk/lib/FlairCore/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/Semaphore.cpp
r118 r126 31 31 Semaphore::~Semaphore() { delete pimpl_; } 32 32 33 void Semaphore::GetSemaphore(void) const { pimpl_->GetSemaphore(); }33 bool Semaphore::GetSemaphore(Time timeout) const { return pimpl_->GetSemaphore(timeout); } 34 34 35 void Semaphore::ReleaseSemaphore(void) const {pimpl_->ReleaseSemaphore(); }35 bool Semaphore::ReleaseSemaphore(void) const { return pimpl_->ReleaseSemaphore(); } 36 36 37 37 } // end namespace core -
trunk/lib/FlairCore/src/Semaphore.h
r118 r126 51 51 * 52 52 * Lock the semaphore. 53 * 53 * 54 * \param timeout The timeout, in nanoseconds. 54 55 */ 55 void GetSemaphore(void) const;56 bool GetSemaphore(Time timeout = TIME_INFINITE) const; 56 57 57 58 /*! … … 61 62 * 62 63 */ 63 voidReleaseSemaphore(void) const;64 bool ReleaseSemaphore(void) const; 64 65 65 66 private: -
trunk/lib/FlairCore/src/Semaphore_impl.cpp
r118 r126 20 20 21 21 #include <string.h> 22 #include <time.h> 22 23 23 24 using std::string; … … 48 49 } 49 50 50 void Semaphore_impl::GetSemaphore(void) {51 bool Semaphore_impl::GetSemaphore(Time timeout) { 51 52 int status; 53 bool returnValue = true; 52 54 #ifdef __XENO__ 53 status = rt_sem_p(&semaphore, TM_INFINITE);55 status = rt_sem_p(&semaphore, timeout); 54 56 #else 55 status = sem_wait(&semaphore); 57 if (timeout != 0) { 58 struct timespec semTimeout; 59 clock_gettime(CLOCK_REALTIME, &semTimeout); 60 semTimeout.tv_sec += timeout / 1000000000ULL; 61 semTimeout.tv_nsec += timeout % 1000000000ULL; 62 if (semTimeout.tv_nsec >= 1000000000ULL) { 63 semTimeout.tv_sec++; 64 semTimeout.tv_nsec -= 1000000000ULL; 65 } 66 status = sem_timedwait(&semaphore, &semTimeout); 67 } else { 68 status = sem_wait(&semaphore); 69 } 56 70 #endif 57 if (status != 0) 58 self->Err("error getting the semaphore (%s)\n", strerror(-status)); 71 if (status != 0) { 72 if (errno == ETIMEDOUT) { 73 self->Warn("warning : semaphore timedout\n"); 74 } else { 75 self->Err("error getting the semaphore (%s)\n", strerror(-status)); 76 } 77 returnValue = false; 78 } 79 return returnValue; 59 80 } 60 81 61 voidSemaphore_impl::ReleaseSemaphore(void) {82 bool Semaphore_impl::ReleaseSemaphore(void) { 62 83 int status; 84 bool returnValue = true; 63 85 #ifdef __XENO__ 64 86 status = rt_sem_v(&semaphore); … … 66 88 status = sem_post(&semaphore); 67 89 #endif 68 if (status != 0) 90 if (status != 0) { 69 91 self->Err("error releasing the semaphore (%s)\n", strerror(-status)); 92 returnValue = false; 93 } 94 return returnValue; 70 95 }
Note:
See TracChangeset
for help on using the changeset viewer.