Closed tsoutsman closed 1 year ago
The syntax is also similar to fetch_update
from the world of atomics, though I'm not sure if that's actually superior to update. Another option could be update_with
, since functions that take closures to operate on some value often use the word "with" in Rust.
Regarding the two options, I think having an update method of some kind is a good choice. In the specific case of the scheduler, we might need to wrap SCHEDULERS
(ideally we'd use a name that's more than 1 character different than SCHEDULER
...) in an interrupt-safe mutex since schedulers generally are accessed within interrupt contexts.
Regarding whether to disable interrupts or preemption, in the general case preemption should suffice, since you typically just expect to access something local to the CPU in a way that would still work if the update function logic had to persist across jumps to interrupt handlers. If a particular case requires more "atomicity", i.e., no interrupts can happen, then I'd say that's on the developer of that particular case to disable interrupts separately.
I'm curious to see how SCHEDULERS
gets used, since it's pretty tough to coordinate things across multiple CPUs simultaneously.
I think I'll leave it as update
because fetch_update
also has a different API, and we aren't really fetching the value. Also AFAICT container types usually don't have "with" functions.
Not sure if
update
is the "correct" name. The closest analogue I could find instd
isCell::update
, but that has a very different API.This function is necessary for some upcoming work on the scheduler. Essentially, there's a global list of schedulers, and then also a CPU-local which contains a reference to the current CPUs scheduler.
So
SCHEDULER
would contain a reference that is also an entry inSCHEDULERS
.Now, when updating the policy we need to remove the scheduler from
SCHEDULERS
and updateSCHEDULER
in a special way to prevent race conditions:But we should really be abstracting away from preemption:
Both snippets of code are functionally equivalent, but the latter one is at a higher abstraction level with fewer footguns.