Changeset 126 in flair-src for trunk/lib/FlairCore/src/Semaphore_impl.cpp
- Timestamp:
- Jan 17, 2017, 10:47:02 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.