mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 08:46:45 +08:00
- Add IPC_OS_FREEBSD_ platform detection macro - Enable FreeBSD to use POSIX pthread implementation (shared with QNX) - Update all conditional compilation directives to include FreeBSD - Update README to reflect FreeBSD platform support FreeBSD uses the existing POSIX implementation which supports: - Process-shared mutexes (PTHREAD_PROCESS_SHARED) - Robust mutexes (PTHREAD_MUTEX_ROBUST) - Timed lock operations - POSIX shared memory This is a minimal change that reuses the mature POSIX implementation already proven by QNX platform support.
80 lines
1.7 KiB
C++
80 lines
1.7 KiB
C++
|
|
#include "libipc/semaphore.h"
|
|
|
|
#include "libipc/utility/pimpl.h"
|
|
#include "libipc/utility/log.h"
|
|
#include "libipc/memory/resource.h"
|
|
#include "libipc/platform/detail.h"
|
|
#if defined(IPC_OS_WINDOWS_)
|
|
#include "libipc/platform/win/semaphore.h"
|
|
#elif defined(IPC_OS_LINUX_) || defined(IPC_OS_QNX_) || defined(IPC_OS_FREEBSD_)
|
|
#include "libipc/platform/posix/semaphore_impl.h"
|
|
#else/*IPC_OS*/
|
|
# error "Unsupported platform."
|
|
#endif
|
|
|
|
namespace ipc {
|
|
namespace sync {
|
|
|
|
class semaphore::semaphore_ : public ipc::pimpl<semaphore_> {
|
|
public:
|
|
ipc::detail::sync::semaphore sem_;
|
|
};
|
|
|
|
semaphore::semaphore()
|
|
: p_(p_->make()) {
|
|
}
|
|
|
|
semaphore::semaphore(char const * name, std::uint32_t count)
|
|
: semaphore() {
|
|
open(name, count);
|
|
}
|
|
|
|
semaphore::~semaphore() {
|
|
close();
|
|
p_->clear();
|
|
}
|
|
|
|
void const *semaphore::native() const noexcept {
|
|
return impl(p_)->sem_.native();
|
|
}
|
|
|
|
void *semaphore::native() noexcept {
|
|
return impl(p_)->sem_.native();
|
|
}
|
|
|
|
bool semaphore::valid() const noexcept {
|
|
return impl(p_)->sem_.valid();
|
|
}
|
|
|
|
bool semaphore::open(char const *name, std::uint32_t count) noexcept {
|
|
if (!is_valid_string(name)) {
|
|
ipc::error("fail semaphore open: name is empty\n");
|
|
return false;
|
|
}
|
|
return impl(p_)->sem_.open(name, count);
|
|
}
|
|
|
|
void semaphore::close() noexcept {
|
|
impl(p_)->sem_.close();
|
|
}
|
|
|
|
void semaphore::clear() noexcept {
|
|
impl(p_)->sem_.clear();
|
|
}
|
|
|
|
void semaphore::clear_storage(char const * name) noexcept {
|
|
ipc::detail::sync::semaphore::clear_storage(name);
|
|
}
|
|
|
|
bool semaphore::wait(std::uint64_t tm) noexcept {
|
|
return impl(p_)->sem_.wait(tm);
|
|
}
|
|
|
|
bool semaphore::post(std::uint32_t count) noexcept {
|
|
return impl(p_)->sem_.post(count);
|
|
}
|
|
|
|
} // namespace sync
|
|
} // namespace ipc
|