mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
Update platform-specific feature macros to new interfaces in imp
This commit is contained in:
parent
b70dea04c5
commit
73ce564ab2
@ -33,7 +33,7 @@ public:
|
|||||||
void init() {
|
void init() {
|
||||||
/* DCLP */
|
/* DCLP */
|
||||||
if (!constructed_.load(std::memory_order_acquire)) {
|
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)) {
|
if (!constructed_.load(std::memory_order_relaxed)) {
|
||||||
::new (this) conn_head_base;
|
::new (this) conn_head_base;
|
||||||
constructed_.store(true, std::memory_order_release);
|
constructed_.store(true, std::memory_order_release);
|
||||||
|
|||||||
@ -252,12 +252,12 @@ chunk_info_t *chunk_storage_info(conn_info_head *inf, std::size_t chunk_size) {
|
|||||||
std::decay_t<decltype(storages)>::iterator it;
|
std::decay_t<decltype(storages)>::iterator it;
|
||||||
{
|
{
|
||||||
static ipc::rw_lock lock;
|
static ipc::rw_lock lock;
|
||||||
IPC_UNUSED_ std::shared_lock<ipc::rw_lock> guard {lock};
|
LIBIPC_UNUSED std::shared_lock<ipc::rw_lock> guard {lock};
|
||||||
if ((it = storages.find(chunk_size)) == storages.end()) {
|
if ((it = storages.find(chunk_size)) == storages.end()) {
|
||||||
using chunk_handle_ptr_t = std::decay_t<decltype(storages)>::value_type::second_type;
|
using chunk_handle_ptr_t = std::decay_t<decltype(storages)>::value_type::second_type;
|
||||||
using chunk_handle_t = chunk_handle_ptr_t::element_type;
|
using chunk_handle_t = chunk_handle_ptr_t::element_type;
|
||||||
guard.unlock();
|
guard.unlock();
|
||||||
IPC_UNUSED_ std::lock_guard<ipc::rw_lock> guard {lock};
|
LIBIPC_UNUSED std::lock_guard<ipc::rw_lock> guard {lock};
|
||||||
it = storages.emplace(chunk_size, chunk_handle_ptr_t{
|
it = storages.emplace(chunk_size, chunk_handle_ptr_t{
|
||||||
ipc::mem::alloc<chunk_handle_t>(), [](chunk_handle_t *p) {
|
ipc::mem::alloc<chunk_handle_t>(), [](chunk_handle_t *p) {
|
||||||
ipc::mem::destruct(p);
|
ipc::mem::destruct(p);
|
||||||
@ -669,7 +669,7 @@ static ipc::buff_t recv(ipc::handle_t h, std::uint64_t tm) {
|
|||||||
} else {
|
} else {
|
||||||
return ipc::buff_t{buf, msg_size, [](void* p_info, std::size_t size) {
|
return ipc::buff_t{buf, msg_size, [](void* p_info, std::size_t size) {
|
||||||
auto r_info = static_cast<recycle_t *>(p_info);
|
auto r_info = static_cast<recycle_t *>(p_info);
|
||||||
IPC_UNUSED_ auto finally = ipc::guard([r_info] {
|
LIBIPC_UNUSED auto finally = ipc::guard([r_info] {
|
||||||
ipc::mem::free(r_info);
|
ipc::mem::free(r_info);
|
||||||
});
|
});
|
||||||
recycle_storage<flag_t>(r_info->storage_id,
|
recycle_storage<flag_t>(r_info->storage_id,
|
||||||
|
|||||||
@ -51,13 +51,13 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void try_recover(alloc_policy & alc) {
|
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;
|
if (master_allocs_.empty()) return;
|
||||||
take_first_do([&alc](alloc_policy & first) { alc.swap(first); });
|
take_first_do([&alc](alloc_policy & first) { alc.swap(first); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void collect(alloc_policy && alc) {
|
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) {
|
if (master_allocs_.size() >= 32) {
|
||||||
take_first_do([](alloc_policy &) {}); // erase first
|
take_first_do([](alloc_policy &) {}); // erase first
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ class default_recycler : public limited_recycler<AllocP> {
|
|||||||
|
|
||||||
template <typename A>
|
template <typename A>
|
||||||
void try_fill(A & alc) {
|
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;
|
if (this->master_allocs_.empty()) return;
|
||||||
this->take_first_do([&alc](alloc_policy & first) { alc.take(std::move(first)); });
|
this->take_first_do([&alc](alloc_policy & first) { alc.take(std::move(first)); });
|
||||||
}
|
}
|
||||||
@ -197,17 +197,17 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
void swap(sync_wrapper& rhs) {
|
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_);
|
alloc_.swap(rhs.alloc_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* alloc(std::size_t size) {
|
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);
|
return alloc_.alloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(void* p, std::size_t 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);
|
alloc_.free(p, size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,20 +1,7 @@
|
|||||||
#ifndef LIBIPC_SRC_PLATFORM_DETAIL_H_
|
#ifndef LIBIPC_SRC_PLATFORM_DETAIL_H_
|
||||||
#define LIBIPC_SRC_PLATFORM_DETAIL_H_
|
#define LIBIPC_SRC_PLATFORM_DETAIL_H_
|
||||||
|
|
||||||
// detect platform
|
#include "libipc/imp/detect_plat.h"
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|
||||||
@ -27,12 +14,6 @@
|
|||||||
|
|
||||||
// pre-defined
|
// 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_
|
#ifdef IPC_STBIND_
|
||||||
# error "IPC_STBIND_ has been defined."
|
# error "IPC_STBIND_ has been defined."
|
||||||
#endif
|
#endif
|
||||||
@ -42,23 +23,11 @@
|
|||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
|
|
||||||
#define IPC_UNUSED_ [[maybe_unused]]
|
|
||||||
#define IPC_FALLTHROUGH_ [[fallthrough]]
|
|
||||||
#define IPC_STBIND_(A, B, ...) auto [A, B] = __VA_ARGS__
|
#define IPC_STBIND_(A, B, ...) auto [A, B] = __VA_ARGS__
|
||||||
#define IPC_CONSTEXPR_ constexpr
|
#define IPC_CONSTEXPR_ constexpr
|
||||||
|
|
||||||
#else /*__cplusplus < 201703L*/
|
#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, ...) \
|
#define IPC_STBIND_(A, B, ...) \
|
||||||
auto tp___ = __VA_ARGS__ \
|
auto tp___ = __VA_ARGS__ \
|
||||||
auto A = std::get<0>(tp___); \
|
auto A = std::get<0>(tp___); \
|
||||||
|
|||||||
@ -122,7 +122,7 @@ class mutex {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto &info = curr_prog::get();
|
auto &info = curr_prog::get();
|
||||||
IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock};
|
LIBIPC_UNUSED std::lock_guard<std::mutex> guard {info.lock};
|
||||||
auto it = info.mutex_handles.find(name);
|
auto it = info.mutex_handles.find(name);
|
||||||
if (it == info.mutex_handles.end()) {
|
if (it == info.mutex_handles.end()) {
|
||||||
it = info.mutex_handles
|
it = info.mutex_handles
|
||||||
@ -139,7 +139,7 @@ class mutex {
|
|||||||
static void release_mutex(ipc::string const &name, F &&clear) {
|
static void release_mutex(ipc::string const &name, F &&clear) {
|
||||||
if (name.empty()) return;
|
if (name.empty()) return;
|
||||||
auto &info = curr_prog::get();
|
auto &info = curr_prog::get();
|
||||||
IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock};
|
LIBIPC_UNUSED std::lock_guard<std::mutex> guard {info.lock};
|
||||||
auto it = info.mutex_handles.find(name);
|
auto it = info.mutex_handles.find(name);
|
||||||
if (it == info.mutex_handles.end()) {
|
if (it == info.mutex_handles.end()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
#include "libipc/platform/detail.h"
|
#include "libipc/platform/detail.h"
|
||||||
#if defined(IPC_OS_WINDOWS_)
|
#if defined(LIBIPC_OS_WIN)
|
||||||
#elif defined(IPC_OS_LINUX_)
|
#elif defined(LIBIPC_OS_LINUX)
|
||||||
#include "libipc/platform/linux/a0/err.c"
|
#include "libipc/platform/linux/a0/err.c"
|
||||||
#include "libipc/platform/linux/a0/mtx.c"
|
#include "libipc/platform/linux/a0/mtx.c"
|
||||||
#include "libipc/platform/linux/a0/strconv.c"
|
#include "libipc/platform/linux/a0/strconv.c"
|
||||||
#include "libipc/platform/linux/a0/tid.c"
|
#include "libipc/platform/linux/a0/tid.c"
|
||||||
#include "libipc/platform/linux/a0/time.c"
|
#include "libipc/platform/linux/a0/time.c"
|
||||||
#elif defined(IPC_OS_QNX_)
|
#elif defined(LIBIPC_OS_QNX)
|
||||||
#else/*IPC_OS*/
|
#else/*IPC_OS*/
|
||||||
# error "Unsupported platform."
|
# error "Unsupported platform."
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
#include "libipc/platform/detail.h"
|
#include "libipc/platform/detail.h"
|
||||||
#if defined(IPC_OS_WINDOWS_)
|
#if defined(LIBIPC_OS_WIN)
|
||||||
#include "libipc/platform/win/shm_win.cpp"
|
#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"
|
#include "libipc/platform/posix/shm_posix.cpp"
|
||||||
#else/*IPC_OS*/
|
#else/*IPC_OS*/
|
||||||
# error "Unsupported platform."
|
# error "Unsupported platform."
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public:
|
|||||||
ipc::error("fail pthread_condattr_init[%d]\n", eno);
|
ipc::error("fail pthread_condattr_init[%d]\n", eno);
|
||||||
return false;
|
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) {
|
if ((eno = ::pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED)) != 0) {
|
||||||
ipc::error("fail pthread_condattr_setpshared[%d]\n", eno);
|
ipc::error("fail pthread_condattr_setpshared[%d]\n", eno);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -52,7 +52,7 @@ class mutex {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto &info = curr_prog::get();
|
auto &info = curr_prog::get();
|
||||||
IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock};
|
LIBIPC_UNUSED std::lock_guard<std::mutex> guard {info.lock};
|
||||||
auto it = info.mutex_handles.find(name);
|
auto it = info.mutex_handles.find(name);
|
||||||
if (it == info.mutex_handles.end()) {
|
if (it == info.mutex_handles.end()) {
|
||||||
it = info.mutex_handles
|
it = info.mutex_handles
|
||||||
@ -74,7 +74,7 @@ class mutex {
|
|||||||
static void release_mutex(ipc::string const &name, F &&clear) {
|
static void release_mutex(ipc::string const &name, F &&clear) {
|
||||||
if (name.empty()) return;
|
if (name.empty()) return;
|
||||||
auto &info = curr_prog::get();
|
auto &info = curr_prog::get();
|
||||||
IPC_UNUSED_ std::lock_guard<std::mutex> guard {info.lock};
|
LIBIPC_UNUSED std::lock_guard<std::mutex> guard {info.lock};
|
||||||
auto it = info.mutex_handles.find(name);
|
auto it = info.mutex_handles.find(name);
|
||||||
if (it == info.mutex_handles.end()) {
|
if (it == info.mutex_handles.end()) {
|
||||||
return;
|
return;
|
||||||
@ -130,7 +130,7 @@ public:
|
|||||||
ipc::error("fail pthread_mutexattr_init[%d]\n", eno);
|
ipc::error("fail pthread_mutexattr_init[%d]\n", eno);
|
||||||
return false;
|
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) {
|
if ((eno = ::pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED)) != 0) {
|
||||||
ipc::error("fail pthread_mutexattr_setpshared[%d]\n", eno);
|
ipc::error("fail pthread_mutexattr_setpshared[%d]\n", eno);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -85,7 +85,7 @@ public:
|
|||||||
if (!valid()) return false;
|
if (!valid()) return false;
|
||||||
auto &cnt = counter();
|
auto &cnt = counter();
|
||||||
{
|
{
|
||||||
IPC_UNUSED_ std::lock_guard<ipc::sync::mutex> guard {lock_};
|
LIBIPC_UNUSED std::lock_guard<ipc::sync::mutex> guard {lock_};
|
||||||
cnt = (cnt < 0) ? 1 : cnt + 1;
|
cnt = (cnt < 0) ? 1 : cnt + 1;
|
||||||
}
|
}
|
||||||
DWORD ms = (tm == invalid_value) ? INFINITE : static_cast<DWORD>(tm);
|
DWORD ms = (tm == invalid_value) ? INFINITE : static_cast<DWORD>(tm);
|
||||||
@ -97,7 +97,7 @@ public:
|
|||||||
bool rs = ::SignalObjectAndWait(mtx.native(), sem_.native(), ms, FALSE) == WAIT_OBJECT_0;
|
bool rs = ::SignalObjectAndWait(mtx.native(), sem_.native(), ms, FALSE) == WAIT_OBJECT_0;
|
||||||
bool rl = mtx.lock(); // INFINITE
|
bool rl = mtx.lock(); // INFINITE
|
||||||
if (!rs) {
|
if (!rs) {
|
||||||
IPC_UNUSED_ std::lock_guard<ipc::sync::mutex> guard {lock_};
|
LIBIPC_UNUSED std::lock_guard<ipc::sync::mutex> guard {lock_};
|
||||||
cnt -= 1;
|
cnt -= 1;
|
||||||
}
|
}
|
||||||
return rs && rl;
|
return rs && rl;
|
||||||
|
|||||||
@ -88,7 +88,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
case WAIT_ABANDONED:
|
case WAIT_ABANDONED:
|
||||||
unlock();
|
unlock();
|
||||||
IPC_FALLTHROUGH_;
|
LIBIPC_FALLTHROUGH;
|
||||||
default:
|
default:
|
||||||
ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret);
|
ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret);
|
||||||
throw std::system_error{static_cast<int>(ret), std::system_category()};
|
throw std::system_error{static_cast<int>(ret), std::system_category()};
|
||||||
|
|||||||
@ -5,11 +5,11 @@
|
|||||||
#include "libipc/utility/log.h"
|
#include "libipc/utility/log.h"
|
||||||
#include "libipc/memory/resource.h"
|
#include "libipc/memory/resource.h"
|
||||||
#include "libipc/platform/detail.h"
|
#include "libipc/platform/detail.h"
|
||||||
#if defined(IPC_OS_WINDOWS_)
|
#if defined(LIBIPC_OS_WIN)
|
||||||
#include "libipc/platform/win/condition.h"
|
#include "libipc/platform/win/condition.h"
|
||||||
#elif defined(IPC_OS_LINUX_)
|
#elif defined(LIBIPC_OS_LINUX)
|
||||||
#include "libipc/platform/linux/condition.h"
|
#include "libipc/platform/linux/condition.h"
|
||||||
#elif defined(IPC_OS_QNX_)
|
#elif defined(LIBIPC_OS_QNX)
|
||||||
#include "libipc/platform/posix/condition.h"
|
#include "libipc/platform/posix/condition.h"
|
||||||
#else/*IPC_OS*/
|
#else/*IPC_OS*/
|
||||||
# error "Unsupported platform."
|
# error "Unsupported platform."
|
||||||
|
|||||||
@ -5,11 +5,11 @@
|
|||||||
#include "libipc/utility/log.h"
|
#include "libipc/utility/log.h"
|
||||||
#include "libipc/memory/resource.h"
|
#include "libipc/memory/resource.h"
|
||||||
#include "libipc/platform/detail.h"
|
#include "libipc/platform/detail.h"
|
||||||
#if defined(IPC_OS_WINDOWS_)
|
#if defined(LIBIPC_OS_WIN)
|
||||||
#include "libipc/platform/win/mutex.h"
|
#include "libipc/platform/win/mutex.h"
|
||||||
#elif defined(IPC_OS_LINUX_)
|
#elif defined(LIBIPC_OS_LINUX)
|
||||||
#include "libipc/platform/linux/mutex.h"
|
#include "libipc/platform/linux/mutex.h"
|
||||||
#elif defined(IPC_OS_QNX_)
|
#elif defined(LIBIPC_OS_QNX)
|
||||||
#include "libipc/platform/posix/mutex.h"
|
#include "libipc/platform/posix/mutex.h"
|
||||||
#else/*IPC_OS*/
|
#else/*IPC_OS*/
|
||||||
# error "Unsupported platform."
|
# error "Unsupported platform."
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
#include "libipc/utility/log.h"
|
#include "libipc/utility/log.h"
|
||||||
#include "libipc/memory/resource.h"
|
#include "libipc/memory/resource.h"
|
||||||
#include "libipc/platform/detail.h"
|
#include "libipc/platform/detail.h"
|
||||||
#if defined(IPC_OS_WINDOWS_)
|
#if defined(LIBIPC_OS_WIN)
|
||||||
#include "libipc/platform/win/semaphore.h"
|
#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"
|
#include "libipc/platform/posix/semaphore_impl.h"
|
||||||
#else/*IPC_OS*/
|
#else/*IPC_OS*/
|
||||||
# error "Unsupported platform."
|
# error "Unsupported platform."
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
#include "libipc/waiter.h"
|
#include "libipc/waiter.h"
|
||||||
|
|
||||||
#include "libipc/platform/detail.h"
|
#include "libipc/platform/detail.h"
|
||||||
#if defined(IPC_OS_WINDOWS_)
|
#if defined(LIBIPC_OS_WIN)
|
||||||
#include "libipc/platform/win/mutex.h"
|
#include "libipc/platform/win/mutex.h"
|
||||||
#elif defined(IPC_OS_LINUX_)
|
#elif defined(LIBIPC_OS_LINUX)
|
||||||
#include "libipc/platform/linux/mutex.h"
|
#include "libipc/platform/linux/mutex.h"
|
||||||
#elif defined(IPC_OS_QNX_)
|
#elif defined(LIBIPC_OS_QNX)
|
||||||
#include "libipc/platform/posix/mutex.h"
|
#include "libipc/platform/posix/mutex.h"
|
||||||
#else/*IPC_OS*/
|
#else/*IPC_OS*/
|
||||||
# error "Unsupported platform."
|
# error "Unsupported platform."
|
||||||
|
|||||||
@ -27,7 +27,7 @@ constexpr decltype(auto) static_switch(std::size_t i, F&& f, D&& def) {
|
|||||||
|
|
||||||
template <typename F, std::size_t...I>
|
template <typename F, std::size_t...I>
|
||||||
IPC_CONSTEXPR_ void static_for(std::index_sequence<I...>, F&& f) {
|
IPC_CONSTEXPR_ void static_for(std::index_sequence<I...>, F&& f) {
|
||||||
IPC_UNUSED_ auto expand = { (std::forward<F>(f)(std::integral_constant<std::size_t, I>{}), 0)... };
|
LIBIPC_UNUSED auto expand = { (std::forward<F>(f)(std::integral_constant<std::size_t, I>{}), 0)... };
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::size_t N, typename F>
|
template <std::size_t N, typename F>
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public:
|
|||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
bool wait_if(F &&pred, std::uint64_t tm = ipc::invalid_value) noexcept {
|
bool wait_if(F &&pred, std::uint64_t tm = ipc::invalid_value) noexcept {
|
||||||
IPC_UNUSED_ std::lock_guard<ipc::sync::mutex> guard {lock_};
|
LIBIPC_UNUSED std::lock_guard<ipc::sync::mutex> guard {lock_};
|
||||||
while ([this, &pred] {
|
while ([this, &pred] {
|
||||||
return !quit_.load(std::memory_order_relaxed)
|
return !quit_.load(std::memory_order_relaxed)
|
||||||
&& std::forward<F>(pred)();
|
&& std::forward<F>(pred)();
|
||||||
@ -75,14 +75,14 @@ public:
|
|||||||
|
|
||||||
bool notify() noexcept {
|
bool notify() noexcept {
|
||||||
{
|
{
|
||||||
IPC_UNUSED_ std::lock_guard<ipc::sync::mutex> barrier{lock_}; // barrier
|
LIBIPC_UNUSED std::lock_guard<ipc::sync::mutex> barrier{lock_}; // barrier
|
||||||
}
|
}
|
||||||
return cond_.notify(lock_);
|
return cond_.notify(lock_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool broadcast() noexcept {
|
bool broadcast() noexcept {
|
||||||
{
|
{
|
||||||
IPC_UNUSED_ std::lock_guard<ipc::sync::mutex> barrier{lock_}; // barrier
|
LIBIPC_UNUSED std::lock_guard<ipc::sync::mutex> barrier{lock_}; // barrier
|
||||||
}
|
}
|
||||||
return cond_.broadcast(lock_);
|
return cond_.broadcast(lock_);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
#include "thread_pool.h"
|
#include "thread_pool.h"
|
||||||
|
|
||||||
#include "libipc/platform/detail.h"
|
#include "libipc/platform/detail.h"
|
||||||
#ifdef IPC_OS_LINUX_
|
#ifdef LIBIPC_OS_LINUX
|
||||||
#include <fcntl.h> // ::open
|
#include <fcntl.h> // ::open
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ inline static thread_pool & reader() {
|
|||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef IPC_OS_LINUX_
|
#ifdef LIBIPC_OS_LINUX
|
||||||
inline bool check_exist(char const *name) noexcept {
|
inline bool check_exist(char const *name) noexcept {
|
||||||
int fd = ::open((std::string{"/dev/shm/"} + name).c_str(), O_RDONLY);
|
int fd = ::open((std::string{"/dev/shm/"} + name).c_str(), O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
@ -100,7 +100,7 @@ inline bool check_exist(char const *name) noexcept {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline bool expect_exist(char const *name, bool expected) noexcept {
|
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;
|
return ipc_ut::check_exist(name) == expected;
|
||||||
#else
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
#include "libipc/platform/detail.h"
|
#include "libipc/platform/detail.h"
|
||||||
#if defined(IPC_OS_LINUX_)
|
#if defined(LIBIPC_OS_LINUX)
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@ -36,10 +36,8 @@ TEST(PThread, Robust) {
|
|||||||
pthread_mutex_unlock(&mutex);
|
pthread_mutex_unlock(&mutex);
|
||||||
pthread_mutex_destroy(&mutex);
|
pthread_mutex_destroy(&mutex);
|
||||||
}
|
}
|
||||||
#elif defined(IPC_OS_WINDOWS_)
|
#elif defined(LIBIPC_OS_WIN)
|
||||||
#if defined(__MINGW32__)
|
#include <Windows.h>
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user