mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-21 18:26:06 -05:00
Merge branch 'fixthreads' into fixosx
This commit is contained in:
100
src/misc.c
100
src/misc.c
@@ -262,6 +262,15 @@ safe_hextou64(const char *str, uint64_t *val)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
safe_strdup(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
|
||||
return strdup(str);
|
||||
}
|
||||
|
||||
|
||||
/* Key/value functions */
|
||||
struct keyval *
|
||||
@@ -1052,87 +1061,34 @@ timer_getoverrun(timer_t timer_id) {
|
||||
|
||||
#endif /* HAVE_MACH_CLOCK */
|
||||
|
||||
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