9 #ifndef app_semUtils_hpp
10 #define app_semUtils_hpp
20 #define XWC_SEM_WAIT_TS_RETVOID( ts, sec, nsec ) \
21 if(clock_gettime(CLOCK_REALTIME, &ts) < 0) \
23 log<software_critical>({__FILE__,__LINE__,errno,0,"clock_gettime"}); \
27 mx::sys::timespecAddNsec(ts, nsec);
38 #define XWC_SEM_WAIT_TS( ts, sec, nsec ) \
39 if(clock_gettime(CLOCK_REALTIME, &ts) < 0) \
41 log<software_critical>({__FILE__,__LINE__,errno,0,"clock_gettime"}); \
45 mx::sys::timespecAddNsec(ts, nsec);
53 #define XWC_SEM_TIMEDWAIT_LOOP( sem, ts ) \
54 if(sem_timedwait(&sem, &ts) != 0) \
59 if(errno == EINTR || errno == ETIMEDOUT) continue; \
62 log<software_error>({__FILE__, __LINE__,errno, "sem_timedwait"}); \
66 #define XWC_SEM_FLUSH( sem ) \
69 if(sem_getvalue( &sem, &semval)<0) \
71 return log<software_error,-1>({__FILE__, __LINE__,errno, "sem_getvalue"}); \
73 for(int i = 0; i < semval; ++i) \
75 if(sem_trywait(&sem) != 0) \
77 if(errno == EAGAIN) break; \
78 return log<software_error,-1>({__FILE__, __LINE__,errno, "sem_trywait"}); \