From ee03010e77b70a64830544b0d3827b92463cc798 Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Mon, 4 Sep 2023 15:09:53 +0200 Subject: [PATCH] fixup! Fix race condition in main loop --- apps/cloud_server.c | 8 +++++++- docker/apps/Dockerfile.cloud-server-debug | 2 +- util/oc_compiler.h | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/cloud_server.c b/apps/cloud_server.c index e21b07417b..41c4c43516 100644 --- a/apps/cloud_server.c +++ b/apps/cloud_server.c @@ -26,6 +26,7 @@ #include "oc_pki.h" #include "oc_clock_util.h" #include "port/oc_assert.h" +#include "util/oc_compiler.h" #include "util/oc_features.h" #include "util/oc_process.h" @@ -119,7 +120,12 @@ static pthread_mutex_t g_mutex; static pthread_cond_t g_cv; static void -signal_event_loop(void) +#if !defined(__clang__) && defined(__GNUC__) + /* gcc with thread sanitizer enabled reports a double lock when + pthread_cond_signal is called under a locked mutex */ + __attribute__((no_sanitize("thread"))) +#endif /* !__clang__ && __GNUC__ */ + signal_event_loop(void) { pthread_mutex_lock(&g_mutex); pthread_cond_signal(&g_cv); diff --git a/docker/apps/Dockerfile.cloud-server-debug b/docker/apps/Dockerfile.cloud-server-debug index 4f00bf3313..9e1a6d986c 100644 --- a/docker/apps/Dockerfile.cloud-server-debug +++ b/docker/apps/Dockerfile.cloud-server-debug @@ -7,7 +7,7 @@ COPY ./ /iotivity-lite/ RUN cd /iotivity-lite/ && git submodule update --recursive RUN mkdir /iotivity-lite/build && \ cd /iotivity-lite/build && \ - cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_TESTING=OFF -DOC_CLOUD_ENABLED=ON ${BUILD_ARGS} .. && \ + cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_TESTING=OFF -DOC_CLOUD_ENABLED=ON ${BUILD_ARGS} .. && \ cmake --build . --target cloud_server RUN cp /iotivity-lite/build/apps/cloud_server /iotivity-lite/port/linux/service diff --git a/util/oc_compiler.h b/util/oc_compiler.h index a4daaf2dd5..c8c7ed6bac 100644 --- a/util/oc_compiler.h +++ b/util/oc_compiler.h @@ -67,6 +67,12 @@ #define OC_RETURNS_NONNULL #endif +#if defined(__clang__) || defined(__GNUC__) +#define OC_NO_SANITIZE(...) __attribute__((no_sanitize(__VA_ARGS__))) +#else +#define OC_NO_SANITIZE(...) +#endif + #if defined(__clang__) || defined(__GNUC__) #if defined(__MINGW32__) && defined(__USE_MINGW_ANSI_STDIO) && \ __USE_MINGW_ANSI_STDIO == 1