mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 08:46:45 +08:00
fix(platform): rename linux/posix namespaces to avoid predefined macro conflict
Problem: - 'linux' is a predefined macro on Linux platforms - Using 'namespace linux' causes compilation errors - Preprocessor replaces 'linux' with '1' before compilation Solution: - Rename 'namespace linux' to 'namespace linux_' - Rename 'namespace posix' to 'namespace posix_' - Update all 7 call sites accordingly: - linux/condition.h: linux_::detail::make_timespec() - linux/mutex.h: linux_::detail::make_timespec() (2 places) - posix/condition.h: posix_::detail::make_timespec() - posix/mutex.h: posix_::detail::make_timespec() (2 places) - posix/semaphore_impl.h: posix_::detail::make_timespec() This prevents preprocessor macro expansion issues while maintaining the ODR violation fix from the previous commit.
This commit is contained in:
parent
e66bd880e9
commit
b9dd75ccd9
@ -27,7 +27,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
auto ts = linux::detail::make_timespec(tm);
|
||||
auto ts = linux_::detail::make_timespec(tm);
|
||||
int eno = A0_SYSERR(a0_cnd_timedwait(native(), static_cast<a0_mtx_t *>(mtx.native()), {ts}));
|
||||
if (eno != 0) {
|
||||
if (eno != ETIMEDOUT) {
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#include "a0/err_macro.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace linux {
|
||||
namespace linux_ {
|
||||
namespace detail {
|
||||
|
||||
inline bool calc_wait_time(timespec &ts, std::uint64_t tm /*ms*/) noexcept {
|
||||
@ -44,5 +44,5 @@ inline timespec make_timespec(std::uint64_t tm /*ms*/) noexcept(false) {
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace linux
|
||||
} // namespace linux_
|
||||
} // namespace ipc
|
||||
|
||||
@ -25,7 +25,7 @@ public:
|
||||
bool lock(std::uint64_t tm) noexcept {
|
||||
if (!valid()) return false;
|
||||
for (;;) {
|
||||
auto ts = linux::detail::make_timespec(tm);
|
||||
auto ts = linux_::detail::make_timespec(tm);
|
||||
int eno = A0_SYSERR(
|
||||
(tm == invalid_value) ? a0_mtx_lock(native())
|
||||
: a0_mtx_timedlock(native(), {ts}));
|
||||
@ -56,7 +56,7 @@ public:
|
||||
|
||||
bool try_lock() noexcept(false) {
|
||||
if (!valid()) return false;
|
||||
int eno = A0_SYSERR(a0_mtx_timedlock(native(), {linux::detail::make_timespec(0)}));
|
||||
int eno = A0_SYSERR(a0_mtx_timedlock(native(), {linux_::detail::make_timespec(0)}));
|
||||
switch (eno) {
|
||||
case 0:
|
||||
return true;
|
||||
|
||||
@ -115,7 +115,7 @@ public:
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
auto ts = posix::detail::make_timespec(tm);
|
||||
auto ts = posix_::detail::make_timespec(tm);
|
||||
int eno;
|
||||
if ((eno = ::pthread_cond_timedwait(cond_, static_cast<pthread_mutex_t *>(mtx.native()), &ts)) != 0) {
|
||||
if (eno != ETIMEDOUT) {
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#include "libipc/utility/log.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace posix {
|
||||
namespace posix_ {
|
||||
namespace detail {
|
||||
|
||||
inline bool calc_wait_time(timespec &ts, std::uint64_t tm /*ms*/) noexcept {
|
||||
@ -37,5 +37,5 @@ inline timespec make_timespec(std::uint64_t tm /*ms*/) noexcept(false) {
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace posix
|
||||
} // namespace posix_
|
||||
} // namespace ipc
|
||||
|
||||
@ -196,7 +196,7 @@ public:
|
||||
bool lock(std::uint64_t tm) noexcept {
|
||||
if (!valid()) return false;
|
||||
for (;;) {
|
||||
auto ts = posix::detail::make_timespec(tm);
|
||||
auto ts = posix_::detail::make_timespec(tm);
|
||||
int eno = (tm == invalid_value)
|
||||
? ::pthread_mutex_lock(mutex_)
|
||||
: ::pthread_mutex_timedlock(mutex_, &ts);
|
||||
@ -230,7 +230,7 @@ public:
|
||||
|
||||
bool try_lock() noexcept(false) {
|
||||
if (!valid()) return false;
|
||||
auto ts = posix::detail::make_timespec(0);
|
||||
auto ts = posix_::detail::make_timespec(0);
|
||||
int eno = ::pthread_mutex_timedlock(mutex_, &ts);
|
||||
switch (eno) {
|
||||
case 0:
|
||||
|
||||
@ -88,7 +88,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
auto ts = posix::detail::make_timespec(tm);
|
||||
auto ts = posix_::detail::make_timespec(tm);
|
||||
if (::sem_timedwait(h_, &ts) != 0) {
|
||||
if (errno != ETIMEDOUT) {
|
||||
ipc::error("fail sem_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user