mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
IPC_UNUSED_
This commit is contained in:
parent
05ff0efc25
commit
b52eae7c90
@ -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;
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "def.h"
|
||||
|
||||
#include "memory/alloc.hpp"
|
||||
#include "memory/wrapper.hpp"
|
||||
|
||||
@ -32,7 +34,7 @@ constexpr void static_for(std::index_sequence<I...>, F&& f) {
|
||||
#else /*__cplusplus < 201703L*/
|
||||
inline void static_for(std::index_sequence<I...>, F&& f) {
|
||||
#endif/*__cplusplus < 201703L*/
|
||||
[[maybe_unused]] auto expand = { (f(std::integral_constant<size_t, I>{}), 0)... };
|
||||
auto IPC_UNUSED_ expand = { (f(std::integral_constant<size_t, I>{}), 0)... };
|
||||
}
|
||||
|
||||
template <std::size_t Size>
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
#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_);
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <utility>
|
||||
#include <mutex>
|
||||
|
||||
#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()) {
|
||||
|
||||
@ -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()) {
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user