Line data Source code
1 : #ifndef OPENDDS_DCPS_MESSAGE_BLOCK_PTR_H 2 : #define OPENDDS_DCPS_MESSAGE_BLOCK_PTR_H 3 : 4 : #if !defined (ACE_LACKS_PRAGMA_ONCE) 5 : # pragma once 6 : #endif /* ACE_LACKS_PRAGMA_ONCE */ 7 : 8 : #include "dcps_export.h" 9 : #include "unique_ptr.h" 10 : #include "ace/Message_Block.h" 11 : 12 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 13 : 14 : namespace OpenDDS { 15 : namespace DCPS { 16 : 17 : struct Message_Block_Deleter 18 : { 19 1846 : void operator()(ACE_Message_Block* ptr) const { 20 : // In order to avoid locking order issues for message blocks with different locking strategies, 21 : // it is safer to unlink elements in the chain before releasing them individually 22 13796 : while (ptr) { 23 11950 : ACE_Message_Block* cont = ptr->cont(); 24 11950 : ptr->cont(0); 25 11950 : ACE_Message_Block::release(ptr); 26 11950 : ptr = cont; 27 : } 28 1846 : } 29 : }; 30 : 31 : typedef unique_ptr<ACE_Message_Block, Message_Block_Deleter> Message_Block_Ptr; 32 : 33 : class OpenDDS_Dcps_Export Message_Block_Shared_Ptr { 34 : public: 35 : Message_Block_Shared_Ptr() {} 36 : 37 : explicit Message_Block_Shared_Ptr(ACE_Message_Block* payload) 38 : : msg_(payload) 39 : {} 40 : 41 : Message_Block_Shared_Ptr(const Message_Block_Shared_Ptr& other) 42 : : msg_(ACE_Message_Block::duplicate(other.msg_.get())) 43 : {} 44 : 45 : Message_Block_Shared_Ptr& operator=(const Message_Block_Shared_Ptr& other) 46 : { 47 : Message_Block_Shared_Ptr cpy(other); 48 : swap(*this, cpy); 49 : return *this; 50 : } 51 : 52 : operator bool() const { return msg_.get(); } 53 : 54 : ACE_Message_Block& operator*() const { return *msg_; } 55 : 56 : ACE_Message_Block* operator->() const { return msg_.get(); } 57 : 58 : ACE_Message_Block* get() const { return msg_.get(); } 59 : 60 : static void swap(Message_Block_Shared_Ptr& a, Message_Block_Shared_Ptr& b) 61 : { 62 : using std::swap; 63 : swap(a.msg_, b.msg_); 64 : } 65 : 66 : private: 67 : Message_Block_Ptr msg_; 68 : }; 69 : 70 : } // namespace DCPS 71 : } // namespace OpenDDS 72 : 73 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 74 : 75 : #endif // MESSAGE_BLOCK_PTR_H_18C6F30C