hexagon: fix futex race in hmx_worker_drain

Store the boolean to local variable avoid atomic load twice
This commit is contained in:
njsyw1997
2026-04-11 16:32:52 -07:00
committed by Max Krasnyansky
parent b2ec80a65f
commit f14e9c6f4c
+9 -2
View File
@@ -98,8 +98,15 @@ static void hmx_worker_issue(struct hmx_worker_context * ctx,
// Block until the worker has completed the most recently issued command.
static void hmx_worker_drain(struct hmx_worker_context * ctx) {
unsigned int expected = atomic_load_explicit(&ctx->cmd_seqn, memory_order_acquire);
while (atomic_load_explicit(&ctx->done_seqn, memory_order_acquire) != expected) {
qurt_futex_wait(&ctx->done_seqn, atomic_load_explicit(&ctx->done_seqn, memory_order_relaxed));
for (;;) {
unsigned int seen = atomic_load_explicit(&ctx->done_seqn, memory_order_acquire);
if (seen == expected) {
return;
}
// Pass the same observed value to futex_wait(). If the worker completes
// between the load above and the futex call, the value mismatch makes the
// wait return immediately instead of sleeping forever on the new seqn.
qurt_futex_wait(&ctx->done_seqn, seen);
}
}