71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
/**
|
|
* @file mix_cc/shm/utility.h
|
|
* @brief 共享内存常用工具
|
|
* @author Cat (null.null.null@qq.com)
|
|
* @version 0.1
|
|
* @date 2021-05-07
|
|
*
|
|
* Copyright: Baosight Co. Ltd.
|
|
* DO NOT COPY/USE WITHOUT PERMISSION
|
|
*
|
|
*/
|
|
#pragma once
|
|
|
|
#include <algorithm>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include "mix_cc/type/data_size.h"
|
|
#include "mix_cc/utility/read_config.h"
|
|
|
|
#include <boost/container/scoped_allocator.hpp>
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/interprocess/allocators/allocator.hpp>
|
|
#include <boost/interprocess/file_mapping.hpp>
|
|
#include <boost/interprocess/managed_mapped_file.hpp>
|
|
#include <boost/interprocess/managed_shared_memory.hpp>
|
|
#include <boost/interprocess/offset_ptr.hpp>
|
|
namespace mix_cc {
|
|
namespace shm {
|
|
namespace bip = boost::interprocess;
|
|
namespace bc = boost::container;
|
|
template <class T, class Segment>
|
|
using ScopedShmAlloc = bc::scoped_allocator_adaptor<
|
|
bip::allocator<T, typename Segment::segment_manager>>;
|
|
|
|
namespace utility {
|
|
/**
|
|
* @brief Get the mapped path info
|
|
* @return std::string
|
|
*/
|
|
maybe<std::string> get_mapped_path_maybe();
|
|
|
|
/**
|
|
* @brief 得到映射的共享内存文件
|
|
* @param file_path 文件路径
|
|
* @param mapped_file_name 文件名
|
|
* @param size 大小
|
|
* @return bip::managed_mapped_file
|
|
*/
|
|
bip::managed_mapped_file get_managed_mapped_file(
|
|
const std::string& file_path, const std::string& mapped_file_name,
|
|
const data_size_t& size);
|
|
|
|
/**
|
|
* @brief 删除映射的共享内存文件
|
|
* @param file_path 文件路径
|
|
* @param file_name 文件名
|
|
* @return true
|
|
* @return false
|
|
*/
|
|
bool remove_mapped_file(const std::string& file_path,
|
|
const std::string& file_name);
|
|
|
|
bip::managed_shared_memory get_managed_memory_segment(
|
|
const std::string& segment_name, const data_size_t& size);
|
|
}; // namespace utility
|
|
|
|
} // namespace shm
|
|
|
|
} // namespace mix_cc
|