diff --git a/src/libipc/circ/elem_def.h b/src/libipc/circ/elem_def.h index 1b6c6ec..2e88823 100755 --- a/src/libipc/circ/elem_def.h +++ b/src/libipc/circ/elem_def.h @@ -33,7 +33,7 @@ public: void init() { /* DCLP */ if (!constructed_.load(std::memory_order_acquire)) { - IPC_UNUSED_ auto guard = ipc::detail::unique_lock(lc_); + LIBIPC_UNUSED auto guard = ipc::detail::unique_lock(lc_); if (!constructed_.load(std::memory_order_relaxed)) { ::new (this) conn_head_base; constructed_.store(true, std::memory_order_release); diff --git a/src/libipc/ipc.cpp b/src/libipc/ipc.cpp index e71dca9..419d3d2 100755 --- a/src/libipc/ipc.cpp +++ b/src/libipc/ipc.cpp @@ -252,12 +252,12 @@ chunk_info_t *chunk_storage_info(conn_info_head *inf, std::size_t chunk_size) { std::decay_t::iterator it; { static ipc::rw_lock lock; - IPC_UNUSED_ std::shared_lock guard {lock}; + LIBIPC_UNUSED std::shared_lock guard {lock}; if ((it = storages.find(chunk_size)) == storages.end()) { using chunk_handle_ptr_t = std::decay_t::value_type::second_type; using chunk_handle_t = chunk_handle_ptr_t::element_type; guard.unlock(); - IPC_UNUSED_ std::lock_guard guard {lock}; + LIBIPC_UNUSED std::lock_guard guard {lock}; it = storages.emplace(chunk_size, chunk_handle_ptr_t{ ipc::mem::alloc(), [](chunk_handle_t *p) { ipc::mem::destruct(p); @@ -669,7 +669,7 @@ static ipc::buff_t recv(ipc::handle_t h, std::uint64_t tm) { } else { return ipc::buff_t{buf, msg_size, [](void* p_info, std::size_t size) { auto r_info = static_cast(p_info); - IPC_UNUSED_ auto finally = ipc::guard([r_info] { + LIBIPC_UNUSED auto finally = ipc::guard([r_info] { ipc::mem::free(r_info); }); recycle_storage(r_info->storage_id, diff --git a/src/libipc/memory/wrapper.h b/src/libipc/memory/wrapper.h index b0b7c58..cf0b905 100755 --- a/src/libipc/memory/wrapper.h +++ b/src/libipc/memory/wrapper.h @@ -51,13 +51,13 @@ protected: public: void try_recover(alloc_policy & alc) { - IPC_UNUSED_ auto guard = ipc::detail::unique_lock(master_lock_); + LIBIPC_UNUSED auto guard = ipc::detail::unique_lock(master_lock_); if (master_allocs_.empty()) return; take_first_do([&alc](alloc_policy & first) { alc.swap(first); }); } void collect(alloc_policy && alc) { - IPC_UNUSED_ auto guard = ipc::detail::unique_lock(master_lock_); + LIBIPC_UNUSED auto guard = ipc::detail::unique_lock(master_lock_); if (master_allocs_.size() >= 32) { take_first_do([](alloc_policy &) {}); // erase first } @@ -75,7 +75,7 @@ class default_recycler : public limited_recycler { template void try_fill(A & alc) { - IPC_UNUSED_ auto guard = ipc::detail::unique_lock(this->master_lock_); + LIBIPC_UNUSED auto guard = ipc::detail::unique_lock(this->master_lock_); if (this->master_allocs_.empty()) return; this->take_first_do([&alc](alloc_policy & first) { alc.take(std::move(first)); }); } @@ -197,17 +197,17 @@ public: {} void swap(sync_wrapper& rhs) { - IPC_UNUSED_ auto guard = ipc::detail::unique_lock(lock_); + LIBIPC_UNUSED auto guard = ipc::detail::unique_lock(lock_); alloc_.swap(rhs.alloc_); } void* alloc(std::size_t size) { - IPC_UNUSED_ auto guard = ipc::detail::unique_lock(lock_); + LIBIPC_UNUSED auto guard = ipc::detail::unique_lock(lock_); return alloc_.alloc(size); } void free(void* p, std::size_t size) { - IPC_UNUSED_ auto guard = ipc::detail::unique_lock(lock_); + LIBIPC_UNUSED auto guard = ipc::detail::unique_lock(lock_); alloc_.free(p, size); } }; diff --git a/src/libipc/platform/detail.h b/src/libipc/platform/detail.h index 4d6a27c..97b7b29 100755 --- a/src/libipc/platform/detail.h +++ b/src/libipc/platform/detail.h @@ -1,20 +1,7 @@ #ifndef LIBIPC_SRC_PLATFORM_DETAIL_H_ #define LIBIPC_SRC_PLATFORM_DETAIL_H_ -// detect platform - -#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || \ - defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || \ - defined(WINCE) || defined(_WIN32_WCE) -# define IPC_OS_WINDOWS_ -#elif defined(__linux__) || defined(__linux) -# define IPC_OS_LINUX_ -#elif defined(__QNX__) -# define IPC_OS_QNX_ -#elif defined(__APPLE__) -#elif defined(__ANDROID__) -// TBD -#endif +#include "libipc/imp/detect_plat.h" #if defined(__cplusplus) @@ -27,12 +14,6 @@ // pre-defined -#ifdef IPC_UNUSED_ -# error "IPC_UNUSED_ has been defined." -#endif -#ifdef IPC_FALLTHROUGH_ -# error "IPC_FALLTHROUGH_ has been defined." -#endif #ifdef IPC_STBIND_ # error "IPC_STBIND_ has been defined." #endif @@ -42,23 +23,11 @@ #if __cplusplus >= 201703L -#define IPC_UNUSED_ [[maybe_unused]] -#define IPC_FALLTHROUGH_ [[fallthrough]] #define IPC_STBIND_(A, B, ...) auto [A, B] = __VA_ARGS__ #define IPC_CONSTEXPR_ constexpr #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 - -#define IPC_FALLTHROUGH_ - #define IPC_STBIND_(A, B, ...) \ auto tp___ = __VA_ARGS__ \ auto A = std::get<0>(tp___); \ diff --git a/src/libipc/platform/linux/mutex.h b/src/libipc/platform/linux/mutex.h index 3ece297..5f4da37 100644 --- a/src/libipc/platform/linux/mutex.h +++ b/src/libipc/platform/linux/mutex.h @@ -122,7 +122,7 @@ class mutex { return; } auto &info = curr_prog::get(); - IPC_UNUSED_ std::lock_guard guard {info.lock}; + LIBIPC_UNUSED std::lock_guard guard {info.lock}; auto it = info.mutex_handles.find(name); if (it == info.mutex_handles.end()) { it = info.mutex_handles @@ -139,7 +139,7 @@ class mutex { static void release_mutex(ipc::string const &name, F &&clear) { if (name.empty()) return; auto &info = curr_prog::get(); - IPC_UNUSED_ std::lock_guard guard {info.lock}; + LIBIPC_UNUSED std::lock_guard guard {info.lock}; auto it = info.mutex_handles.find(name); if (it == info.mutex_handles.end()) { return; diff --git a/src/libipc/platform/platform.c b/src/libipc/platform/platform.c index 49cc977..7b225bc 100644 --- a/src/libipc/platform/platform.c +++ b/src/libipc/platform/platform.c @@ -1,13 +1,13 @@ #include "libipc/platform/detail.h" -#if defined(IPC_OS_WINDOWS_) -#elif defined(IPC_OS_LINUX_) +#if defined(LIBIPC_OS_WIN) +#elif defined(LIBIPC_OS_LINUX) #include "libipc/platform/linux/a0/err.c" #include "libipc/platform/linux/a0/mtx.c" #include "libipc/platform/linux/a0/strconv.c" #include "libipc/platform/linux/a0/tid.c" #include "libipc/platform/linux/a0/time.c" -#elif defined(IPC_OS_QNX_) +#elif defined(LIBIPC_OS_QNX) #else/*IPC_OS*/ # error "Unsupported platform." #endif diff --git a/src/libipc/platform/platform.cpp b/src/libipc/platform/platform.cpp index b77cbc9..0e31553 100644 --- a/src/libipc/platform/platform.cpp +++ b/src/libipc/platform/platform.cpp @@ -1,8 +1,8 @@ #include "libipc/platform/detail.h" -#if defined(IPC_OS_WINDOWS_) +#if defined(LIBIPC_OS_WIN) #include "libipc/platform/win/shm_win.cpp" -#elif defined(IPC_OS_LINUX_) || defined(IPC_OS_QNX_) +#elif defined(LIBIPC_OS_LINUX) || defined(LIBIPC_OS_QNX) #include "libipc/platform/posix/shm_posix.cpp" #else/*IPC_OS*/ # error "Unsupported platform." diff --git a/src/libipc/platform/posix/condition.h b/src/libipc/platform/posix/condition.h index 541c0ef..2b543a2 100644 --- a/src/libipc/platform/posix/condition.h +++ b/src/libipc/platform/posix/condition.h @@ -63,7 +63,7 @@ public: ipc::error("fail pthread_condattr_init[%d]\n", eno); return false; } - IPC_UNUSED_ auto guard_cond_attr = guard([&cond_attr] { ::pthread_condattr_destroy(&cond_attr); }); + LIBIPC_UNUSED auto guard_cond_attr = guard([&cond_attr] { ::pthread_condattr_destroy(&cond_attr); }); if ((eno = ::pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED)) != 0) { ipc::error("fail pthread_condattr_setpshared[%d]\n", eno); return false; diff --git a/src/libipc/platform/posix/mutex.h b/src/libipc/platform/posix/mutex.h index 2293678..f18f69b 100644 --- a/src/libipc/platform/posix/mutex.h +++ b/src/libipc/platform/posix/mutex.h @@ -52,7 +52,7 @@ class mutex { return nullptr; } auto &info = curr_prog::get(); - IPC_UNUSED_ std::lock_guard guard {info.lock}; + LIBIPC_UNUSED std::lock_guard guard {info.lock}; auto it = info.mutex_handles.find(name); if (it == info.mutex_handles.end()) { it = info.mutex_handles @@ -74,7 +74,7 @@ class mutex { static void release_mutex(ipc::string const &name, F &&clear) { if (name.empty()) return; auto &info = curr_prog::get(); - IPC_UNUSED_ std::lock_guard guard {info.lock}; + LIBIPC_UNUSED std::lock_guard guard {info.lock}; auto it = info.mutex_handles.find(name); if (it == info.mutex_handles.end()) { return; @@ -130,7 +130,7 @@ public: ipc::error("fail pthread_mutexattr_init[%d]\n", eno); return false; } - IPC_UNUSED_ auto guard_mutex_attr = guard([&mutex_attr] { ::pthread_mutexattr_destroy(&mutex_attr); }); + LIBIPC_UNUSED auto guard_mutex_attr = guard([&mutex_attr] { ::pthread_mutexattr_destroy(&mutex_attr); }); if ((eno = ::pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED)) != 0) { ipc::error("fail pthread_mutexattr_setpshared[%d]\n", eno); return false; diff --git a/src/libipc/platform/win/condition.h b/src/libipc/platform/win/condition.h index 69d7fe1..1bc3851 100644 --- a/src/libipc/platform/win/condition.h +++ b/src/libipc/platform/win/condition.h @@ -85,7 +85,7 @@ public: if (!valid()) return false; auto &cnt = counter(); { - IPC_UNUSED_ std::lock_guard guard {lock_}; + LIBIPC_UNUSED std::lock_guard guard {lock_}; cnt = (cnt < 0) ? 1 : cnt + 1; } DWORD ms = (tm == invalid_value) ? INFINITE : static_cast(tm); @@ -97,7 +97,7 @@ public: bool rs = ::SignalObjectAndWait(mtx.native(), sem_.native(), ms, FALSE) == WAIT_OBJECT_0; bool rl = mtx.lock(); // INFINITE if (!rs) { - IPC_UNUSED_ std::lock_guard guard {lock_}; + LIBIPC_UNUSED std::lock_guard guard {lock_}; cnt -= 1; } return rs && rl; diff --git a/src/libipc/platform/win/mutex.h b/src/libipc/platform/win/mutex.h index 6fd45d0..eeb6c6a 100644 --- a/src/libipc/platform/win/mutex.h +++ b/src/libipc/platform/win/mutex.h @@ -88,7 +88,7 @@ public: return false; case WAIT_ABANDONED: unlock(); - IPC_FALLTHROUGH_; + LIBIPC_FALLTHROUGH; default: ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret); throw std::system_error{static_cast(ret), std::system_category()}; diff --git a/src/libipc/platform/win/system.h b/src/libipc/platform/win/system.h index 645de2f..25a7add 100644 --- a/src/libipc/platform/win/system.h +++ b/src/libipc/platform/win/system.h @@ -74,7 +74,7 @@ result conf(info r) noexcept { LIBIPC_LOG(); switch (r) { case info::page_size: { - ::SYSTEM_INFO info {}; + ::SYSTEM_INFO info{}; ::GetNativeSystemInfo(&info); return (std::int64_t)info.dwPageSize; } diff --git a/src/libipc/sync/condition.cpp b/src/libipc/sync/condition.cpp index e64e688..dbb5745 100644 --- a/src/libipc/sync/condition.cpp +++ b/src/libipc/sync/condition.cpp @@ -5,11 +5,11 @@ #include "libipc/utility/log.h" #include "libipc/memory/resource.h" #include "libipc/platform/detail.h" -#if defined(IPC_OS_WINDOWS_) +#if defined(LIBIPC_OS_WIN) #include "libipc/platform/win/condition.h" -#elif defined(IPC_OS_LINUX_) +#elif defined(LIBIPC_OS_LINUX) #include "libipc/platform/linux/condition.h" -#elif defined(IPC_OS_QNX_) +#elif defined(LIBIPC_OS_QNX) #include "libipc/platform/posix/condition.h" #else/*IPC_OS*/ # error "Unsupported platform." diff --git a/src/libipc/sync/mutex.cpp b/src/libipc/sync/mutex.cpp index c9c59f7..3e1c3fe 100644 --- a/src/libipc/sync/mutex.cpp +++ b/src/libipc/sync/mutex.cpp @@ -5,11 +5,11 @@ #include "libipc/utility/log.h" #include "libipc/memory/resource.h" #include "libipc/platform/detail.h" -#if defined(IPC_OS_WINDOWS_) +#if defined(LIBIPC_OS_WIN) #include "libipc/platform/win/mutex.h" -#elif defined(IPC_OS_LINUX_) +#elif defined(LIBIPC_OS_LINUX) #include "libipc/platform/linux/mutex.h" -#elif defined(IPC_OS_QNX_) +#elif defined(LIBIPC_OS_QNX) #include "libipc/platform/posix/mutex.h" #else/*IPC_OS*/ # error "Unsupported platform." diff --git a/src/libipc/sync/semaphore.cpp b/src/libipc/sync/semaphore.cpp index ccb13c4..42f78ae 100644 --- a/src/libipc/sync/semaphore.cpp +++ b/src/libipc/sync/semaphore.cpp @@ -5,9 +5,9 @@ #include "libipc/utility/log.h" #include "libipc/memory/resource.h" #include "libipc/platform/detail.h" -#if defined(IPC_OS_WINDOWS_) +#if defined(LIBIPC_OS_WIN) #include "libipc/platform/win/semaphore.h" -#elif defined(IPC_OS_LINUX_) || defined(IPC_OS_QNX_) +#elif defined(LIBIPC_OS_LINUX) || defined(LIBIPC_OS_QNX) #include "libipc/platform/posix/semaphore_impl.h" #else/*IPC_OS*/ # error "Unsupported platform." diff --git a/src/libipc/sync/waiter.cpp b/src/libipc/sync/waiter.cpp index 3a04abf..cb9f39b 100644 --- a/src/libipc/sync/waiter.cpp +++ b/src/libipc/sync/waiter.cpp @@ -1,11 +1,11 @@ #include "libipc/waiter.h" #include "libipc/platform/detail.h" -#if defined(IPC_OS_WINDOWS_) +#if defined(LIBIPC_OS_WIN) #include "libipc/platform/win/mutex.h" -#elif defined(IPC_OS_LINUX_) +#elif defined(LIBIPC_OS_LINUX) #include "libipc/platform/linux/mutex.h" -#elif defined(IPC_OS_QNX_) +#elif defined(LIBIPC_OS_QNX) #include "libipc/platform/posix/mutex.h" #else/*IPC_OS*/ # error "Unsupported platform." diff --git a/src/libipc/utility/utility.h b/src/libipc/utility/utility.h index 79424d9..f4387e4 100755 --- a/src/libipc/utility/utility.h +++ b/src/libipc/utility/utility.h @@ -27,7 +27,7 @@ constexpr decltype(auto) static_switch(std::size_t i, F&& f, D&& def) { template IPC_CONSTEXPR_ void static_for(std::index_sequence, F&& f) { - IPC_UNUSED_ auto expand = { (std::forward(f)(std::integral_constant{}), 0)... }; + LIBIPC_UNUSED auto expand = { (std::forward(f)(std::integral_constant{}), 0)... }; } template diff --git a/src/libipc/waiter.h b/src/libipc/waiter.h index 0892bc1..b2779f6 100644 --- a/src/libipc/waiter.h +++ b/src/libipc/waiter.h @@ -63,7 +63,7 @@ public: template bool wait_if(F &&pred, std::uint64_t tm = ipc::invalid_value) noexcept { - IPC_UNUSED_ std::lock_guard guard {lock_}; + LIBIPC_UNUSED std::lock_guard guard {lock_}; while ([this, &pred] { return !quit_.load(std::memory_order_relaxed) && std::forward(pred)(); @@ -75,14 +75,14 @@ public: bool notify() noexcept { { - IPC_UNUSED_ std::lock_guard barrier{lock_}; // barrier + LIBIPC_UNUSED std::lock_guard barrier{lock_}; // barrier } return cond_.notify(lock_); } bool broadcast() noexcept { { - IPC_UNUSED_ std::lock_guard barrier{lock_}; // barrier + LIBIPC_UNUSED std::lock_guard barrier{lock_}; // barrier } return cond_.broadcast(lock_); } diff --git a/test/archive/test.h b/test/archive/test.h index db05eed..7f3ef93 100755 --- a/test/archive/test.h +++ b/test/archive/test.h @@ -15,7 +15,7 @@ #include "thread_pool.h" #include "libipc/platform/detail.h" -#ifdef IPC_OS_LINUX_ +#ifdef LIBIPC_OS_LINUX #include // ::open #endif @@ -88,7 +88,7 @@ inline static thread_pool & reader() { return pool; } -#ifdef IPC_OS_LINUX_ +#ifdef LIBIPC_OS_LINUX inline bool check_exist(char const *name) noexcept { int fd = ::open((std::string{"/dev/shm/"} + name).c_str(), O_RDONLY); if (fd == -1) { @@ -100,7 +100,7 @@ inline bool check_exist(char const *name) noexcept { #endif inline bool expect_exist(char const *name, bool expected) noexcept { -#ifdef IPC_OS_LINUX_ +#ifdef LIBIPC_OS_LINUX return ipc_ut::check_exist(name) == expected; #else return true; diff --git a/test/archive/test_sync.cpp b/test/archive/test_sync.cpp index d05dd77..090629c 100644 --- a/test/archive/test_sync.cpp +++ b/test/archive/test_sync.cpp @@ -10,7 +10,7 @@ #include "test.h" #include "libipc/platform/detail.h" -#if defined(IPC_OS_LINUX_) +#if defined(LIBIPC_OS_LINUX) #include #include @@ -36,10 +36,8 @@ TEST(PThread, Robust) { pthread_mutex_unlock(&mutex); pthread_mutex_destroy(&mutex); } -#elif defined(IPC_OS_WINDOWS_) -#if defined(__MINGW32__) -#include -#else +#elif defined(LIBIPC_OS_WIN) +#include #include #endif #include