mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2026-02-06 09:49:48 +08:00
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:
parent
9ac5c24254
commit
8b1dca8831
@ -92,6 +92,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clear() noexcept {
|
void clear() noexcept {
|
||||||
|
LIBIPC_LOG();
|
||||||
if ((shm_.ref() <= 1) && cond_ != nullptr) {
|
if ((shm_.ref() <= 1) && cond_ != nullptr) {
|
||||||
int eno;
|
int eno;
|
||||||
if ((eno = ::pthread_cond_destroy(cond_)) != 0) {
|
if ((eno = ::pthread_cond_destroy(cond_)) != 0) {
|
||||||
@ -134,6 +135,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool notify(ipc::sync::mutex &) noexcept {
|
bool notify(ipc::sync::mutex &) noexcept {
|
||||||
|
LIBIPC_LOG();
|
||||||
if (!valid()) return false;
|
if (!valid()) return false;
|
||||||
int eno;
|
int eno;
|
||||||
if ((eno = ::pthread_cond_signal(cond_)) != 0) {
|
if ((eno = ::pthread_cond_signal(cond_)) != 0) {
|
||||||
@ -144,6 +146,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool broadcast(ipc::sync::mutex &) noexcept {
|
bool broadcast(ipc::sync::mutex &) noexcept {
|
||||||
|
LIBIPC_LOG();
|
||||||
if (!valid()) return false;
|
if (!valid()) return false;
|
||||||
int eno;
|
int eno;
|
||||||
if ((eno = ::pthread_cond_broadcast(cond_)) != 0) {
|
if ((eno = ::pthread_cond_broadcast(cond_)) != 0) {
|
||||||
|
|||||||
@ -113,6 +113,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool open(char const *name) noexcept {
|
bool open(char const *name) noexcept {
|
||||||
|
LIBIPC_LOG();
|
||||||
close();
|
close();
|
||||||
if ((mutex_ = acquire_mutex(name)) == nullptr) {
|
if ((mutex_ = acquire_mutex(name)) == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
@ -152,7 +153,7 @@ public:
|
|||||||
LIBIPC_LOG();
|
LIBIPC_LOG();
|
||||||
if ((ref_ != nullptr) && (shm_ != nullptr) && (mutex_ != nullptr)) {
|
if ((ref_ != nullptr) && (shm_ != nullptr) && (mutex_ != nullptr)) {
|
||||||
if (shm_->name() != 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);
|
auto self_ref = ref_->fetch_sub(1, std::memory_order_relaxed);
|
||||||
if ((shm_->ref() <= 1) && (self_ref <= 1)) {
|
if ((shm_->ref() <= 1) && (self_ref <= 1)) {
|
||||||
// Before destroying the mutex, try to unlock it.
|
// Before destroying the mutex, try to unlock it.
|
||||||
@ -183,7 +184,7 @@ public:
|
|||||||
LIBIPC_LOG();
|
LIBIPC_LOG();
|
||||||
if ((shm_ != nullptr) && (mutex_ != nullptr)) {
|
if ((shm_ != nullptr) && (mutex_ != nullptr)) {
|
||||||
if (shm_->name() != nullptr) {
|
if (shm_->name() != nullptr) {
|
||||||
release_mutex(shm_->name(), [this] {
|
release_mutex(shm_->name(), [this, &log] {
|
||||||
// Unlock before destroying, same reasoning as in close()
|
// Unlock before destroying, same reasoning as in close()
|
||||||
::pthread_mutex_unlock(mutex_);
|
::pthread_mutex_unlock(mutex_);
|
||||||
|
|
||||||
@ -240,6 +241,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool try_lock() noexcept(false) {
|
bool try_lock() noexcept(false) {
|
||||||
|
LIBIPC_LOG();
|
||||||
if (!valid()) return false;
|
if (!valid()) return false;
|
||||||
auto ts = posix_::detail::make_timespec(0);
|
auto ts = posix_::detail::make_timespec(0);
|
||||||
int eno = ::pthread_mutex_timedlock(mutex_, &ts);
|
int eno = ::pthread_mutex_timedlock(mutex_, &ts);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user