diff --git a/include/def.h b/include/def.h index 2dc1cb7..e8fae87 100644 --- a/include/def.h +++ b/include/def.h @@ -9,6 +9,24 @@ namespace ipc { +// pre-defined + +#ifdef IPC_UNUSED_ +# error "IPC_UNUSED_ has been defined." +#endif + +#if __cplusplus >= 201703L +# define IPC_UNUSED_ [[maybe_unused]] +#else /*__cplusplus < 201703L*/ +#if defined(_MSC_VER) +# define IPC_UNUSED_ __pragma(warning(suppress: 4100 4101 4189)) +#elif defined(__GNUC__) +# define IPC_UNUSED_ __attribute__((__unused__)) +#else +# define IPC_UNUSED_ +#endif +#endif/*__cplusplus < 201703L*/ + // types using byte_t = std::uint8_t; diff --git a/src/memory/resource.hpp b/src/memory/resource.hpp index c3a6daf..6573643 100644 --- a/src/memory/resource.hpp +++ b/src/memory/resource.hpp @@ -7,6 +7,8 @@ #include #include +#include "def.h" + #include "memory/alloc.hpp" #include "memory/wrapper.hpp" @@ -32,7 +34,7 @@ constexpr void static_for(std::index_sequence, F&& f) { #else /*__cplusplus < 201703L*/ inline void static_for(std::index_sequence, F&& f) { #endif/*__cplusplus < 201703L*/ - [[maybe_unused]] auto expand = { (f(std::integral_constant{}), 0)... }; + auto IPC_UNUSED_ expand = { (f(std::integral_constant{}), 0)... }; } template diff --git a/src/memory/wrapper.hpp b/src/memory/wrapper.hpp index b96d15d..92f7416 100644 --- a/src/memory/wrapper.hpp +++ b/src/memory/wrapper.hpp @@ -12,6 +12,7 @@ #include #include +#include "def.h" #include "rw_lock.h" #include "tls_pointer.h" @@ -52,7 +53,7 @@ private: alloc_t(synchronized* t) : t_ { t } { { - [[maybe_unused]] auto guard = ipc::detail::unique_lock(t_->lc_); + auto IPC_UNUSED_ guard = ipc::detail::unique_lock(t_->lc_); auto it = t_->allocs_.begin(); if (it != t_->allocs_.end()) { std::tie(s_, a_) = *it; @@ -65,7 +66,7 @@ private: } ~alloc_t() { - [[maybe_unused]] auto guard = ipc::detail::unique_lock(t_->lc_); + auto IPC_UNUSED_ guard = ipc::detail::unique_lock(t_->lc_); t_->allocs_.emplace(s_, a_); } diff --git a/src/platform/shm_linux.cpp b/src/platform/shm_linux.cpp index a8f50f2..baf79e0 100644 --- a/src/platform/shm_linux.cpp +++ b/src/platform/shm_linux.cpp @@ -11,6 +11,7 @@ #include #include +#include "def.h" #include "memory/resource.hpp" namespace { @@ -65,7 +66,7 @@ void* acquire(char const * name, std::size_t size) { auto acc = acc_of(mem); acc->fetch_add(1, std::memory_order_release); { - [[maybe_unused]] auto guard = ipc::detail::unique_lock(m2h()->lc_); + auto IPC_UNUSED_ guard = ipc::detail::unique_lock(m2h()->lc_); m2h()->cache_.emplace(++acc, std::move(op_name)); } return acc; @@ -75,7 +76,7 @@ void release(void* mem, std::size_t size) { if (mem == nullptr) { return; } - [[maybe_unused]] auto guard = ipc::detail::unique_lock(m2h()->lc_); + auto IPC_UNUSED_ guard = ipc::detail::unique_lock(m2h()->lc_); auto& cc = m2h()->cache_; auto it = cc.find(mem); if (it == cc.end()) { diff --git a/src/platform/shm_win.cpp b/src/platform/shm_win.cpp index 6136414..225e38b 100644 --- a/src/platform/shm_win.cpp +++ b/src/platform/shm_win.cpp @@ -43,7 +43,7 @@ void* acquire(char const * name, std::size_t size) { return nullptr; } { - [[maybe_unused]] auto guard = ipc::detail::unique_lock(m2h()->lc_); + auto IPC_UNUSED_ guard = ipc::detail::unique_lock(m2h()->lc_); m2h()->cache_.emplace(mem, h); } return mem; @@ -53,7 +53,7 @@ void release(void* mem, std::size_t /*size*/) { if (mem == nullptr) { return; } - [[maybe_unused]] auto guard = ipc::detail::unique_lock(m2h()->lc_); + auto IPC_UNUSED_ guard = ipc::detail::unique_lock(m2h()->lc_); auto& cc = m2h()->cache_; auto it = cc.find(mem); if (it == cc.end()) { diff --git a/src/platform/waiter_linux.h b/src/platform/waiter_linux.h index a0f704f..2ffec49 100644 --- a/src/platform/waiter_linux.h +++ b/src/platform/waiter_linux.h @@ -7,6 +7,8 @@ #include #include +#include "def.h" + #if __cplusplus >= 201703L namespace std { @@ -58,7 +60,7 @@ public: if (::pthread_mutexattr_init(&mutex_attr) != 0) { return invalid(); } - [[maybe_unused]] auto guard_mutex_attr = unique_ptr(&mutex_attr, ::pthread_mutexattr_destroy); + auto IPC_UNUSED_ guard_mutex_attr = unique_ptr(&mutex_attr, ::pthread_mutexattr_destroy); if (::pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED) != 0) { return invalid(); } @@ -71,7 +73,7 @@ public: if (::pthread_condattr_init(&cond_attr) != 0) { return invalid(); } - [[maybe_unused]] auto guard_cond_attr = unique_ptr(&cond_attr, ::pthread_condattr_destroy); + auto IPC_UNUSED_ guard_cond_attr = unique_ptr(&cond_attr, ::pthread_condattr_destroy); if (::pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED) != 0) { return invalid(); } @@ -100,7 +102,7 @@ public: if (::pthread_mutex_lock(&(w->mutex_)) != 0) { return false; } - [[maybe_unused]] auto guard = unique_ptr(&(w->mutex_), ::pthread_mutex_unlock); + auto IPC_UNUSED_ guard = unique_ptr(&(w->mutex_), ::pthread_mutex_unlock); if (::pthread_cond_wait(&(w->cond_), &(w->mutex_)) != 0) { return false; }