cgsem - increase information on failure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
diff --git a/util.c b/util.c
index 16016d0..173b2d7 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 c95f7f4..dd17931 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)