add attach/detach for shm

This commit is contained in:
zhangyi 2019-03-28 16:23:31 +08:00
parent 2e2cf82d91
commit 755bea8112
2 changed files with 12 additions and 3 deletions

View File

@ -38,7 +38,9 @@ public:
void release();
void* get() const;
id_t dismiss();
void attach(id_t);
id_t detach();
private:
class handle_;

View File

@ -66,7 +66,7 @@ bool handle::acquire(char const * name, std::size_t size, unsigned mode) {
void handle::release() {
if (!valid()) return;
shm::release(dismiss());
shm::release(detach());
}
void* handle::get() const {
@ -74,7 +74,14 @@ void* handle::get() const {
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;
auto old = impl(p_)->id_;
impl(p_)->id_ = nullptr;