From 2996a6b5f82d3dffaeb11a2850d658f7e7f666fc Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Tue, 24 Sep 2019 08:52:18 +0200 Subject: [PATCH] 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 --- src/ddsrt/src/cdtors.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ddsrt/src/cdtors.c b/src/ddsrt/src/cdtors.c index ff7c5ee..c8fa25a 100644 --- a/src/ddsrt/src/cdtors.c +++ b/src/ddsrt/src/cdtors.c @@ -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;