light
light copied to clipboard
Only allow one process per target for writes
What do we need?
We need to limit the amount of processes that want to write to a single target at the same time, without limiting user operations. When light is executed to write to a target, it must first kill any conflicting processes.
Why do we need it?
As a prerequisite to smooth transitions. Smooth transitions would execute many sequential writes over a period of time in the same process. If multiple process instances write to the same target at the same time, jittery and undefined behaviour would occur. Therefore, any older light processes that target the same target must be killed before any writes are made.
How do we achieve it?
At program start, when we have decided to write to a target, check for writelocks (using fcntl) on cache/target/pid
. If it is locked, read the pid and kill the process it refers to (assert process filename). Then, create a write lock and write our own pid to the file, then proceed as normal. When program exits, lock is released.
What about handling it more like a mutex? I.e. the first caller gets the lock, the second caller either waits for the lock to clear or aborts with an error (perhaps with an optional flag --force
to kill the process holding the lock?).
Just throwing this out there for discussion. I don't really have a strong preference here, but I do think unconditionally killing the lock holder is kind of iffy.
Handling it like a mutex defeats the whole purpose. It would block the user experience just for managing fades. Killing it would make sure usage has a defined behaviour.