Browse Source

Check for more interrupted conditions in util.c and handle them gracefully.

port-ckolivas
Con Kolivas 11 years ago committed by Noel Maersk
parent
commit
f7394ff165
  1. 20
      util.c

20
util.c

@ -2596,19 +2596,24 @@ void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int l @@ -2596,19 +2596,24 @@ void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int l
const char buf = 1;
int ret;
retry:
ret = write(cgsem->pipefd[1], &buf, 1);
if (unlikely(ret == 0))
applog(LOG_WARNING, "Failed to write errno=%d" IN_FMT_FFL, errno, file, func, line);
else if (unlikely(ret < 0 && interrupted))
goto retry;
}
void _cgsem_wait(cgsem_t *cgsem, const char *file, const char *func, const int line)
{
char buf;
int ret;
retry:
ret = read(cgsem->pipefd[0], &buf, 1);
if (unlikely(ret == 0))
applog(LOG_WARNING, "Failed to read errno=%d" IN_FMT_FFL, errno, file, func, line);
else if (unlikely(ret < 0 && interrupted))
goto retry;
}
void cgsem_destroy(cgsem_t *cgsem)
@ -2661,6 +2666,8 @@ void cgsem_reset(cgsem_t *cgsem) @@ -2661,6 +2666,8 @@ void cgsem_reset(cgsem_t *cgsem)
ret = select(fd + 1, &rd, NULL, NULL, &timeout);
if (ret > 0)
ret = read(fd, &buf, 1);
else if (unlikely(ret < 0 && interrupted()))
ret = 1;
} while (ret > 0);
}
#else
@ -2679,8 +2686,12 @@ void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int l @@ -2679,8 +2686,12 @@ void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int l
void _cgsem_wait(cgsem_t *cgsem, const char *file, const char *func, const int line)
{
if (unlikely(sem_wait(cgsem)))
retry:
if (unlikely(sem_wait(cgsem))) {
if (interrupted())
goto retry;
quitfrom(1, file, func, line, "Failed to sem_wait errno=%d cgsem=0x%p", errno, cgsem);
}
}
int _cgsem_mswait(cgsem_t *cgsem, int ms, const char *file, const char *func, const int line)
@ -2692,12 +2703,15 @@ int _cgsem_mswait(cgsem_t *cgsem, int ms, const char *file, const char *func, co @@ -2692,12 +2703,15 @@ int _cgsem_mswait(cgsem_t *cgsem, int ms, const char *file, const char *func, co
cgtime(&tv_now);
timeval_to_spec(&ts_now, &tv_now);
ms_to_timespec(&abs_timeout, ms);
retry:
timeraddspec(&abs_timeout, &ts_now);
ret = sem_timedwait(cgsem, &abs_timeout);
if (ret) {
if (likely(sock_timeout()))
return ETIMEDOUT;
if (interrupted())
goto retry;
quitfrom(1, file, func, line, "Failed to sem_timedwait errno=%d cgsem=0x%p", errno, cgsem);
}
return 0;
@ -2709,6 +2723,8 @@ void cgsem_reset(cgsem_t *cgsem) @@ -2709,6 +2723,8 @@ void cgsem_reset(cgsem_t *cgsem)
do {
ret = sem_trywait(cgsem);
if (unlikely(ret < 0 && interrupted()))
ret = 0;
} while (!ret);
}

Loading…
Cancel
Save