From 48d91c7f2db749a9b46ddf273c60946bf286a3a6 Mon Sep 17 00:00:00 2001 From: Kano Date: Sat, 10 Aug 2013 10:36:38 +1000 Subject: [PATCH] cgsem - increase information on failure --- util.c | 31 ++++++++++++++++--------------- util.h | 13 +++++++++---- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/util.c b/util.c index 16016d05..173b2d72 100644 --- a/util.c +++ b/util.c @@ -1874,7 +1874,7 @@ void RenameThread(const char* name) * that support them and for apple which does not. We use a single byte across * a pipe to emulate semaphore behaviour there. */ #ifdef __APPLE__ -void cgsem_init(cgsem_t *cgsem) +void _cgsem_init(cgsem_t *cgsem, const char *file, const char *func, const int line) { int flags, fd, i; @@ -1888,55 +1888,56 @@ void cgsem_init(cgsem_t *cgsem) flags = fcntl(fd, F_GETFD, 0); flags |= FD_CLOEXEC; if (fcntl(fd, F_SETFD, flags) == -1) - quit(1, "Failed to fcntl in cgsem_init"); + quit(1, "Failed to fcntl in cgsem_init errno=%d (%s %s():%d)", errno, file, func, line); } } -void cgsem_post(cgsem_t *cgsem) +void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int line) { const char buf = 1; int ret; ret = write(cgsem->pipefd[1], &buf, 1); if (unlikely(ret == 0)) - applog(LOG_WARNING, "Failed to write in cgsem_post"); + applog(LOG_WARNING, "Failed to write in cgsem_post errno=%d (%s %s():%d)", errno, file, func, line); } -void cgsem_wait(cgsem_t *cgsem) +void _cgsem_wait(cgsem_t *cgsem, const char *file, const char *func, const int line) { char buf; int ret; ret = read(cgsem->pipefd[0], &buf, 1); if (unlikely(ret == 0)) - applog(LOG_WARNING, "Failed to read in cgsem_wait"); + applog(LOG_WARNING, "Failed to read in cgsem_wait errno=%d (%s %s():%d)", errno, file, func, line); } -void cgsem_destroy(cgsem_t *cgsem) +void _cgsem_destroy(cgsem_t *cgsem) { close(cgsem->pipefd[1]); close(cgsem->pipefd[0]); } #else -void cgsem_init(cgsem_t *cgsem) +void _cgsem_init(cgsem_t *cgsem, const char *file, const char *func, const int line) { - if (sem_init(cgsem, 0, 0)) - quit(1, "Failed to sem_init in cgsem_init"); + int ret; + if ((ret = sem_init(cgsem, 0, 0))) + quit(1, "Failed to sem_init in cgsem_init ret=%d errno=%d (%s %s():%d)", ret, errno, file, func, line); } -void cgsem_post(cgsem_t *cgsem) +void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int line) { if (unlikely(sem_post(cgsem))) - quit(1, "Failed to sem_post in cgsem_post"); + quit(1, "Failed to sem_post in cgsem_post errno=%d cgsem=0x%p (%s %s():%d)", errno, cgsem, file, func, line); } -void cgsem_wait(cgsem_t *cgsem) +void _cgsem_wait(cgsem_t *cgsem, const char *file, const char *func, const int line) { if (unlikely(sem_wait(cgsem))) - quit(1, "Failed to sem_wait in cgsem_wait"); + quit(1, "Failed to sem_wait in cgsem_wait errno=%d cgsem=0x%p (%s %s():%d)", errno, cgsem, file, func, line); } -void cgsem_destroy(cgsem_t *cgsem) +void _cgsem_destroy(cgsem_t *cgsem) { sem_destroy(cgsem); } diff --git a/util.h b/util.h index c95f7f46..dd179319 100644 --- a/util.h +++ b/util.h @@ -93,10 +93,15 @@ void dev_error(struct cgpu_info *dev, enum dev_reason reason); void *realloc_strcat(char *ptr, char *s); void *str_text(char *ptr); void RenameThread(const char* name); -void cgsem_init(cgsem_t *cgsem); -void cgsem_post(cgsem_t *cgsem); -void cgsem_wait(cgsem_t *cgsem); -void cgsem_destroy(cgsem_t *cgsem); +void _cgsem_init(cgsem_t *cgsem, const char *file, const char *func, const int line); +void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int line); +void _cgsem_wait(cgsem_t *cgsem, const char *file, const char *func, const int line); +void _cgsem_destroy(cgsem_t *cgsem); + +#define cgsem_init(_sem) _cgsem_init(_sem, __FILE__, __func__, __LINE__) +#define cgsem_post(_sem) _cgsem_post(_sem, __FILE__, __func__, __LINE__) +#define cgsem_wait(_sem) _cgsem_wait(_sem, __FILE__, __func__, __LINE__) +#define cgsem_destroy(_sem) _cgsem_destroy(_sem) /* Align a size_t to 4 byte boundaries for fussy arches */ static inline void align_len(size_t *len)