mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2026-01-01 03:12:13 +08:00
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()
This commit is contained in:
parent
298354973a
commit
2ff5c94479
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -6,6 +6,7 @@ namespace ipc {
|
||||
namespace detail {
|
||||
|
||||
inline LPSECURITY_ATTRIBUTES get_sa() {
|
||||
LIBIPC_LOG();
|
||||
static struct initiator {
|
||||
|
||||
SECURITY_DESCRIPTOR sd_;
|
||||
|
||||
@ -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<DWORD>(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;
|
||||
|
||||
@ -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<LONG>(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<DWORD>(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<LONG>(count), NULL)) {
|
||||
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");"}]
|
||||
return false;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user