Skip to content

Commit

Permalink
jbuf,main,thread,trace: fix c11 return checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Jul 12, 2022
1 parent b38512c commit ad53db0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
14 changes: 9 additions & 5 deletions include/re_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,13 @@ void tss_delete(tss_t key);

/******************************************************************************
* Extra - non C11 helpers
* (We avoid tss_ mtx_ cnd_ prefixes since these reserved for functions with
* different return values)
*****************************************************************************/
/* int thrd_prio(enum thrd_prio prio) */
/* void thrd_print(struct re_printf *pf, void *unused); */

/* Ideas: */
/* int thread_prio(enum thrd_prio prio) */
/* void thread_print(struct re_printf *pf, void *unused); */

/**
* Allocates and initializes a new mutex
Expand All @@ -267,7 +271,7 @@ void tss_delete(tss_t key);
*
* @return 0 if success, otherwise errorcode
*/
int mtx_alloc(mtx_t **mtx);
int mutex_alloc(mtx_t **mtx);


/**
Expand All @@ -278,7 +282,7 @@ int mtx_alloc(mtx_t **mtx);
* @param func Function to execute
* @param arg Argument to pass to the function
*
* @return thrd_success on success, otherwise thrd_error or thrd_nomem
* @return 0 if success, otherwise errorcode
*/
int thrd_create_name(thrd_t *thr, const char *name, thrd_start_t func,
int thread_create_name(thrd_t *thr, const char *name, thrd_start_t func,
void *arg);
4 changes: 3 additions & 1 deletion src/jbuf/jbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ int jbuf_alloc(struct jbuf **jbp, uint32_t min, uint32_t max)

jb->pt = -1;
err = mtx_init(&jb->lock, mtx_plain);
if (err)
if (err != thrd_success) {
err = ENOMEM;
goto out;
}

/* Allocate all frames now */
for (i=0; i<jb->max; i++) {
Expand Down
14 changes: 8 additions & 6 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int re_alloc(struct re **rep)
if (!re)
return ENOMEM;

err = mtx_alloc(&re->mutex);
err = mutex_alloc(&re->mutex);
if (err) {
DEBUG_WARNING("thread_init: mtx_init error\n");
goto out;
Expand Down Expand Up @@ -212,8 +212,8 @@ static inline void re_lock(struct re *re)
int err;

err = mtx_lock(re->mutexp);
if (err)
DEBUG_WARNING("re_lock: %m\n", err);
if (err != thrd_success)
DEBUG_WARNING("re_lock err\n");
}


Expand All @@ -222,8 +222,8 @@ static inline void re_unlock(struct re *re)
int err;

err = mtx_unlock(re->mutexp);
if (err)
DEBUG_WARNING("re_unlock: %m\n", err);
if (err != thrd_success)
DEBUG_WARNING("re_unlock err\n");
}


Expand Down Expand Up @@ -1258,8 +1258,10 @@ int re_thread_init(void)
re_global = re;

err = tss_set(key, re);
if (err == thrd_error)
if (err != thrd_success) {
err = ENOMEM;
DEBUG_WARNING("thread_init: tss_set error\n");
}

return err;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rtp/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int rtcp_sess_alloc(struct rtcp_sess **sessp, struct rtp_sock *rs)
sess->rs = rs;
tmr_init(&sess->tmr);

err = mtx_alloc(&sess->lock);
err = mutex_alloc(&sess->lock);
if (err)
goto out;

Expand Down
4 changes: 2 additions & 2 deletions src/thread/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct thread {
};


static void *thrd_handler(void *p)
static void *handler(void *p)
{
struct thread th = *(struct thread *)p;

Expand All @@ -41,7 +41,7 @@ int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
th->func = func;
th->arg = arg;

err = pthread_create(thr, NULL, thrd_handler, th);
err = pthread_create(thr, NULL, handler, th);
if (err) {
mem_deref(th);
return thrd_error;
Expand Down
14 changes: 7 additions & 7 deletions src/thread/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#include <re_thread.h>


static void mtx_destructor(void *data)
static void mutex_destructor(void *data)
{
mtx_t *mtx = data;

mtx_destroy(mtx);
}


int mtx_alloc(mtx_t **mtx)
int mutex_alloc(mtx_t **mtx)
{
mtx_t *m;
int err;
Expand All @@ -29,7 +29,7 @@ int mtx_alloc(mtx_t **mtx)
goto out;
}

mem_destructor(m, mtx_destructor);
mem_destructor(m, mutex_destructor);

*mtx = m;

Expand All @@ -41,13 +41,13 @@ int mtx_alloc(mtx_t **mtx)
}


int thrd_create_name(thrd_t *thr, const char *name, thrd_start_t func,
int thread_create_name(thrd_t *thr, const char *name, thrd_start_t func,
void *arg)
{
(void)name; /* @TODO implement */
(void)name;

if (!thr || !func)
return thrd_error;
return EINVAL;

return thrd_create(thr, func, arg);
return (thrd_create(thr, func, arg) == thrd_success) ? 0 : EAGAIN;
}
4 changes: 3 additions & 1 deletion src/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ int re_trace_init(const char *json_file)
}

err = mtx_init(&trace.lock, mtx_plain);
if (err)
if (err != thrd_success) {
err = ENOMEM;
goto out;
}

err = fs_fopen(&trace.f, json_file, "w+");
if (err)
Expand Down

0 comments on commit ad53db0

Please sign in to comment.