core/host/task: Fix task_set_event
task_set_event is expected to _add_ the event bit to the current
mask, not reset the whole mask.
Also, fix all operations to use atomics.
BRANCH=none
TEST=No more timeouts when running usb_pd fuzzing tests.
@@ -183,7 +183,7 @@ pthread_t task_get_thread(task_id_t tskid)
uint32_t task_set_event(task_id_t tskid, uint32_t event, int wait)
{
- tasks[tskid].event = event;
+ atomic_or(&tasks[tskid].event, event);
if (wait)
return task_wait_event(-1);
return 0;
@@ -202,8 +202,7 @@ uint32_t task_wait_event(int timeout_us)
pthread_cond_wait(&tasks[tid].resume, &run_lock);
/* Resume */
- ret = tasks[tid].event;
- tasks[tid].event = 0;
+ ret = atomic_read_clear(&tasks[tid].event);
pthread_mutex_unlock(&interrupt_lock);
return ret;
}
@@ -231,7 +230,8 @@ uint32_t task_wait_event_mask(uint32_t event_mask, int timeout_us)
/* Re-post any other events collected */
if (events & ~event_mask)
- tasks[task_get_current()].event |= events & ~event_mask;
+ atomic_or(&tasks[task_get_current()].event,
+ events & ~event_mask);
return events & event_mask;
}
