Skip to content

Commit b9dd75c

Browse files
committed
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.
1 parent e66bd88 commit b9dd75c

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

src/libipc/platform/linux/condition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class condition : public sync::obj_impl<a0_cnd_t> {
2727
return false;
2828
}
2929
} else {
30-
auto ts = linux::detail::make_timespec(tm);
30+
auto ts = linux_::detail::make_timespec(tm);
3131
int eno = A0_SYSERR(a0_cnd_timedwait(native(), static_cast<a0_mtx_t *>(mtx.native()), {ts}));
3232
if (eno != 0) {
3333
if (eno != ETIMEDOUT) {

src/libipc/platform/linux/get_wait_time.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "a0/err_macro.h"
1111

1212
namespace ipc {
13-
namespace linux {
13+
namespace linux_ {
1414
namespace detail {
1515

1616
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) {
4444
}
4545

4646
} // namespace detail
47-
} // namespace linux
47+
} // namespace linux_
4848
} // namespace ipc

src/libipc/platform/linux/mutex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class robust_mutex : public sync::obj_impl<a0_mtx_t> {
2525
bool lock(std::uint64_t tm) noexcept {
2626
if (!valid()) return false;
2727
for (;;) {
28-
auto ts = linux::detail::make_timespec(tm);
28+
auto ts = linux_::detail::make_timespec(tm);
2929
int eno = A0_SYSERR(
3030
(tm == invalid_value) ? a0_mtx_lock(native())
3131
: a0_mtx_timedlock(native(), {ts}));
@@ -56,7 +56,7 @@ class robust_mutex : public sync::obj_impl<a0_mtx_t> {
5656

5757
bool try_lock() noexcept(false) {
5858
if (!valid()) return false;
59-
int eno = A0_SYSERR(a0_mtx_timedlock(native(), {linux::detail::make_timespec(0)}));
59+
int eno = A0_SYSERR(a0_mtx_timedlock(native(), {linux_::detail::make_timespec(0)}));
6060
switch (eno) {
6161
case 0:
6262
return true;

src/libipc/platform/posix/condition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class condition {
115115
}
116116
break;
117117
default: {
118-
auto ts = posix::detail::make_timespec(tm);
118+
auto ts = posix_::detail::make_timespec(tm);
119119
int eno;
120120
if ((eno = ::pthread_cond_timedwait(cond_, static_cast<pthread_mutex_t *>(mtx.native()), &ts)) != 0) {
121121
if (eno != ETIMEDOUT) {

src/libipc/platform/posix/get_wait_time.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "libipc/utility/log.h"
1111

1212
namespace ipc {
13-
namespace posix {
13+
namespace posix_ {
1414
namespace detail {
1515

1616
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) {
3737
}
3838

3939
} // namespace detail
40-
} // namespace posix
40+
} // namespace posix_
4141
} // namespace ipc

src/libipc/platform/posix/mutex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class mutex {
196196
bool lock(std::uint64_t tm) noexcept {
197197
if (!valid()) return false;
198198
for (;;) {
199-
auto ts = posix::detail::make_timespec(tm);
199+
auto ts = posix_::detail::make_timespec(tm);
200200
int eno = (tm == invalid_value)
201201
? ::pthread_mutex_lock(mutex_)
202202
: ::pthread_mutex_timedlock(mutex_, &ts);
@@ -230,7 +230,7 @@ class mutex {
230230

231231
bool try_lock() noexcept(false) {
232232
if (!valid()) return false;
233-
auto ts = posix::detail::make_timespec(0);
233+
auto ts = posix_::detail::make_timespec(0);
234234
int eno = ::pthread_mutex_timedlock(mutex_, &ts);
235235
switch (eno) {
236236
case 0:

src/libipc/platform/posix/semaphore_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class semaphore {
8888
return false;
8989
}
9090
} else {
91-
auto ts = posix::detail::make_timespec(tm);
91+
auto ts = posix_::detail::make_timespec(tm);
9292
if (::sem_timedwait(h_, &ts) != 0) {
9393
if (errno != ETIMEDOUT) {
9494
ipc::error("fail sem_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n",

0 commit comments

Comments
 (0)