Skip to content

Commit

Permalink
jbuf: use C11 mutex (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredh authored Jun 7, 2022
1 parent 265546f commit 71390b4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/jbuf/jbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <re_mbuf.h>
#include <re_mem.h>
#include <re_rtp.h>
#include <re_lock.h>
#include <re_thread.h>
#include <re_tmr.h>
#include <re_jbuf.h>

Expand Down Expand Up @@ -75,7 +75,7 @@ struct jbuf {
int32_t rdiff; /**< Average out of order reverse diff */
struct tmr tmr; /**< Rdiff down timer */

struct lock *lock; /**< Makes jitter buffer thread safe */
mtx_t lock; /**< Makes jitter buffer thread safe */
enum jbuf_type jbtype; /**< Jitter buffer type */
#if JBUF_STAT
struct jbuf_stat stat; /**< Jitter buffer Statistics */
Expand Down Expand Up @@ -144,7 +144,7 @@ static void jbuf_destructor(void *data)

/* Free all frames in the pool list */
list_flush(&jb->pooll);
mem_deref(jb->lock);
mtx_destroy(&jb->lock);
}


Expand Down Expand Up @@ -188,7 +188,7 @@ int jbuf_alloc(struct jbuf **jbp, uint32_t min, uint32_t max)
DEBUG_INFO("alloc: delay=%u-%u frames\n", min, max);

jb->pt = -1;
err = lock_alloc(&jb->lock);
err = mtx_init(&jb->lock, mtx_plain);
if (err)
goto out;

Expand Down Expand Up @@ -329,7 +329,7 @@ int jbuf_put(struct jbuf *jb, const struct rtp_header *hdr, void *mem)

jb->tr = tr;

lock_write_get(jb->lock);
mtx_lock(&jb->lock);
jb->ssrc = hdr->ssrc;

if (jb->running) {
Expand Down Expand Up @@ -406,7 +406,7 @@ int jbuf_put(struct jbuf *jb, const struct rtp_header *hdr, void *mem)
f->mem = mem_ref(mem);

out:
lock_rel(jb->lock);
mtx_unlock(&jb->lock);
return err;
}

Expand All @@ -429,7 +429,7 @@ int jbuf_get(struct jbuf *jb, struct rtp_header *hdr, void **mem)
if (!jb || !hdr || !mem)
return EINVAL;

lock_write_get(jb->lock);
mtx_lock(&jb->lock);
STAT_INC(n_get);

if (jb->n <= jb->wish || !jb->framel.head) {
Expand Down Expand Up @@ -477,7 +477,7 @@ int jbuf_get(struct jbuf *jb, struct rtp_header *hdr, void **mem)
}

out:
lock_rel(jb->lock);
mtx_unlock(&jb->lock);
return err;
}

Expand All @@ -497,7 +497,7 @@ void jbuf_flush(struct jbuf *jb)
if (!jb)
return;

lock_write_get(jb->lock);
mtx_lock(&jb->lock);
if (jb->framel.head) {
DEBUG_INFO("flush: %u frames\n", jb->n);
}
Expand All @@ -519,7 +519,7 @@ void jbuf_flush(struct jbuf *jb)
memset(&jb->stat, 0, sizeof(jb->stat));
jb->stat.n_flush = n_flush;
#endif
lock_rel(jb->lock);
mtx_unlock(&jb->lock);
}


Expand Down

0 comments on commit 71390b4

Please sign in to comment.