mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2026-02-06 17:59:48 +08:00
Merge pull request #176 from mutouyun/issue-174
fix: FreeBSD compilation errors (issue #174)
This commit is contained in:
commit
b6cbbc940e
@ -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);
|
||||||
|
|||||||
@ -7,8 +7,7 @@
|
|||||||
#include "libipc/platform/detail.h"
|
#include "libipc/platform/detail.h"
|
||||||
#if defined(LIBIPC_OS_WIN)
|
#if defined(LIBIPC_OS_WIN)
|
||||||
#include "libipc/platform/win/semaphore.h"
|
#include "libipc/platform/win/semaphore.h"
|
||||||
#elif defined(LIBIPC_OS_QNX) || defined(LIBIPC_OS_FREEBSD)
|
#elif defined(LIBIPC_OS_LINUX) || defined(LIBIPC_OS_QNX) || defined(LIBIPC_OS_FREEBSD)
|
||||||
#elif defined(LIBIPC_OS_LINUX) || defined(LIBIPC_OS_QNX)
|
|
||||||
#include "libipc/platform/posix/semaphore_impl.h"
|
#include "libipc/platform/posix/semaphore_impl.h"
|
||||||
#else/*IPC_OS*/
|
#else/*IPC_OS*/
|
||||||
# error "Unsupported platform."
|
# error "Unsupported platform."
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user