From 2ff5c944793443b3a0c9074d55d868aef7416fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E5=A4=B4=E4=BA=91?= <372449116@qq.com> Date: Mon, 15 Dec 2025 09:48:54 +0000 Subject: [PATCH] fix(log): add missing LIBIPC_LOG() to all functions using log interface - Add LIBIPC_LOG() to functions in platform files that use log.error/warning/debug - Fixed files: - POSIX platform: mutex.h, semaphore_impl.h, shm_posix.cpp - Windows platform: get_sa.h, mutex.h, semaphore.h, shm_win.cpp - Sync layer: condition.cpp, mutex.cpp, semaphore.cpp All functions using the new log interface now properly initialize the logger with LIBIPC_LOG() --- src/libipc/platform/posix/mutex.h | 4 ++++ src/libipc/platform/posix/semaphore_impl.h | 5 +++++ src/libipc/platform/posix/shm_posix.cpp | 4 ++++ src/libipc/platform/win/get_sa.h | 1 + src/libipc/platform/win/mutex.h | 3 +++ src/libipc/platform/win/semaphore.h | 3 +++ src/libipc/platform/win/shm_win.cpp | 4 ++++ src/libipc/sync/condition.cpp | 1 + src/libipc/sync/mutex.cpp | 1 + src/libipc/sync/semaphore.cpp | 1 + 10 files changed, 27 insertions(+) diff --git a/src/libipc/platform/posix/mutex.h b/src/libipc/platform/posix/mutex.h index b699ed8..16f2647 100644 --- a/src/libipc/platform/posix/mutex.h +++ b/src/libipc/platform/posix/mutex.h @@ -149,6 +149,7 @@ public: } void close() noexcept { + LIBIPC_LOG(); if ((ref_ != nullptr) && (shm_ != nullptr) && (mutex_ != nullptr)) { if (shm_->name() != nullptr) { release_mutex(shm_->name(), [this] { @@ -179,6 +180,7 @@ public: } void clear() noexcept { + LIBIPC_LOG(); if ((shm_ != nullptr) && (mutex_ != nullptr)) { if (shm_->name() != nullptr) { release_mutex(shm_->name(), [this] { @@ -206,6 +208,7 @@ public: } bool lock(std::uint64_t tm) noexcept { + LIBIPC_LOG(); if (!valid()) return false; for (;;) { auto ts = posix_::detail::make_timespec(tm); @@ -265,6 +268,7 @@ public: } bool unlock() noexcept { + LIBIPC_LOG(); if (!valid()) return false; int eno; if ((eno = ::pthread_mutex_unlock(mutex_)) != 0) { diff --git a/src/libipc/platform/posix/semaphore_impl.h b/src/libipc/platform/posix/semaphore_impl.h index 5358351..9d52cbe 100644 --- a/src/libipc/platform/posix/semaphore_impl.h +++ b/src/libipc/platform/posix/semaphore_impl.h @@ -34,6 +34,7 @@ public: } bool open(char const *name, std::uint32_t count) noexcept { + LIBIPC_LOG(); close(); if (!shm_.acquire(name, 1)) { log.error("[open_semaphore] fail shm.acquire: ", name, ""); @@ -55,6 +56,7 @@ public: } void close() noexcept { + LIBIPC_LOG(); if (!valid()) return; if (::sem_close(h_) != 0) { log.error("fail sem_close[%d]: ", errno, ""); @@ -71,6 +73,7 @@ public: } void clear() noexcept { + LIBIPC_LOG(); if (valid()) { if (::sem_close(h_) != 0) { log.error("fail sem_close[%d]: ", errno, ""); @@ -97,6 +100,7 @@ public: } bool wait(std::uint64_t tm) noexcept { + LIBIPC_LOG(); if (!valid()) return false; if (tm == invalid_value) { if (::sem_wait(h_) != 0) { @@ -116,6 +120,7 @@ public: } bool post(std::uint32_t count) noexcept { + LIBIPC_LOG(); if (!valid()) return false; for (std::uint32_t i = 0; i < count; ++i) { if (::sem_post(h_) != 0) { diff --git a/src/libipc/platform/posix/shm_posix.cpp b/src/libipc/platform/posix/shm_posix.cpp index 440692b..f4e784f 100644 --- a/src/libipc/platform/posix/shm_posix.cpp +++ b/src/libipc/platform/posix/shm_posix.cpp @@ -105,6 +105,7 @@ std::int32_t get_ref(id_t id) { } void sub_ref(id_t id) { + LIBIPC_LOG(); if (id == nullptr) { log.error("fail sub_ref: invalid id (null)"); return; @@ -165,6 +166,7 @@ void * get_mem(id_t id, std::size_t * size) { } std::int32_t release(id_t id) noexcept { + LIBIPC_LOG(); if (id == nullptr) { log.error("fail release: invalid id (null)"); return -1; @@ -189,6 +191,7 @@ std::int32_t release(id_t id) noexcept { } void remove(id_t id) noexcept { + LIBIPC_LOG(); if (id == nullptr) { log.error("fail remove: invalid id (null)"); return; @@ -205,6 +208,7 @@ void remove(id_t id) noexcept { } void remove(char const * name) noexcept { + LIBIPC_LOG(); if (!is_valid_string(name)) { log.error("fail remove: name is empty"); return; diff --git a/src/libipc/platform/win/get_sa.h b/src/libipc/platform/win/get_sa.h index f0980b1..4dc3a2b 100644 --- a/src/libipc/platform/win/get_sa.h +++ b/src/libipc/platform/win/get_sa.h @@ -6,6 +6,7 @@ namespace ipc { namespace detail { inline LPSECURITY_ATTRIBUTES get_sa() { + LIBIPC_LOG(); static struct initiator { SECURITY_DESCRIPTOR sd_; diff --git a/src/libipc/platform/win/mutex.h b/src/libipc/platform/win/mutex.h index 123b213..3eb536d 100644 --- a/src/libipc/platform/win/mutex.h +++ b/src/libipc/platform/win/mutex.h @@ -36,6 +36,7 @@ public: } bool open(char const *name) noexcept { + LIBIPC_LOG(); close(); h_ = ::CreateMutex(detail::get_sa(), FALSE, detail::to_tchar(name).c_str()); if (h_ == NULL) { @@ -59,6 +60,7 @@ public: } bool lock(std::uint64_t tm) noexcept { + LIBIPC_LOG(); DWORD ret, ms = (tm == invalid_value) ? INFINITE : static_cast(tm); for(;;) { switch ((ret = ::WaitForSingleObject(h_, ms))) { @@ -96,6 +98,7 @@ public: } bool unlock() noexcept { + LIBIPC_LOG(); if (!::ReleaseMutex(h_)) { log.error("fail ReleaseMutex[", ::GetLastError(), "]"); return false; diff --git a/src/libipc/platform/win/semaphore.h b/src/libipc/platform/win/semaphore.h index 753d1e0..1be0b56 100644 --- a/src/libipc/platform/win/semaphore.h +++ b/src/libipc/platform/win/semaphore.h @@ -33,6 +33,7 @@ public: } bool open(char const *name, std::uint32_t count) noexcept { + LIBIPC_LOG(); close(); h_ = ::CreateSemaphore(detail::get_sa(), static_cast(count), LONG_MAX, @@ -58,6 +59,7 @@ public: } bool wait(std::uint64_t tm) noexcept { + LIBIPC_LOG(); DWORD ret, ms = (tm == invalid_value) ? INFINITE : static_cast(tm); switch ((ret = ::WaitForSingleObject(h_, ms))) { case WAIT_OBJECT_0: @@ -72,6 +74,7 @@ public: } bool post(std::uint32_t count) noexcept { + LIBIPC_LOG(); if (!::ReleaseSemaphore(h_, static_cast(count), NULL)) { log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");"}] return false; diff --git a/src/libipc/platform/win/shm_win.cpp b/src/libipc/platform/win/shm_win.cpp index 76c5813..9f4c935 100755 --- a/src/libipc/platform/win/shm_win.cpp +++ b/src/libipc/platform/win/shm_win.cpp @@ -94,6 +94,7 @@ std::int32_t get_ref(id_t id) { } void sub_ref(id_t id) { + LIBIPC_LOG(); if (id == nullptr) { log.error("fail sub_ref: invalid id (null)"); return; @@ -144,6 +145,7 @@ void * get_mem(id_t id, std::size_t * size) { } std::int32_t release(id_t id) noexcept { + LIBIPC_LOG(); if (id == nullptr) { log.error("fail release: invalid id (null)"); return -1; @@ -166,6 +168,7 @@ std::int32_t release(id_t id) noexcept { } void remove(id_t id) noexcept { + LIBIPC_LOG(); if (id == nullptr) { log.error("fail release: invalid id (null)"); return; @@ -174,6 +177,7 @@ void remove(id_t id) noexcept { } void remove(char const * name) noexcept { + LIBIPC_LOG(); if (!is_valid_string(name)) { log.error("fail remove: name is empty"); return; diff --git a/src/libipc/sync/condition.cpp b/src/libipc/sync/condition.cpp index ca7c705..0e34a6f 100644 --- a/src/libipc/sync/condition.cpp +++ b/src/libipc/sync/condition.cpp @@ -50,6 +50,7 @@ bool condition::valid() const noexcept { } bool condition::open(char const *name) noexcept { + LIBIPC_LOG(); if (!is_valid_string(name)) { log.error("fail condition open: name is empty"); return false; diff --git a/src/libipc/sync/mutex.cpp b/src/libipc/sync/mutex.cpp index 4080d4f..fb3b7c9 100644 --- a/src/libipc/sync/mutex.cpp +++ b/src/libipc/sync/mutex.cpp @@ -50,6 +50,7 @@ bool mutex::valid() const noexcept { } bool mutex::open(char const *name) noexcept { + LIBIPC_LOG(); if (!is_valid_string(name)) { log.error("fail mutex open: name is empty"); return false; diff --git a/src/libipc/sync/semaphore.cpp b/src/libipc/sync/semaphore.cpp index 5e7ff7d..8f1dbb7 100644 --- a/src/libipc/sync/semaphore.cpp +++ b/src/libipc/sync/semaphore.cpp @@ -49,6 +49,7 @@ bool semaphore::valid() const noexcept { } bool semaphore::open(char const *name, std::uint32_t count) noexcept { + LIBIPC_LOG(); if (!is_valid_string(name)) { log.error("fail semaphore open: name is empty"); return false;