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()
This commit is contained in:
mutouyun 2026-01-29 03:21:03 +00:00
parent 9ac5c24254
commit 8b1dca8831
2 changed files with 7 additions and 2 deletions

View File

@ -92,6 +92,7 @@ public:
}
void clear() noexcept {
LIBIPC_LOG();
if ((shm_.ref() <= 1) && cond_ != nullptr) {
int eno;
if ((eno = ::pthread_cond_destroy(cond_)) != 0) {
@ -134,6 +135,7 @@ public:
}
bool notify(ipc::sync::mutex &) noexcept {
LIBIPC_LOG();
if (!valid()) return false;
int eno;
if ((eno = ::pthread_cond_signal(cond_)) != 0) {
@ -144,6 +146,7 @@ public:
}
bool broadcast(ipc::sync::mutex &) noexcept {
LIBIPC_LOG();
if (!valid()) return false;
int eno;
if ((eno = ::pthread_cond_broadcast(cond_)) != 0) {

View File

@ -113,6 +113,7 @@ public:
}
bool open(char const *name) noexcept {
LIBIPC_LOG();
close();
if ((mutex_ = acquire_mutex(name)) == nullptr) {
return false;
@ -152,7 +153,7 @@ public:
LIBIPC_LOG();
if ((ref_ != nullptr) && (shm_ != nullptr) && (mutex_ != nullptr)) {
if (shm_->name() != nullptr) {
release_mutex(shm_->name(), [this] {
release_mutex(shm_->name(), [this, &log] {
auto self_ref = ref_->fetch_sub(1, std::memory_order_relaxed);
if ((shm_->ref() <= 1) && (self_ref <= 1)) {
// Before destroying the mutex, try to unlock it.
@ -183,7 +184,7 @@ public:
LIBIPC_LOG();
if ((shm_ != nullptr) && (mutex_ != nullptr)) {
if (shm_->name() != nullptr) {
release_mutex(shm_->name(), [this] {
release_mutex(shm_->name(), [this, &log] {
// Unlock before destroying, same reasoning as in close()
::pthread_mutex_unlock(mutex_);
@ -240,6 +241,7 @@ public:
}
bool try_lock() noexcept(false) {
LIBIPC_LOG();
if (!valid()) return false;
auto ts = posix_::detail::make_timespec(0);
int eno = ::pthread_mutex_timedlock(mutex_, &ts);