Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aumix: use mutex_alloc() #1142

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/rem_aumix.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ int aumix_source_put(struct aumix_source *src, const int16_t *sampv,
size_t sampc);
void aumix_source_readh(struct aumix_source *src, aumix_read_h *readh);
void aumix_source_flush(struct aumix_source *src);
int aumix_debug(struct re_printf *pf, struct aumix *mix);
int aumix_debug(struct re_printf *pf, const struct aumix *mix);
54 changes: 27 additions & 27 deletions rem/aumix/aumix.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/** Defines an Audio mixer */
struct aumix {
mtx_t mutex;
mtx_t *mutex;
cnd_t cond;
struct list srcl;
thrd_t thread;
Expand Down Expand Up @@ -62,21 +62,22 @@ static void destructor(void *arg)
{
struct aumix *mix = arg;

mtx_lock(&mix->mutex);
mtx_lock(mix->mutex);
bool run = mix->run;
mtx_unlock(&mix->mutex);
mtx_unlock(mix->mutex);

if (run) {

mtx_lock(&mix->mutex);
mtx_lock(mix->mutex);
mix->run = false;
cnd_signal(&mix->cond);
mtx_unlock(&mix->mutex);
mtx_unlock(mix->mutex);

thrd_join(mix->thread, NULL);
}

mem_deref(mix->af);
mem_deref(mix->mutex);
}


Expand All @@ -85,9 +86,9 @@ static void source_destructor(void *arg)
struct aumix_source *src = arg;

if (src->le.list) {
mtx_lock(&src->mix->mutex);
mtx_lock(src->mix->mutex);
list_unlink(&src->le);
mtx_unlock(&src->mix->mutex);
mtx_unlock(src->mix->mutex);
}

mem_deref(src->aubuf);
Expand All @@ -110,7 +111,7 @@ static int aumix_thread(void *arg)
if (!silence || !frame || !mix_frame)
goto out;

mtx_lock(&mix->mutex);
mtx_lock(mix->mutex);

while (mix->run) {

Expand All @@ -119,13 +120,13 @@ static int aumix_thread(void *arg)

if (!mix->srcl.head) {
mix->af = mem_deref(mix->af);
cnd_wait(&mix->cond, &mix->mutex);
cnd_wait(&mix->cond, mix->mutex);
ts = 0;
}
else {
mtx_unlock(&mix->mutex);
mtx_unlock(mix->mutex);
sys_usleep(4000);
mtx_lock(&mix->mutex);
mtx_lock(mix->mutex);
}

now = tmr_jiffies();
Expand Down Expand Up @@ -243,7 +244,7 @@ static int aumix_thread(void *arg)
ts += mix->ptime;
}

mtx_unlock(&mix->mutex);
mtx_unlock(mix->mutex);

out:
mem_deref(mix_frame);
Expand Down Expand Up @@ -287,9 +288,8 @@ int aumix_alloc(struct aumix **mixp, uint32_t srate,
mix->rec_sum.srate = srate;
mix->rec_sum.sampc = mix->frame_size;

err = mtx_init(&mix->mutex, mtx_plain) != thrd_success;
err = mutex_alloc(&mix->mutex);
if (err) {
err = ENOMEM;
goto out;
}

Expand Down Expand Up @@ -328,9 +328,9 @@ void aumix_recordh(struct aumix *mix, aumix_record_h *recordh)
if (!mix)
return;

mtx_lock(&mix->mutex);
mtx_lock(mix->mutex);
mix->recordh = recordh;
mtx_unlock(&mix->mutex);
mtx_unlock(mix->mutex);
}


Expand All @@ -345,9 +345,9 @@ void aumix_record_sumh(struct aumix *mix, aumix_record_h *recordh)
if (!mix)
return;

mtx_lock(&mix->mutex);
mtx_lock(mix->mutex);
mix->record_sumh = recordh;
mtx_unlock(&mix->mutex);
mtx_unlock(mix->mutex);
}


Expand Down Expand Up @@ -378,10 +378,10 @@ int aumix_playfile(struct aumix *mix, const char *filepath)
return EINVAL;
}

mtx_lock(&mix->mutex);
mtx_lock(mix->mutex);
mem_deref(mix->af);
mix->af = af;
mtx_unlock(&mix->mutex);
mtx_unlock(mix->mutex);

return 0;
}
Expand Down Expand Up @@ -468,9 +468,9 @@ void aumix_source_readh(struct aumix_source *src, aumix_read_h *readh)
if (!src || !src->mix)
return;

mtx_lock(&src->mix->mutex);
mtx_lock(src->mix->mutex);
src->readh = readh;
mtx_unlock(&src->mix->mutex);
mtx_unlock(src->mix->mutex);
}


Expand Down Expand Up @@ -510,7 +510,7 @@ void aumix_source_enable(struct aumix_source *src, bool enable)

mix = src->mix;

mtx_lock(&mix->mutex);
mtx_lock(mix->mutex);

if (enable) {
list_append(&mix->srcl, &src->le, src);
Expand All @@ -520,7 +520,7 @@ void aumix_source_enable(struct aumix_source *src, bool enable)
list_unlink(&src->le);
}

mtx_unlock(&mix->mutex);
mtx_unlock(mix->mutex);
}


Expand Down Expand Up @@ -565,7 +565,7 @@ void aumix_source_flush(struct aumix_source *src)
*
* @return 0 if success, otherwise errorcode
*/
int aumix_debug(struct re_printf *pf, struct aumix *mix)
int aumix_debug(struct re_printf *pf, const struct aumix *mix)
{
struct le *le;
int err = 0;
Expand All @@ -574,7 +574,7 @@ int aumix_debug(struct re_printf *pf, struct aumix *mix)
return EINVAL;

re_hprintf(pf, "aumix debug:\n");
mtx_lock(&mix->mutex);
mtx_lock(mix->mutex);
LIST_FOREACH(&mix->srcl, le)
{
struct aumix_source *src = le->data;
Expand All @@ -586,6 +586,6 @@ int aumix_debug(struct re_printf *pf, struct aumix *mix)
}

out:
mtx_unlock(&mix->mutex);
mtx_unlock(mix->mutex);
return err;
}
Loading