API

XWC app semaphore Utilities. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define XWC_SEM_WAIT_TS_RETVOID(ts, sec, nsec)
 Add the wait time to a timespec for a sem_timedwait call, with no value returned on error. More...
 
#define XWC_SEM_WAIT_TS(ts, sec, nsec)
 Add the wait time to a timespec for a sem_timedwait call, with -1 returned on error. More...
 
#define XWC_SEM_TIMEDWAIT_LOOP(sem, ts)
 Perform a sem_timedwait in the context of a standard loop in MagAO-X code. More...
 
#define XWC_SEM_FLUSH(sem)
 

Detailed Description

XWC app semaphore Utilities.

Author
Jared R. Males (jared.nosp@m.male.nosp@m.s@gma.nosp@m.il.c.nosp@m.om)

Definition in file semUtils.hpp.

Macro Definition Documentation

◆ XWC_SEM_FLUSH

#define XWC_SEM_FLUSH (   sem)
Value:
{ \
int semval; \
if(sem_getvalue( &sem, &semval)<0) \
{ \
return log<software_error,-1>({__FILE__, __LINE__,errno, "sem_getvalue"}); \
} \
for(int i = 0; i < semval; ++i) \
{ \
if(sem_trywait(&sem) != 0) \
{ \
if(errno == EAGAIN) break; \
return log<software_error,-1>({__FILE__, __LINE__,errno, "sem_trywait"}); \
} \
} \
}

Definition at line 65 of file semUtils.hpp.

◆ XWC_SEM_TIMEDWAIT_LOOP

#define XWC_SEM_TIMEDWAIT_LOOP (   sem,
  ts 
)
Value:
if(sem_timedwait(&sem, &ts) != 0) \
{ \
/* Check for why we timed out */ \
/* EINTER probably indicates time to shutdown, loop wil exit if m_shutdown is set */ \
/* ETIMEDOUT just means keep waiting */ \
if(errno == EINTR || errno == ETIMEDOUT) continue; \
\
/*Otherwise, report an error.*/ \
log<software_error>({__FILE__, __LINE__,errno, "sem_timedwait"}); \
break; \
}

Perform a sem_timedwait in the context of a standard loop in MagAO-X code.

Parameters
semthe semaphore
tsthe timespec with the time to wait until

Definition at line 52 of file semUtils.hpp.

◆ XWC_SEM_WAIT_TS

#define XWC_SEM_WAIT_TS (   ts,
  sec,
  nsec 
)
Value:
if(clock_gettime(CLOCK_REALTIME, &ts) < 0) \
{ \
log<software_critical>({__FILE__,__LINE__,errno,0,"clock_gettime"}); \
return -1; \
} \
ts.tv_sec += sec; \
mx::sys::timespecAddNsec(ts, nsec);

Add the wait time to a timespec for a sem_timedwait call, with -1 returned on error.

An error would be generated by clock_gettime

Parameters
tsis the timespec to modify, should be set to current time
secis the number of seconds to add to ts
nsecis the number of nanoseconds to add to ts

Definition at line 37 of file semUtils.hpp.

◆ XWC_SEM_WAIT_TS_RETVOID

#define XWC_SEM_WAIT_TS_RETVOID (   ts,
  sec,
  nsec 
)
Value:
if(clock_gettime(CLOCK_REALTIME, &ts) < 0) \
{ \
log<software_critical>({__FILE__,__LINE__,errno,0,"clock_gettime"}); \
return; /*will trigger a shutdown*/ \
} \
ts.tv_sec += sec; \
mx::sys::timespecAddNsec(ts, nsec);

Add the wait time to a timespec for a sem_timedwait call, with no value returned on error.

An error would be generated by clock_gettime.

Parameters
tsis the timespec to modify, should be set to current time
secis the number of seconds to add to ts
nsecis the number of nanoseconds to add to ts

Definition at line 20 of file semUtils.hpp.