sscall

UDP based voice chat
git clone git://git.2f30.org/sscall.git
Log | Files | Refs | README | LICENSE

commit 583a91b8fcbc659b8d4e7f30e2167616ea04fe00
parent 80e0fc2beee76190ac24ccfa200c15b0ee7b52fb
Author: sin <sin@2f30.org>
Date:   Mon Jun  4 16:48:37 +0100

sscall: Acquire mutex only when it is necessary


Diffstat:
sscall.c | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/sscall.c b/sscall.c @@ -107,16 +107,19 @@ do_output_pcm(const void *buf, size_t len) { struct pcm_buf *pctx; - pthread_mutex_lock(&pcm_buf_lock); pctx = malloc(sizeof(*pctx)); if (!pctx) err(1, "malloc"); memset(pctx, 0, sizeof(*pctx)); + pctx->buf = malloc(len); if (!pctx->buf) err(1, "malloc"); + pctx->len = len; memcpy(pctx->buf, buf, len); + + pthread_mutex_lock(&pcm_buf_lock); INIT_LIST_HEAD(&pctx->list); list_add_tail(&pctx->list, &pcm_buf.list); pthread_cond_signal(&tx_pcm_cond);