Browse Source

Implement a cksem_trywait function

master
Con Kolivas 9 years ago
parent
commit
b6588c5f13
  1. 9
      src/libckpool.c
  2. 2
      src/libckpool.h

9
src/libckpool.c

@ -399,6 +399,15 @@ void _cksem_wait(sem_t *sem, const char *file, const char *func, const int line)
}
}
int _cksem_trywait(sem_t *sem, const char *file, const char *func, const int line)
{
int ret = sem_trywait(sem);
if (unlikely(ret && errno != EAGAIN && errno != EINTR))
quitfrom(1, file, func, line, "Failed to sem_trywait errno=%d sem=0x%p", errno, sem);
return ret;
}
int _cksem_mswait(sem_t *sem, int ms, const char *file, const char *func, const int line)
{
ts_t abs_timeout, ts_now;

2
src/libckpool.h

@ -452,12 +452,14 @@ void cklock_destroy(cklock_t *lock);
void _cksem_init(sem_t *sem, const char *file, const char *func, const int line);
void _cksem_post(sem_t *sem, const char *file, const char *func, const int line);
void _cksem_wait(sem_t *sem, const char *file, const char *func, const int line);
int _cksem_trywait(sem_t *sem, const char *file, const char *func, const int line);
int _cksem_mswait(sem_t *sem, int ms, const char *file, const char *func, const int line);
void _cksem_destroy(sem_t *sem, const char *file, const char *func, const int line);
#define cksem_init(SEM) _cksem_init(SEM, __FILE__, __func__, __LINE__)
#define cksem_post(SEM) _cksem_post(SEM, __FILE__, __func__, __LINE__)
#define cksem_wait(SEM) _cksem_wait(SEM, __FILE__, __func__, __LINE__)
#define cksem_trywait(SEM) _cksem_trywait(SEM, __FILE__, __func__, __LINE__)
#define cksem_mswait(SEM, _timeout) _cksem_mswait(SEM, _timeout, __FILE__, __func__, __LINE__)
#define cksem_destroy(SEM) _cksem_destroy(SEM, __FILE__, __func__, __LINE__)

Loading…
Cancel
Save