Changeset 238 in flair-src for trunk/lib/FlairCore/src/Semaphore_impl.cpp
- Timestamp:
- 05/15/18 16:41:02 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/Semaphore_impl.cpp
r213 r238 25 25 using namespace flair::core; 26 26 27 Semaphore_impl::Semaphore_impl(Semaphore *self, uint32_t initialValue) {27 Semaphore_impl::Semaphore_impl(Semaphore *self, string name, uint32_t initialValue, Semaphore::Type &type):type(type) { 28 28 this->self = self; 29 29 int status; … … 32 32 status = rt_sem_create(&semaphore, NULL, initialValue, S_FIFO); 33 33 #else 34 status = sem_init(&semaphore, 0, initialValue); 34 if (type==Semaphore::Type::named) { 35 sem_name = "/" + name; 36 semaphore=sem_open(sem_name.c_str(),O_CREAT, 0666, initialValue); 37 if (semaphore==SEM_FAILED) status=errno; else status=0; 38 } else { //anonymous 39 semaphore=new sem_t; 40 status = sem_init(semaphore, 0, initialValue); 41 } 35 42 #endif 36 43 if (status != 0) { … … 46 53 status = rt_sem_delete(&semaphore); 47 54 #else 48 status = sem_destroy(&semaphore); 55 if (type==Semaphore::Type::named) { 56 status=sem_close(semaphore); 57 sem_unlink(sem_name.c_str()); 58 } else { //anonymous 59 status = sem_destroy(semaphore); 60 } 49 61 #endif 50 62 if (status != 0) { … … 58 70 return !rt_sem_p(&semaphore, TM_NONBLOCK); 59 71 #else 60 return !sem_trywait( &semaphore);72 return !sem_trywait(semaphore); 61 73 #endif 62 74 } … … 77 89 semTimeout.tv_nsec -= 1000000000ULL; 78 90 } 79 status = sem_timedwait( &semaphore, &semTimeout);91 status = sem_timedwait(semaphore, &semTimeout); 80 92 } else { 81 status = sem_wait( &semaphore);93 status = sem_wait(semaphore); 82 94 } 83 95 #endif … … 102 114 status = rt_sem_v(&semaphore); 103 115 #else 104 status = sem_post( &semaphore);116 status = sem_post(semaphore); 105 117 #endif 106 118 if (status != 0) {
Note:
See TracChangeset
for help on using the changeset viewer.