From 512de713f191ed7ddfb1cb4251328a732b8a2ce7 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Thu, 24 Jan 2019 23:20:50 +0800 Subject: [PATCH] remove Wno-unused-variable --- build/ipc.pro | 2 +- src/platform/waiter_linux.h | 25 +++++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/build/ipc.pro b/build/ipc.pro index f936a9b..0f9441a 100644 --- a/build/ipc.pro +++ b/build/ipc.pro @@ -4,7 +4,7 @@ TARGET = ipc CONFIG -= qt CONFIG += c++14 c++1z # may be useless -!msvc:QMAKE_CXXFLAGS += -Wno-attributes -Wno-missing-field-initializers -Wno-unused-variable +!msvc:QMAKE_CXXFLAGS += -Wno-attributes -Wno-missing-field-initializers DEFINES += __IPC_LIBRARY__ DESTDIR = ../output diff --git a/src/platform/waiter_linux.h b/src/platform/waiter_linux.h index bc05124..24742bd 100644 --- a/src/platform/waiter_linux.h +++ b/src/platform/waiter_linux.h @@ -18,12 +18,7 @@ class waiter { std::atomic counter_ { 0 }; public: - using handle_t = void*; - -private: - constexpr static waiter* waiter_cast(handle_t h) { - return static_cast(h); - } + using handle_t = waiter*; public: constexpr static handle_t invalid() { @@ -73,23 +68,21 @@ public: void close(handle_t h) { if (h == invalid()) return; - auto w = waiter_cast(h); - if (w->counter_.fetch_sub(1, std::memory_order_acq_rel) == 1) { + if (h->counter_.fetch_sub(1, std::memory_order_acq_rel) == 1) { ::printf("destroy...\n"); - ::pthread_cond_destroy (&(w->cond_ )); - ::pthread_mutex_destroy(&(w->mutex_)); + ::pthread_cond_destroy (&(h->cond_ )); + ::pthread_mutex_destroy(&(h->mutex_)); ::printf("destroy end...\n"); } } bool wait(handle_t h) { if (h == invalid()) return false; - auto w = waiter_cast(h); - if (::pthread_mutex_lock(&(w->mutex_)) != 0) { + if (::pthread_mutex_lock(&(h->mutex_)) != 0) { return false; } - IPC_UNUSED_ auto guard = unique_ptr(&(w->mutex_), ::pthread_mutex_unlock); - if (::pthread_cond_wait(&(w->cond_), &(w->mutex_)) != 0) { + IPC_UNUSED_ auto guard = unique_ptr(&(h->mutex_), ::pthread_mutex_unlock); + if (::pthread_cond_wait(&(h->cond_), &(h->mutex_)) != 0) { return false; } return true; @@ -97,12 +90,12 @@ public: void notify(handle_t h) { if (h == invalid()) return; - ::pthread_cond_signal(&(waiter_cast(h)->cond_)); + ::pthread_cond_signal(&(h->cond_)); } void broadcast(handle_t h) { if (h == invalid()) return; - ::pthread_cond_broadcast(&(waiter_cast(h)->cond_)); + ::pthread_cond_broadcast(&(h->cond_)); } };