Skip to content

Commit 2ff5c94

Browse files
committed
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()
1 parent 2983549 commit 2ff5c94

File tree

10 files changed

+27
-0
lines changed

10 files changed

+27
-0
lines changed

src/libipc/platform/posix/mutex.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class mutex {
149149
}
150150

151151
void close() noexcept {
152+
LIBIPC_LOG();
152153
if ((ref_ != nullptr) && (shm_ != nullptr) && (mutex_ != nullptr)) {
153154
if (shm_->name() != nullptr) {
154155
release_mutex(shm_->name(), [this] {
@@ -179,6 +180,7 @@ class mutex {
179180
}
180181

181182
void clear() noexcept {
183+
LIBIPC_LOG();
182184
if ((shm_ != nullptr) && (mutex_ != nullptr)) {
183185
if (shm_->name() != nullptr) {
184186
release_mutex(shm_->name(), [this] {
@@ -206,6 +208,7 @@ class mutex {
206208
}
207209

208210
bool lock(std::uint64_t tm) noexcept {
211+
LIBIPC_LOG();
209212
if (!valid()) return false;
210213
for (;;) {
211214
auto ts = posix_::detail::make_timespec(tm);
@@ -265,6 +268,7 @@ class mutex {
265268
}
266269

267270
bool unlock() noexcept {
271+
LIBIPC_LOG();
268272
if (!valid()) return false;
269273
int eno;
270274
if ((eno = ::pthread_mutex_unlock(mutex_)) != 0) {

src/libipc/platform/posix/semaphore_impl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class semaphore {
3434
}
3535

3636
bool open(char const *name, std::uint32_t count) noexcept {
37+
LIBIPC_LOG();
3738
close();
3839
if (!shm_.acquire(name, 1)) {
3940
log.error("[open_semaphore] fail shm.acquire: ", name, "");
@@ -55,6 +56,7 @@ class semaphore {
5556
}
5657

5758
void close() noexcept {
59+
LIBIPC_LOG();
5860
if (!valid()) return;
5961
if (::sem_close(h_) != 0) {
6062
log.error("fail sem_close[%d]: ", errno, "");
@@ -71,6 +73,7 @@ class semaphore {
7173
}
7274

7375
void clear() noexcept {
76+
LIBIPC_LOG();
7477
if (valid()) {
7578
if (::sem_close(h_) != 0) {
7679
log.error("fail sem_close[%d]: ", errno, "");
@@ -97,6 +100,7 @@ class semaphore {
97100
}
98101

99102
bool wait(std::uint64_t tm) noexcept {
103+
LIBIPC_LOG();
100104
if (!valid()) return false;
101105
if (tm == invalid_value) {
102106
if (::sem_wait(h_) != 0) {
@@ -116,6 +120,7 @@ class semaphore {
116120
}
117121

118122
bool post(std::uint32_t count) noexcept {
123+
LIBIPC_LOG();
119124
if (!valid()) return false;
120125
for (std::uint32_t i = 0; i < count; ++i) {
121126
if (::sem_post(h_) != 0) {

src/libipc/platform/posix/shm_posix.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ std::int32_t get_ref(id_t id) {
105105
}
106106

107107
void sub_ref(id_t id) {
108+
LIBIPC_LOG();
108109
if (id == nullptr) {
109110
log.error("fail sub_ref: invalid id (null)");
110111
return;
@@ -165,6 +166,7 @@ void * get_mem(id_t id, std::size_t * size) {
165166
}
166167

167168
std::int32_t release(id_t id) noexcept {
169+
LIBIPC_LOG();
168170
if (id == nullptr) {
169171
log.error("fail release: invalid id (null)");
170172
return -1;
@@ -189,6 +191,7 @@ std::int32_t release(id_t id) noexcept {
189191
}
190192

191193
void remove(id_t id) noexcept {
194+
LIBIPC_LOG();
192195
if (id == nullptr) {
193196
log.error("fail remove: invalid id (null)");
194197
return;
@@ -205,6 +208,7 @@ void remove(id_t id) noexcept {
205208
}
206209

207210
void remove(char const * name) noexcept {
211+
LIBIPC_LOG();
208212
if (!is_valid_string(name)) {
209213
log.error("fail remove: name is empty");
210214
return;

src/libipc/platform/win/get_sa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace ipc {
66
namespace detail {
77

88
inline LPSECURITY_ATTRIBUTES get_sa() {
9+
LIBIPC_LOG();
910
static struct initiator {
1011

1112
SECURITY_DESCRIPTOR sd_;

src/libipc/platform/win/mutex.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class mutex {
3636
}
3737

3838
bool open(char const *name) noexcept {
39+
LIBIPC_LOG();
3940
close();
4041
h_ = ::CreateMutex(detail::get_sa(), FALSE, detail::to_tchar(name).c_str());
4142
if (h_ == NULL) {
@@ -59,6 +60,7 @@ class mutex {
5960
}
6061

6162
bool lock(std::uint64_t tm) noexcept {
63+
LIBIPC_LOG();
6264
DWORD ret, ms = (tm == invalid_value) ? INFINITE : static_cast<DWORD>(tm);
6365
for(;;) {
6466
switch ((ret = ::WaitForSingleObject(h_, ms))) {
@@ -96,6 +98,7 @@ class mutex {
9698
}
9799

98100
bool unlock() noexcept {
101+
LIBIPC_LOG();
99102
if (!::ReleaseMutex(h_)) {
100103
log.error("fail ReleaseMutex[", ::GetLastError(), "]");
101104
return false;

src/libipc/platform/win/semaphore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class semaphore {
3333
}
3434

3535
bool open(char const *name, std::uint32_t count) noexcept {
36+
LIBIPC_LOG();
3637
close();
3738
h_ = ::CreateSemaphore(detail::get_sa(),
3839
static_cast<LONG>(count), LONG_MAX,
@@ -58,6 +59,7 @@ class semaphore {
5859
}
5960

6061
bool wait(std::uint64_t tm) noexcept {
62+
LIBIPC_LOG();
6163
DWORD ret, ms = (tm == invalid_value) ? INFINITE : static_cast<DWORD>(tm);
6264
switch ((ret = ::WaitForSingleObject(h_, ms))) {
6365
case WAIT_OBJECT_0:
@@ -72,6 +74,7 @@ class semaphore {
7274
}
7375

7476
bool post(std::uint32_t count) noexcept {
77+
LIBIPC_LOG();
7578
if (!::ReleaseSemaphore(h_, static_cast<LONG>(count), NULL)) {
7679
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");"}]
7780
return false;

src/libipc/platform/win/shm_win.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ std::int32_t get_ref(id_t id) {
9494
}
9595

9696
void sub_ref(id_t id) {
97+
LIBIPC_LOG();
9798
if (id == nullptr) {
9899
log.error("fail sub_ref: invalid id (null)");
99100
return;
@@ -144,6 +145,7 @@ void * get_mem(id_t id, std::size_t * size) {
144145
}
145146

146147
std::int32_t release(id_t id) noexcept {
148+
LIBIPC_LOG();
147149
if (id == nullptr) {
148150
log.error("fail release: invalid id (null)");
149151
return -1;
@@ -166,6 +168,7 @@ std::int32_t release(id_t id) noexcept {
166168
}
167169

168170
void remove(id_t id) noexcept {
171+
LIBIPC_LOG();
169172
if (id == nullptr) {
170173
log.error("fail release: invalid id (null)");
171174
return;
@@ -174,6 +177,7 @@ void remove(id_t id) noexcept {
174177
}
175178

176179
void remove(char const * name) noexcept {
180+
LIBIPC_LOG();
177181
if (!is_valid_string(name)) {
178182
log.error("fail remove: name is empty");
179183
return;

src/libipc/sync/condition.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ bool condition::valid() const noexcept {
5050
}
5151

5252
bool condition::open(char const *name) noexcept {
53+
LIBIPC_LOG();
5354
if (!is_valid_string(name)) {
5455
log.error("fail condition open: name is empty");
5556
return false;

src/libipc/sync/mutex.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ bool mutex::valid() const noexcept {
5050
}
5151

5252
bool mutex::open(char const *name) noexcept {
53+
LIBIPC_LOG();
5354
if (!is_valid_string(name)) {
5455
log.error("fail mutex open: name is empty");
5556
return false;

src/libipc/sync/semaphore.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ bool semaphore::valid() const noexcept {
4949
}
5050

5151
bool semaphore::open(char const *name, std::uint32_t count) noexcept {
52+
LIBIPC_LOG();
5253
if (!is_valid_string(name)) {
5354
log.error("fail semaphore open: name is empty");
5455
return false;

0 commit comments

Comments
 (0)