Skip to content

Commit

Permalink
Fix pthread returns (#444)
Browse files Browse the repository at this point in the history
pthread calls do not set errno, they return the error directly
  • Loading branch information
chrissie-c authored Aug 11, 2021
1 parent fa59903 commit a60ca50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
14 changes: 8 additions & 6 deletions include/tlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ static inline int32_t timerlist_add(struct timerlist *timerlist,
struct timerlist_timer **new_heap_entries;
int32_t res = 0;

if (pthread_mutex_lock(&timerlist->list_mutex)) {
return -errno;
if ( (res=pthread_mutex_lock(&timerlist->list_mutex))) {
return -res;
}

/*
Expand Down Expand Up @@ -351,9 +351,10 @@ static inline int32_t timerlist_del(struct timerlist *timerlist,
timer_handle _timer_handle)
{
struct timerlist_timer *timer = (struct timerlist_timer *)_timer_handle;
int res;

if (pthread_mutex_lock(&timerlist->list_mutex)) {
return -errno;
if ( (res=pthread_mutex_lock(&timerlist->list_mutex))) {
return -res;
}

memset(timer->handle_addr, 0, sizeof(struct timerlist_timer *));
Expand Down Expand Up @@ -453,12 +454,13 @@ static inline int32_t timerlist_expire(struct timerlist *timerlist)
uint64_t current_time_from_epoch;
uint64_t current_monotonic_time;
uint64_t current_time;
int res;

current_monotonic_time = qb_util_nano_current_get();
current_time_from_epoch = qb_util_nano_from_epoch_get();

if (pthread_mutex_lock(&timerlist->list_mutex)) {
return -errno;
if ( (res=pthread_mutex_lock(&timerlist->list_mutex))) {
return -res;
}

while (timerlist->size > 0) {
Expand Down
5 changes: 3 additions & 2 deletions lib/loop_timerlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ qb_loop_timer_add(struct qb_loop * lp,
struct qb_loop_timer *t;
struct qb_timer_source *my_src;
int32_t i;
int res;
struct qb_loop *l = lp;

if (l == NULL) {
Expand All @@ -198,8 +199,8 @@ qb_loop_timer_add(struct qb_loop * lp,
}
my_src = (struct qb_timer_source *)l->timer_source;

if (pthread_mutex_lock(&my_src->lock)) {
return -errno;
if ( (res=pthread_mutex_lock(&my_src->lock))) {
return -res;
}
i = _get_empty_array_position_(my_src);
assert(qb_array_index(my_src->timers, i, (void **)&t) >= 0);
Expand Down
2 changes: 1 addition & 1 deletion lib/rpl_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ _rpl_sem_timedwait(rpl_sem_t * sem, const struct timespec *timeout)
{
int retval = pthread_mutex_lock(&sem->mutex);
if (retval != 0) {
return -errno;
return -retval;
}
if (sem->destroy_request) {
retval = -EINVAL;
Expand Down

0 comments on commit a60ca50

Please sign in to comment.