mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2026-02-10 20:29:50 +08:00
fix(log): use template to pass logger to initiator and fix format error
- src/libipc/platform/win/get_sa.h: * Convert initiator struct to template with Logger parameter * Pass log object from get_sa() to initiator constructor via template * Use 'static initiator<decltype(log)> handle(log)' to instantiate * This allows initiator constructor to properly access log object * Syntax: initiator(Logger const &log) receives the logger - src/libipc/platform/win/semaphore.h: * Fix format error on line 79: remove extra characters '"}]' * Correct closing of log.error() statement * Before: log.error(...)"}] * After: log.error(...); These fixes resolve the static struct initialization issue and code format error in Windows platform.
This commit is contained in:
parent
66a66f15ec
commit
afd1467e03
@ -7,14 +7,14 @@ namespace detail {
|
|||||||
|
|
||||||
inline LPSECURITY_ATTRIBUTES get_sa() {
|
inline LPSECURITY_ATTRIBUTES get_sa() {
|
||||||
LIBIPC_LOG();
|
LIBIPC_LOG();
|
||||||
static struct initiator {
|
|
||||||
|
template <typename Logger>
|
||||||
|
struct initiator {
|
||||||
SECURITY_DESCRIPTOR sd_;
|
SECURITY_DESCRIPTOR sd_;
|
||||||
SECURITY_ATTRIBUTES sa_;
|
SECURITY_ATTRIBUTES sa_;
|
||||||
|
|
||||||
bool succ_ = false;
|
bool succ_ = false;
|
||||||
|
|
||||||
initiator() {
|
initiator(Logger const &log) {
|
||||||
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
|
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
|
||||||
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
|
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
|
||||||
return;
|
return;
|
||||||
@ -28,7 +28,9 @@ inline LPSECURITY_ATTRIBUTES get_sa() {
|
|||||||
sa_.lpSecurityDescriptor = &sd_;
|
sa_.lpSecurityDescriptor = &sd_;
|
||||||
succ_ = true;
|
succ_ = true;
|
||||||
}
|
}
|
||||||
} handle;
|
};
|
||||||
|
|
||||||
|
static initiator<decltype(log)> handle(log);
|
||||||
return handle.succ_ ? &handle.sa_ : nullptr;
|
return handle.succ_ ? &handle.sa_ : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,7 @@ public:
|
|||||||
bool post(std::uint32_t count) noexcept {
|
bool post(std::uint32_t count) noexcept {
|
||||||
LIBIPC_LOG();
|
LIBIPC_LOG();
|
||||||
if (!::ReleaseSemaphore(h_, static_cast<LONG>(count), NULL)) {
|
if (!::ReleaseSemaphore(h_, static_cast<LONG>(count), NULL)) {
|
||||||
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");"}]
|
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user