mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2026-01-01 03:12:13 +08:00
refactor(log): fix remaining complex log format calls
- Fix multi-parameter log calls with complex formatting in POSIX and Windows platforms - Replace remaining ipc::error() and ipc::log() calls with log.error() and log.warning() - Handle special cases: - POSIX condition.h: pthread_cond_timedwait multi-param formatting - POSIX get_wait_time.h: calc_wait_time multi-param formatting - POSIX semaphore_impl.h: sem_timedwait multi-param formatting - Windows mutex.h: WaitForSingleObject with hex formatting, WAIT_ABANDONED as warning - Windows semaphore.h: WaitForSingleObject and ReleaseSemaphore calls - Use std::hex/std::dec for hexadecimal formatting in Windows platform - All log interface migrations now complete
This commit is contained in:
parent
e9a7dbaa74
commit
0c4421d5c2
@ -123,8 +123,7 @@ public:
|
||||
int eno;
|
||||
if ((eno = ::pthread_cond_timedwait(cond_, static_cast<pthread_mutex_t *>(mtx.native()), &ts)) != 0) {
|
||||
if (eno != ETIMEDOUT) {
|
||||
ipc::error("fail pthread_cond_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n",
|
||||
eno, tm, ts.tv_sec, ts.tv_nsec);
|
||||
log.error("fail pthread_cond_timedwait[", eno, "]: tm = ", tm, ", tv_sec = ", ts.tv_sec, ", tv_nsec = ", ts.tv_nsec);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -29,8 +29,7 @@ inline bool calc_wait_time(timespec &ts, std::uint64_t tm /*ms*/) noexcept {
|
||||
inline timespec make_timespec(std::uint64_t tm /*ms*/) noexcept(false) {
|
||||
timespec ts {};
|
||||
if (!calc_wait_time(ts, tm)) {
|
||||
ipc::error("fail calc_wait_time: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n",
|
||||
tm, ts.tv_sec, ts.tv_nsec);
|
||||
log.error("fail calc_wait_time: tm = ", tm, ", tv_sec = ", ts.tv_sec, ", tv_nsec = ", ts.tv_nsec);
|
||||
throw std::system_error{static_cast<int>(errno), std::system_category()};
|
||||
}
|
||||
return ts;
|
||||
|
||||
@ -107,8 +107,7 @@ public:
|
||||
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",
|
||||
errno, tm, ts.tv_sec, ts.tv_nsec);
|
||||
log.error("fail sem_timedwait[", errno, "]: tm = ", tm, ", tv_sec = ", ts.tv_sec, ", tv_nsec = ", ts.tv_nsec);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -67,13 +67,13 @@ public:
|
||||
case WAIT_TIMEOUT:
|
||||
return false;
|
||||
case WAIT_ABANDONED:
|
||||
ipc::log("fail WaitForSingleObject[%lu]: WAIT_ABANDONED, try again.\n", ::GetLastError());
|
||||
log.warning("fail WaitForSingleObject[", ::GetLastError(), "]: WAIT_ABANDONED, try again.");
|
||||
if (!unlock()) {
|
||||
return false;
|
||||
}
|
||||
break; // loop again
|
||||
default:
|
||||
ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret);
|
||||
log.error("fail WaitForSingleObject[", ::GetLastError(), "]: 0x", std::hex, ret, std::dec);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -90,14 +90,14 @@ public:
|
||||
unlock();
|
||||
LIBIPC_FALLTHROUGH;
|
||||
default:
|
||||
ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret);
|
||||
log.error("fail WaitForSingleObject[", ::GetLastError(), "]: 0x", std::hex, ret, std::dec);
|
||||
throw std::system_error{static_cast<int>(ret), std::system_category()};
|
||||
}
|
||||
}
|
||||
|
||||
bool unlock() noexcept {
|
||||
if (!::ReleaseMutex(h_)) {
|
||||
ipc::error("fail ReleaseMutex[%lu]\n", ::GetLastError());
|
||||
log.error("fail ReleaseMutex[", ::GetLastError(), "]");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -66,14 +66,14 @@ public:
|
||||
return false;
|
||||
case WAIT_ABANDONED:
|
||||
default:
|
||||
ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret);
|
||||
log.error("fail WaitForSingleObject[", ::GetLastError(), "]: 0x", std::hex, ret, std::dec);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool post(std::uint32_t count) noexcept {
|
||||
if (!::ReleaseSemaphore(h_, static_cast<LONG>(count), NULL)) {
|
||||
ipc::error("fail ReleaseSemaphore[%lu]\n", ::GetLastError());
|
||||
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");"}]
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user