Changeset 238 in flair-src for trunk/lib/FlairCore/src/Semaphore_impl.cpp


Ignore:
Timestamp:
05/15/18 16:41:02 (6 years ago)
Author:
Bayard Gildas
Message:

correction sémaphore. bloquant tout ça...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Semaphore_impl.cpp

    r213 r238  
    2525using namespace flair::core;
    2626
    27 Semaphore_impl::Semaphore_impl(Semaphore *self, uint32_t initialValue) {
     27Semaphore_impl::Semaphore_impl(Semaphore *self, string name, uint32_t initialValue, Semaphore::Type &type):type(type) {
    2828  this->self = self;
    2929  int status;
     
    3232  status = rt_sem_create(&semaphore, NULL, initialValue, S_FIFO);
    3333#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  }
    3542#endif
    3643  if (status != 0) {
     
    4653  status = rt_sem_delete(&semaphore);
    4754#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  }
    4961#endif
    5062  if (status != 0) {
     
    5870  return !rt_sem_p(&semaphore, TM_NONBLOCK);
    5971#else
    60   return !sem_trywait(&semaphore);
     72  return !sem_trywait(semaphore);
    6173#endif
    6274}
     
    7789        semTimeout.tv_nsec -= 1000000000ULL;
    7890    }
    79     status = sem_timedwait(&semaphore, &semTimeout);
     91    status = sem_timedwait(semaphore, &semTimeout);
    8092  } else {
    81     status = sem_wait(&semaphore);
     93    status = sem_wait(semaphore);
    8294  }
    8395#endif
     
    102114  status = rt_sem_v(&semaphore);
    103115#else
    104   status = sem_post(&semaphore);
     116  status = sem_post(semaphore);
    105117#endif
    106118  if (status != 0) {
Note: See TracChangeset for help on using the changeset viewer.