Let Coverity ignore sleep in ddsrt init "spinlock"

Initialisation of ddsrt layer uses a hand-rolled CAS/sleep device not
unlike a spin lock.  This so initialisation doesn't depend on, e.g.,
ddsrt_once.

Checking or changing thread states between "awake" and "asleep" can end
up in ddsrt_init if the thread is unknown at the time of the call.
Once really only ends up in those cases when the library is initialised
already, in which case no sleeping occurs.

In any case, the sleep is just a friendly yielding of the CPU.  Coverity
will still see the loop, just not the sleep.

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-09-24 08:52:18 +02:00 committed by eboasson
parent d1ad60fdd1
commit 2996a6b5f8

View file

@ -49,7 +49,13 @@ retry:
ddsrt_atomic_or32(&init_status, INIT_STATUS_OK);
} else {
while (v > 1 && !(v & INIT_STATUS_OK)) {
#ifndef __COVERITY__
/* This sleep makes Coverity warn about possibly sleeping while holding in a lock
in many places, all because just-in-time creation of a thread descriptor ends
up here. Since sleeping is merely meant as a better alternative to spinning,
skip the sleep when being analyzed. */
dds_sleepfor(10000000);
#endif
v = ddsrt_atomic_ld32(&init_status);
}
goto retry;