1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-09 22:38:01 +00:00

cgsem - increase information on failure

This commit is contained in:
Kano 2013-08-10 10:36:38 +10:00
parent b1f57595bd
commit 48d91c7f2d
2 changed files with 25 additions and 19 deletions

31
util.c
View File

@ -1874,7 +1874,7 @@ void RenameThread(const char* name)
* that support them and for apple which does not. We use a single byte across * that support them and for apple which does not. We use a single byte across
* a pipe to emulate semaphore behaviour there. */ * a pipe to emulate semaphore behaviour there. */
#ifdef __APPLE__ #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; int flags, fd, i;
@ -1888,55 +1888,56 @@ void cgsem_init(cgsem_t *cgsem)
flags = fcntl(fd, F_GETFD, 0); flags = fcntl(fd, F_GETFD, 0);
flags |= FD_CLOEXEC; flags |= FD_CLOEXEC;
if (fcntl(fd, F_SETFD, flags) == -1) 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; const char buf = 1;
int ret; int ret;
ret = write(cgsem->pipefd[1], &buf, 1); ret = write(cgsem->pipefd[1], &buf, 1);
if (unlikely(ret == 0)) 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; char buf;
int ret; int ret;
ret = read(cgsem->pipefd[0], &buf, 1); ret = read(cgsem->pipefd[0], &buf, 1);
if (unlikely(ret == 0)) 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[1]);
close(cgsem->pipefd[0]); close(cgsem->pipefd[0]);
} }
#else #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)) int ret;
quit(1, "Failed to sem_init in cgsem_init"); 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))) 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))) 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); sem_destroy(cgsem);
} }

13
util.h
View File

@ -93,10 +93,15 @@ void dev_error(struct cgpu_info *dev, enum dev_reason reason);
void *realloc_strcat(char *ptr, char *s); void *realloc_strcat(char *ptr, char *s);
void *str_text(char *ptr); void *str_text(char *ptr);
void RenameThread(const char* name); void RenameThread(const char* name);
void cgsem_init(cgsem_t *cgsem); void _cgsem_init(cgsem_t *cgsem, const char *file, const char *func, const int line);
void cgsem_post(cgsem_t *cgsem); void _cgsem_post(cgsem_t *cgsem, const char *file, const char *func, const int line);
void cgsem_wait(cgsem_t *cgsem); void _cgsem_wait(cgsem_t *cgsem, const char *file, const char *func, const int line);
void cgsem_destroy(cgsem_t *cgsem); 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 */ /* Align a size_t to 4 byte boundaries for fussy arches */
static inline void align_len(size_t *len) static inline void align_len(size_t *len)