Skip to content

Commit

Permalink
async,main: make re_thread_async itself thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Jan 11, 2023
1 parent a1e31bf commit 755ea46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/async/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ int re_async(struct re_async *async, re_async_work_h *workh, re_async_h *cb,
if (unlikely(!async))
return EINVAL;

mtx_lock(&async->mtx);
if (unlikely(list_isempty(&async->freel))) {
async_work = mem_zalloc(sizeof(struct async_work), NULL);
if (!async_work)
return ENOMEM;
if (!async_work) {
err = ENOMEM;
goto out;
}
}
else {
async_work = list_head(&async->freel)->data;
Expand All @@ -239,9 +242,10 @@ int re_async(struct re_async *async, re_async_work_h *workh, re_async_h *cb,
async_work->cb = cb;
async_work->arg = arg;

mtx_lock(&async->mtx);
list_append(&async->workl, &async_work->le, async_work);
cnd_signal(&async->wait);

out:
mtx_unlock(&async->mtx);

return err;
Expand Down
6 changes: 0 additions & 6 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1540,11 +1540,5 @@ int re_thread_async(re_async_work_h *work, re_async_h *cb, void *arg)
return err;
}

#ifndef RELEASE
err = re_thread_check();
if (err)
return err;
#endif

return re_async(re->async, work, cb, arg);
}

0 comments on commit 755ea46

Please sign in to comment.