Skip to content

Commit 8b1dca8

Browse files
author
mutouyun
committed
fix(posix): add missing LIBIPC_LOG() calls and fix lambda captures
Fix issue #174: Several functions in mutex.h and condition.h were using the 'log' variable without first calling LIBIPC_LOG() macro, which defines the 'log' variable. This caused FreeBSD compiler errors like 'unexpected namespace name log: expected expression'. Changes in mutex.h: - Add LIBIPC_LOG() at the beginning of open() - Add LIBIPC_LOG() at the beginning of try_lock() - Fix lambda capture in close() to include '&log' - Fix lambda capture in clear() to include '&log' Changes in condition.h: - Add LIBIPC_LOG() at the beginning of clear() - Add LIBIPC_LOG() at the beginning of notify() - Add LIBIPC_LOG() at the beginning of broadcast()
1 parent 9ac5c24 commit 8b1dca8

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/libipc/platform/posix/condition.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class condition {
9292
}
9393

9494
void clear() noexcept {
95+
LIBIPC_LOG();
9596
if ((shm_.ref() <= 1) && cond_ != nullptr) {
9697
int eno;
9798
if ((eno = ::pthread_cond_destroy(cond_)) != 0) {
@@ -134,6 +135,7 @@ class condition {
134135
}
135136

136137
bool notify(ipc::sync::mutex &) noexcept {
138+
LIBIPC_LOG();
137139
if (!valid()) return false;
138140
int eno;
139141
if ((eno = ::pthread_cond_signal(cond_)) != 0) {
@@ -144,6 +146,7 @@ class condition {
144146
}
145147

146148
bool broadcast(ipc::sync::mutex &) noexcept {
149+
LIBIPC_LOG();
147150
if (!valid()) return false;
148151
int eno;
149152
if ((eno = ::pthread_cond_broadcast(cond_)) != 0) {

src/libipc/platform/posix/mutex.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class mutex {
113113
}
114114

115115
bool open(char const *name) noexcept {
116+
LIBIPC_LOG();
116117
close();
117118
if ((mutex_ = acquire_mutex(name)) == nullptr) {
118119
return false;
@@ -152,7 +153,7 @@ class mutex {
152153
LIBIPC_LOG();
153154
if ((ref_ != nullptr) && (shm_ != nullptr) && (mutex_ != nullptr)) {
154155
if (shm_->name() != nullptr) {
155-
release_mutex(shm_->name(), [this] {
156+
release_mutex(shm_->name(), [this, &log] {
156157
auto self_ref = ref_->fetch_sub(1, std::memory_order_relaxed);
157158
if ((shm_->ref() <= 1) && (self_ref <= 1)) {
158159
// Before destroying the mutex, try to unlock it.
@@ -183,7 +184,7 @@ class mutex {
183184
LIBIPC_LOG();
184185
if ((shm_ != nullptr) && (mutex_ != nullptr)) {
185186
if (shm_->name() != nullptr) {
186-
release_mutex(shm_->name(), [this] {
187+
release_mutex(shm_->name(), [this, &log] {
187188
// Unlock before destroying, same reasoning as in close()
188189
::pthread_mutex_unlock(mutex_);
189190

@@ -240,6 +241,7 @@ class mutex {
240241
}
241242

242243
bool try_lock() noexcept(false) {
244+
LIBIPC_LOG();
243245
if (!valid()) return false;
244246
auto ts = posix_::detail::make_timespec(0);
245247
int eno = ::pthread_mutex_timedlock(mutex_, &ts);

0 commit comments

Comments
 (0)