]> git.corax.cc Git - toolbox/commit
include/inst: Make subsequent calls to inst_running() return false
authorMatthias Kruk <m@m10k.eu>
Thu, 22 Jul 2021 23:21:48 +0000 (08:21 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 22 Jul 2021 23:36:15 +0000 (08:36 +0900)
commit7c40b02004a8d4bb5c7aa14fc32b32318d24fd5a
tree23d658114d7e370367a390fe1a78ca7a772fceba
parent6a8ec48b65b374e20e5624969eb553de11fc28a5
include/inst: Make subsequent calls to inst_running() return false

When an instance is instructed to stop, a semaphore is increased to
signal this condition. The inst_running() function uses sem_trywait()
on this semaphore, returning false if the semaphore could be passed,
thus telling the caller that the instance should be stopped.
However, since sem_trywait() decreases the semaphore, subsequent calls
to inst_running() will return true again.
This commit changes inst_running() to increase the semaphore in case
it was decreased by sem_trywait(). However, there remains a small
window of opportunity where the function may return different values
to different callers if multiple processes from the same instance call
the function at the same time.
include/inst.sh