34 shm_name_ = std::to_string(channel_id);
39bool PosixSegment::OpenOrCreate() {
45 int fd = shm_open(shm_name_.c_str(), O_RDWR | O_CREAT | O_EXCL, 0644);
47 if (EEXIST == errno) {
48 ADEBUG <<
"shm already exist, open only.";
51 AERROR <<
"create shm failed, error: " << strerror(errno);
57 AERROR <<
"ftruncate failed: " << strerror(errno);
66 AERROR <<
"attach shm failed:" << strerror(errno);
68 shm_unlink(shm_name_.c_str());
77 AERROR <<
"create state failed.";
80 shm_unlink(shm_name_.c_str());
90 AERROR <<
"create blocks failed.";
95 shm_unlink(shm_name_.c_str());
104 AERROR <<
"create blocks failed.";
109 shm_unlink(shm_name_.c_str());
117 new (
static_cast<char*
>(
managed_shm_) +
sizeof(State) + \
122 if (addr ==
nullptr) {
134 new(
static_cast<char*
>(
managed_shm_) +
sizeof(State) + \
140 if (addr ==
nullptr) {
149 AERROR <<
"create arena block buf failed.";
164 shm_unlink(shm_name_.c_str());
173bool PosixSegment::OpenOnly() {
179 int fd = shm_open(shm_name_.c_str(), O_RDWR, 0644);
181 AERROR <<
"get shm failed: " << strerror(errno);
185 struct stat file_attr;
186 if (fstat(fd, &file_attr) < 0) {
187 AERROR <<
"fstat failed: " << strerror(errno);
193 managed_shm_ = mmap(
nullptr, file_attr.st_size, PROT_READ | PROT_WRITE,
196 AERROR <<
"attach shm failed: " << strerror(errno);
205 AERROR <<
"get state failed.";
217 AERROR <<
"get blocks failed.";
229 AERROR <<
"get arena blocks failed.";
239 uint8_t* addr =
reinterpret_cast<uint8_t*
>(
245 if (addr ==
nullptr) {
255 uint8_t* addr =
reinterpret_cast<uint8_t*
>(
261 if (addr ==
nullptr) {
269 AERROR <<
"open only failed.";
284 shm_unlink(shm_name_.c_str());
290 ADEBUG <<
"open only true.";
294bool PosixSegment::Remove() {
295 if (shm_unlink(shm_name_.c_str()) < 0) {
296 AERROR <<
"shm_unlink failed: " << strerror(errno);
302void PosixSegment::Reset() {
PosixSegment(uint64_t channel_id)
std::mutex arena_block_buf_lock_
std::mutex block_buf_lock_
std::unordered_map< uint32_t, uint8_t * > block_buf_addrs_
std::unordered_map< uint32_t, uint8_t * > arena_block_buf_addrs_
static const uint32_t ARENA_BLOCK_NUM
const uint64_t & ceiling_msg_size()
const uint64_t & managed_shm_size()
const uint32_t & block_num()
static const uint64_t ARENA_MESSAGE_SIZE
void Update(const uint64_t &real_msg_size)
const uint64_t & block_buf_size()
uint64_t ceiling_msg_size()
void IncreaseReferenceCounts()