OpenDDS  Snapshot(2023/04/28-20:55)
Message_Block_Ptr.h
Go to the documentation of this file.
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 
13 
14 namespace OpenDDS {
15 namespace DCPS {
16 
18 {
19  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  while (ptr) {
23  ACE_Message_Block* cont = ptr->cont();
24  ptr->cont(0);
26  ptr = cont;
27  }
28  }
29 };
30 
32 
34 public:
36 
38  : msg_(payload)
39  {}
40 
42  : msg_(ACE_Message_Block::duplicate(other.msg_.get()))
43  {}
44 
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 
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 
74 
75 #endif // MESSAGE_BLOCK_PTR_H_18C6F30C
void swap(MessageBlock &lhs, MessageBlock &rhs)
ACE_Message_Block & operator*() const
Message_Block_Shared_Ptr(const Message_Block_Shared_Ptr &other)
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
ACE_Message_Block * operator->() const
Message_Block_Shared_Ptr(ACE_Message_Block *payload)
static void swap(Message_Block_Shared_Ptr &a, Message_Block_Shared_Ptr &b)
void operator()(ACE_Message_Block *ptr) const
virtual ACE_Message_Block * release(void)
unique_ptr< ACE_Message_Block, Message_Block_Deleter > Message_Block_Ptr
ACE_Message_Block * cont(void) const
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
Message_Block_Shared_Ptr & operator=(const Message_Block_Shared_Ptr &other)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28