Skip to content

Commit

Permalink
xrun: Add locking to pause/resume operations
Browse files Browse the repository at this point in the history
Add locking to pause and resume operations to prevent container->status
from getting out of sync with the actual state of the container.

Signed-off-by: Mykyta Poturai <[email protected]>
  • Loading branch information
Deedone committed Aug 2, 2024
1 parent f8cc403 commit 9b61505
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions xrun/src/xrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct container {
char dt_image[CONFIG_XRUN_MAX_PATH_SIZE];
bool has_dt_image;
enum container_status status;
struct k_mutex lock;
int refcount;
};

Expand Down Expand Up @@ -234,6 +235,7 @@ static struct container *register_container_id(const char *container_id)

strncpy(container->container_id, container_id, CONTAINER_NAME_SIZE);
container->domid = next_domid++;
k_mutex_init(&container->lock);

sys_slist_append(&container_list, &container->node);
container->refcount = 1;
Expand Down Expand Up @@ -631,6 +633,7 @@ int xrun_pause(const char *container_id)
if (!container) {
return -EINVAL;
}
k_mutex_lock(&container->lock, K_FOREVER);

ret = domain_pause(container->domid);
if (ret) {
Expand All @@ -639,6 +642,7 @@ int xrun_pause(const char *container_id)

container->status = PAUSED;
out:
k_mutex_unlock(&container->lock);
put_container(container);
return ret;
}
Expand All @@ -651,6 +655,7 @@ int xrun_resume(const char *container_id)
if (!container) {
return -EINVAL;
}
k_mutex_lock(&container->lock, K_FOREVER);

ret = domain_unpause(container->domid);
if (ret) {
Expand All @@ -659,6 +664,7 @@ int xrun_resume(const char *container_id)

container->status = RUNNING;
out:
k_mutex_unlock(&container->lock);
put_container(container);
return ret;
}
Expand Down

0 comments on commit 9b61505

Please sign in to comment.