mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
add attach/detach for shm
This commit is contained in:
parent
2e2cf82d91
commit
755bea8112
@ -38,7 +38,9 @@ public:
|
|||||||
void release();
|
void release();
|
||||||
|
|
||||||
void* get() const;
|
void* get() const;
|
||||||
id_t dismiss();
|
|
||||||
|
void attach(id_t);
|
||||||
|
id_t detach();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class handle_;
|
class handle_;
|
||||||
|
|||||||
11
src/shm.cpp
11
src/shm.cpp
@ -66,7 +66,7 @@ bool handle::acquire(char const * name, std::size_t size, unsigned mode) {
|
|||||||
|
|
||||||
void handle::release() {
|
void handle::release() {
|
||||||
if (!valid()) return;
|
if (!valid()) return;
|
||||||
shm::release(dismiss());
|
shm::release(detach());
|
||||||
}
|
}
|
||||||
|
|
||||||
void* handle::get() const {
|
void* handle::get() const {
|
||||||
@ -74,7 +74,14 @@ void* handle::get() const {
|
|||||||
return impl(p_)->m_;
|
return impl(p_)->m_;
|
||||||
}
|
}
|
||||||
|
|
||||||
id_t handle::dismiss() {
|
void handle::attach(id_t id) {
|
||||||
|
if (id == nullptr) return;
|
||||||
|
release();
|
||||||
|
impl(p_)->id_ = id;
|
||||||
|
impl(p_)->m_ = shm::get_mem(impl(p_)->id_, &(impl(p_)->s_));
|
||||||
|
}
|
||||||
|
|
||||||
|
id_t handle::detach() {
|
||||||
if (!valid()) return nullptr;
|
if (!valid()) return nullptr;
|
||||||
auto old = impl(p_)->id_;
|
auto old = impl(p_)->id_;
|
||||||
impl(p_)->id_ = nullptr;
|
impl(p_)->id_ = nullptr;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user