• Lars-Peter Clausen's avatar
    iio:trigger: Fix use_count race condition · a1a8e1dc
    Lars-Peter Clausen authored
    When using more than one trigger consumer it can happen that multiple threads
    perform a read-modify-update cycle on 'use_count' concurrently. This can cause
    updates to be lost and use_count can get stuck at non-zero value, in which case
    the IIO core assumes that at least one thread is still running and will wait for
    it to finish before running any trigger handlers again. This effectively renders
    the trigger disabled and a reboot is necessary before it can be used again. To
    fix this make use_count an atomic variable. Also set it to the number of
    consumers before starting the first consumer, otherwise it might happen that
    use_count drops to 0 even though not all consumers have been run yet.
    Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
    Tested-by: default avatarDenis Ciocca <denis.ciocca@st.com>
    Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
    a1a8e1dc
industrialio-trigger.c 12.5 KB