| | |
| | | */ |
| | | #include "msg.h" |
| | | #include "bh_util.h" |
| | | #include "socket.h" |
| | | |
| | | namespace bhome_msg |
| | | { |
| | | |
| | | ShmSocket &ShmMsg::Sender() |
| | | { |
| | | static ShmSocket sender(shm(), false, BHGlobalSenderAddress(), 16); |
| | | return sender; |
| | | } |
| | | |
| | | int ShmMsg::Release() |
| | | { |
| | | if (!valid()) { |
| | | return 0; |
| | | } |
| | | auto n = meta()->count_.Dec(); |
| | | if (n == 0) { |
| | | int64_t free_cmd = (id() << 4) | EncodeCmd(eCmdFree); |
| | | Sender().Send(BHTopicCenterAddress(), free_cmd); |
| | | } else if (n < 0) { |
| | | throw -123; |
| | | } |
| | | return n; |
| | | } |
| | | |
| | | void ShmMsg::Free() |
| | | { |
| | | assert(valid()); |
| | | shm().Dealloc(meta()); |
| | | offset_ = 0; |
| | | assert(!valid()); |
| | | } |
| | | } // namespace bhome_msg |