From 67e8ef9debd01b1a150bfcbc5320c16d01290586 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 23 Feb 2023 15:53:26 +0100 Subject: [PATCH] More Sonar issues. --- examples/sthread/pthread-producer-consumer.c | 9 +++++---- src/kernel/EngineImpl.cpp | 3 +-- src/kernel/EngineImpl.hpp | 1 + src/s4u/s4u_Actor.cpp | 4 ++-- src/sthread/sthread_impl.cpp | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/sthread/pthread-producer-consumer.c b/examples/sthread/pthread-producer-consumer.c index bc0755036f..78deb2b018 100644 --- a/examples/sthread/pthread-producer-consumer.c +++ b/examples/sthread/pthread-producer-consumer.c @@ -58,7 +58,8 @@ int main(int argc, char** argv) { if (argc == 2 && strcmp(argv[1], "-q") == 0) do_output = 0; - pthread_t pro[2], con[2]; + pthread_t pro[2]; + pthread_t con[2]; pthread_mutex_init(&mutex, NULL); sem_init(&empty, 0, BufferSize); sem_init(&full, 0, 0); @@ -66,9 +67,9 @@ int main(int argc, char** argv) int ids[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // The identity of each thread (for debug messages) for (int i = 0; i < ProducerCount; i++) - pthread_create(&pro[i], NULL, (void*)producer, (void*)&ids[i]); + pthread_create(&pro[i], NULL, (void*)&producer, (void*)&ids[i]); for (int i = 0; i < ConsumerCount; i++) - pthread_create(&con[i], NULL, (void*)consumer, (void*)&ids[i]); + pthread_create(&con[i], NULL, (void*)&consumer, (void*)&ids[i]); for (int i = 0; i < ProducerCount; i++) pthread_join(pro[i], NULL); @@ -80,4 +81,4 @@ int main(int argc, char** argv) sem_destroy(&full); return 0; -} \ No newline at end of file +} diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 6b2da71b62..d493956782 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -178,8 +178,7 @@ void EngineImpl::initialize(int* argc, char** argv) simgrid::mc::AppSide::initialize(); #endif - static bool inited = false; - if (not inited) { + if (static bool inited = false; not inited) { inited = true; xbt_log_init(argc, argv); diff --git a/src/kernel/EngineImpl.hpp b/src/kernel/EngineImpl.hpp index ab1ea0711f..68624091c3 100644 --- a/src/kernel/EngineImpl.hpp +++ b/src/kernel/EngineImpl.hpp @@ -58,6 +58,7 @@ class EngineImpl { friend s4u::Engine; std::vector cmdline_; // Copy of the argv we got (including argv[0]) + public: EngineImpl() = default; diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 1e022aa5ea..3e84903f38 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -413,7 +413,7 @@ ExecPtr exec_async(double flops) aid_t get_pid() { - auto* self = simgrid::kernel::actor::ActorImpl::self(); + const auto* self = simgrid::kernel::actor::ActorImpl::self(); return self ? self->get_pid() : 0; } @@ -429,7 +429,7 @@ std::string get_name() const char* get_cname() { - auto* self = simgrid::kernel::actor::ActorImpl::self(); + const auto* self = simgrid::kernel::actor::ActorImpl::self(); return self ? self->get_cname() : nullptr; } diff --git a/src/sthread/sthread_impl.cpp b/src/sthread/sthread_impl.cpp index 2e2af7e0eb..807623177e 100644 --- a/src/sthread/sthread_impl.cpp +++ b/src/sthread/sthread_impl.cpp @@ -152,7 +152,7 @@ int sthread_mutex_destroy(sthread_mutex_t* mutex) intrusive_ptr_release(static_cast(mutex->mutex)); return 0; } -int sthread_sem_init(sthread_sem_t* sem, int pshared, unsigned int value) +int sthread_sem_init(sthread_sem_t* sem, int /*pshared*/, unsigned int value) { auto s = sg4::Semaphore::create(value); intrusive_ptr_add_ref(s.get()); @@ -187,7 +187,7 @@ int sthread_sem_trywait(sthread_sem_t* sem) } int sthread_sem_timedwait(sthread_sem_t* sem, const struct timespec* abs_timeout) { - if (static_cast(sem->sem)->acquire_timeout(abs_timeout->tv_sec + + if (static_cast(sem->sem)->acquire_timeout(static_cast(abs_timeout->tv_sec) + static_cast(abs_timeout->tv_nsec) / 1E9)) { errno = ETIMEDOUT; return -1; -- 2.20.1