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

rz_core_task_join: Return true on join #4474

Merged
merged 1 commit into from
May 6, 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
21 changes: 14 additions & 7 deletions librz/core/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,33 @@ RZ_API int rz_core_task_running_tasks_count(RzCoreTaskScheduler *scheduler) {
return count;
}

static void task_join(RzCoreTask *task) {
static bool task_join(RzCoreTask *task) {
RzThreadSemaphore *sem = task->running_sem;
if (!sem) {
return;
return false;
}

rz_th_sem_wait(sem);
rz_th_sem_post(sem);
return true;
}

RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id) {
RZ_API bool rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id) {
bool ret = true;
if (current && id == current->id) {
return;
return false;
}
if (id >= 0) {
RzCoreTask *task = rz_core_task_get_incref(scheduler, id);
if (!task) {
return;
return false;
}
if (current) {
rz_core_task_sleep_begin(current);
}
task_join(task);
if (!task_join(task)) {
ret = false;
}
if (current) {
rz_core_task_sleep_end(current);
}
Expand All @@ -131,14 +135,17 @@ RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *curren
if (current) {
rz_core_task_sleep_begin(current);
}
task_join(task);
if (!task_join(task)) {
ret = false;
}
if (current) {
rz_core_task_sleep_end(current);
}
rz_core_task_decref(task);
}
rz_list_free(tasks);
}
return ret;
}

static void task_free(RzCoreTask *task) {
Expand Down
2 changes: 1 addition & 1 deletion librz/include/rz_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ RZ_API void rz_core_task_break(RzCoreTaskScheduler *scheduler, int id);
RZ_API void rz_core_task_break_all(RzCoreTaskScheduler *scheduler);
RZ_API int rz_core_task_del(RzCoreTaskScheduler *scheduler, int id);
RZ_API RzCoreTask *rz_core_task_self(RzCoreTaskScheduler *scheduler);
RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id);
RZ_API bool rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id);
typedef void (*inRangeCb)(RzCore *core, ut64 from, ut64 to, int vsize, void *cb_user);
RZ_API int rz_core_search_value_in_range(RzCore *core, RzInterval search_itv,
ut64 vmin, ut64 vmax, int vsize, inRangeCb cb, void *cb_user);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/test_core_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ static bool test_core_task_finished_cb(void) {
RzCoreTask *a = rz_core_cmd_task_new(core, "echo amor; echo vincit; echo omnia", finished_cb, &res_indir);
rz_core_task_enqueue(&core->tasks, a);

rz_core_task_join(&core->tasks, rz_core_task_self(&core->tasks), a->id);
bool task_joined = rz_core_task_join(&core->tasks, rz_core_task_self(&core->tasks), a->id);
mu_assert_true(task_joined, "task joined");

const char *cmd_result = rz_core_cmd_task_get_result(a);
mu_assert_streq(cmd_result, "amor\nvincit\nomnia\n", "cmd result");
Expand Down
Loading