github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/common/ipc/shm_service_construct_helper.cpp (about) 1 // Copyright (C) 2018 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or 6 // modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // the go-nebulas library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with the go-nebulas library. If not, see 18 // <http://www.gnu.org/licenses/>. 19 // 20 #include "common/ipc/shm_service_construct_helper.h" 21 22 namespace neb { 23 namespace ipc { 24 namespace internal { 25 shm_service_construct_helper::shm_service_construct_helper( 26 boost::interprocess::managed_shared_memory *shmem, 27 shm_service_op_queue *op_queue) 28 : m_op_queue(op_queue), m_shmem(shmem), m_next_alloc_op_counter(0) { 29 m_local_thread_id = std::this_thread::get_id(); 30 } 31 32 void shm_service_construct_helper::handle_construct_op( 33 const std::shared_ptr<shm_service_op_base> &op) { 34 assert(op->op_id() == shm_service_op_base::op_allocate_obj); 35 shm_service_op_allocate *alloc_op = 36 static_cast<shm_service_op_allocate *>(op.get()); 37 alloc_op->m_ret = alloc_op->m_func(); 38 std::unique_lock<std::mutex> _l(m_mutex); 39 m_finished_alloc_ops.push_back(alloc_op->m_counter); 40 m_cond_var.notify_all(); 41 } 42 43 void shm_service_construct_helper::handle_destroy_op( 44 const std::shared_ptr<shm_service_op_base> &op) { 45 assert(op->op_id() == shm_service_op_base::op_destroy); 46 47 shm_service_op_destroy *dry_op = 48 static_cast<shm_service_op_destroy *>(op.get()); 49 dry_op->m_func(); 50 } 51 } // namespace internal 52 } // namespace ipc 53 } // namespace neb