mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-21 18:26:06 -05:00
[threads] Update mutex/cond functions to use new CHECK_ERR macros
Added various macros to check return values and log any errors and abort if the call fails. Updated logging to handle early errors before logging initialized.
This commit is contained in:
91
src/misc.c
91
src/misc.c
@@ -920,87 +920,34 @@ timespec_cmp(struct timespec time1, struct timespec time2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
fork_mutex_init(pthread_mutex_t *mutex)
|
||||
int
|
||||
mutex_init(pthread_mutex_t *mutex)
|
||||
{
|
||||
pthread_mutexattr_t mattr;
|
||||
int err;
|
||||
|
||||
err = pthread_mutexattr_init(&mattr);
|
||||
assert(err == 0);
|
||||
err = pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
assert(err == 0);
|
||||
CHECK_ERR(L_MISC, pthread_mutexattr_init(&mattr));
|
||||
CHECK_ERR(L_MISC, pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_ERRORCHECK));
|
||||
err = pthread_mutex_init(mutex, &mattr);
|
||||
assert(err == 0);
|
||||
err = pthread_mutexattr_destroy(&mattr);
|
||||
assert(err == 0);
|
||||
}
|
||||
CHECK_ERR(L_MISC, pthread_mutexattr_destroy(&mattr));
|
||||
|
||||
void
|
||||
fork_mutex_lock(pthread_mutex_t *mutex)
|
||||
{
|
||||
int err;
|
||||
err = pthread_mutex_lock(mutex);
|
||||
assert(err == 0);
|
||||
}
|
||||
|
||||
void
|
||||
fork_mutex_unlock(pthread_mutex_t *mutex)
|
||||
{
|
||||
int err;
|
||||
err = pthread_mutex_unlock(mutex);
|
||||
assert(err == 0);
|
||||
}
|
||||
|
||||
void
|
||||
fork_mutex_destroy(pthread_mutex_t *mutex)
|
||||
{
|
||||
int err;
|
||||
err = pthread_mutex_destroy(mutex);
|
||||
assert(err == 0);
|
||||
}
|
||||
|
||||
/* condition wrappers with checks */
|
||||
void
|
||||
fork_cond_init(pthread_cond_t *cond)
|
||||
{
|
||||
int err;
|
||||
err = pthread_cond_init(cond, NULL);
|
||||
assert(err == 0);
|
||||
}
|
||||
|
||||
void
|
||||
fork_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
|
||||
{
|
||||
int err;
|
||||
err = pthread_cond_wait(cond, mutex);
|
||||
assert(err == 0);
|
||||
}
|
||||
|
||||
int
|
||||
fork_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||
const struct timespec *ts)
|
||||
{
|
||||
int err;
|
||||
err = pthread_cond_timedwait(cond, mutex, ts);
|
||||
if(err == ETIMEDOUT)
|
||||
return err;
|
||||
assert(err == 0);
|
||||
return err;
|
||||
}
|
||||
|
||||
void
|
||||
fork_cond_signal(pthread_cond_t *cond)
|
||||
{
|
||||
int err;
|
||||
err = pthread_cond_signal(cond);
|
||||
assert(err == 0);
|
||||
void log_fatal_err(int domain, const char *func, int line, int err) {
|
||||
DPRINTF(E_FATAL, domain, "%s failed at line %d, error %d (%s)\n", func,
|
||||
line, err, strerror(err));
|
||||
abort();
|
||||
}
|
||||
|
||||
void
|
||||
fork_cond_destroy(pthread_cond_t *cond)
|
||||
{
|
||||
int err;
|
||||
err = pthread_cond_destroy(cond);
|
||||
assert(err == 0);
|
||||
void log_fatal_errno(int domain, const char *func, int line) {
|
||||
DPRINTF(E_FATAL, domain, "%s failed at line %d, error %d (%s)\n", func,
|
||||
line, errno, strerror(errno));
|
||||
abort();
|
||||
}
|
||||
|
||||
void log_fatal_null(int domain, const char *func, int line) {
|
||||
DPRINTF(E_FATAL, domain, "%s returned NULL at line %d\n", func, line);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user