33 key_ =
static_cast<key_t
>(channel_id);
38bool XsiSegment::OpenOrCreate() {
52 if (EINVAL == errno) {
53 AINFO <<
"need larger space, recreate.";
57 }
else if (EEXIST == errno) {
58 ADEBUG <<
"shm already exist, open only.";
66 AERROR <<
"create shm failed, error code: " << strerror(errno);
73 AERROR <<
"attach shm failed, error: " << strerror(errno);
74 shmctl(shmid, IPC_RMID, 0);
81 AERROR <<
"create state failed.";
84 shmctl(shmid, IPC_RMID, 0);
94 AERROR <<
"create blocks failed.";
99 shmctl(shmid, IPC_RMID, 0);
108 AERROR <<
"create arena blocks failed.";
113 shmctl(shmid, IPC_RMID, 0);
121 new (
static_cast<char*
>(
managed_shm_) +
sizeof(State) + \
131 for (; ai < ShmConf::ARENA_BLOCK_NUM; ++ai) {
133 new(
static_cast<char*
>(
managed_shm_) +
sizeof(State) + \
144 AERROR <<
"create arena block or block buf failed.";
159 shmctl(shmid, IPC_RMID, 0);
165 ADEBUG <<
"open or create true.";
169bool XsiSegment::OpenOnly() {
175 int shmid = shmget(key_, 0, 0644);
177 AERROR <<
"get shm failed. error: " << strerror(errno);
184 AERROR <<
"attach shm failed, error: " << strerror(errno);
191 AERROR <<
"get state failed.";
203 AERROR <<
"get blocks failed.";
215 AERROR <<
"get blocks failed.";
225 uint8_t* addr =
reinterpret_cast<uint8_t*
>(
231 if (addr ==
nullptr) {
241 uint8_t* addr =
reinterpret_cast<uint8_t*
>(
247 if (addr ==
nullptr) {
255 AERROR <<
"open only failed.";
270 shmctl(shmid, IPC_RMID, 0);
276 ADEBUG <<
"open only true.";
280bool XsiSegment::Remove() {
281 int shmid = shmget(key_, 0, 0644);
282 if (shmid == -1 || shmctl(shmid, IPC_RMID, 0) == -1) {
283 AERROR <<
"remove shm failed, error code: " << strerror(errno);
286 ADEBUG <<
"remove success.";
290void XsiSegment::Reset() {
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()
XsiSegment(uint64_t channel_id)