Merge pull request #176 from mutouyun/issue-174

fix: FreeBSD compilation errors (issue #174)
This commit is contained in:
木头云 2026-02-02 12:18:44 +08:00 committed by GitHub
commit b6cbbc940e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 4 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);

View File

@ -7,8 +7,7 @@
#include "libipc/platform/detail.h"
#if defined(LIBIPC_OS_WIN)
#include "libipc/platform/win/semaphore.h"
#elif defined(LIBIPC_OS_QNX) || defined(LIBIPC_OS_FREEBSD)
#elif defined(LIBIPC_OS_LINUX) || defined(LIBIPC_OS_QNX)
#elif defined(LIBIPC_OS_LINUX) || defined(LIBIPC_OS_QNX) || defined(LIBIPC_OS_FREEBSD)
#include "libipc/platform/posix/semaphore_impl.h"
#else/*IPC_OS*/
# error "Unsupported platform."