Stores the data payload that is accessed via one or more ACE_Message_Block's. More...
#include <Message_Block.h>


Public Member Functions | |
| ACE_Data_Block (void) | |
| Default "do-nothing" constructor. | |
| ACE_Data_Block (size_t size, ACE_Message_Block::ACE_Message_Type msg_type, const char *msg_data, ACE_Allocator *allocator_strategy, ACE_Lock *locking_strategy, ACE_Message_Block::Message_Flags flags, ACE_Allocator *data_block_allocator) | |
| Initialize. | |
| virtual | ~ACE_Data_Block (void) |
| Delete all the resources held in the message. | |
| ACE_Message_Block::ACE_Message_Type | msg_type (void) const |
| Get type of the message. | |
| void | msg_type (ACE_Message_Block::ACE_Message_Type type) |
| Set type of the message. | |
| char * | base (void) const |
| Get message data pointer. | |
| void | base (char *data, size_t size, ACE_Message_Block::Message_Flags mflags=ACE_Message_Block::DONT_DELETE) |
| Set message data pointer (doesn't reallocate). | |
| char * | end (void) const |
| Return a pointer to 1 past the end of the allocated data in a message. | |
| char * | mark (void) const |
| size_t | size (void) const |
| int | size (size_t length) |
| size_t | capacity (void) const |
| Get the total amount of allocated space. | |
| virtual ACE_Data_Block * | clone (ACE_Message_Block::Message_Flags mask=0) const |
| virtual ACE_Data_Block * | clone_nocopy (ACE_Message_Block::Message_Flags mask=0, size_t max_size=0) const |
| ACE_Data_Block * | duplicate (void) |
| Return a "shallow" copy that increments our reference count by 1. | |
| ACE_Data_Block * | release (ACE_Lock *lock=0) |
| ACE_Message_Block::Message_Flags | set_flags (ACE_Message_Block::Message_Flags more_flags) |
| ACE_Message_Block::Message_Flags | clr_flags (ACE_Message_Block::Message_Flags less_flags) |
| ACE_Message_Block::Message_Flags | flags (void) const |
| Get the current message flags. | |
| ACE_Allocator * | allocator_strategy (void) const |
| Obtain the allocator strategy. | |
| ACE_Lock * | locking_strategy (void) |
| Get the locking strategy. | |
| ACE_Lock * | locking_strategy (ACE_Lock *) |
| Set a new locking strategy and return the hold one. | |
| void | dump (void) const |
| Dump the state of an object. | |
| int | reference_count (void) const |
| Get the current reference count. | |
| ACE_Allocator * | data_block_allocator (void) const |
| Get the allocator used to create this object. | |
Protected Member Functions | |
| virtual ACE_Data_Block * | release_i (void) |
| Internal release implementation. | |
| int | reference_count_i (void) const |
| Internal get the current reference count. | |
| ACE_Data_Block * | release_no_delete (ACE_Lock *lock) |
Protected Attributes | |
| ACE_Message_Block::ACE_Message_Type | type_ |
| Type of message. | |
| size_t | cur_size_ |
| Current size of message block. | |
| size_t | max_size_ |
| Total size of buffer. | |
| ACE_Message_Block::Message_Flags | flags_ |
| Misc flags (e.g., DONT_DELETE and USER_FLAGS). | |
| char * | base_ |
| Pointer To beginning of message payload. | |
| ACE_Allocator * | allocator_strategy_ |
| ACE_Lock * | locking_strategy_ |
| int | reference_count_ |
| ACE_Allocator * | data_block_allocator_ |
| The allocator use to destroy ourselves. | |
Private Member Functions | |
| ACE_Data_Block & | operator= (const ACE_Data_Block &) |
| ACE_Data_Block (const ACE_Data_Block &) | |
Friends | |
| class | ACE_Message_Block |
Stores the data payload that is accessed via one or more ACE_Message_Block's.
This data structure is reference counted to maximize sharing. It also contains the <locking_strategy_> (which protects the reference count from race conditions in concurrent programs) and the <allocation_strategy_> (which determines what memory pool is used to allocate the memory).
Definition at line 677 of file Message_Block.h.
| ACE_Data_Block::ACE_Data_Block | ( | void | ) |
Default "do-nothing" constructor.
Definition at line 315 of file Message_Block.cpp.
00316 : type_ (ACE_Message_Block::MB_DATA), 00317 cur_size_ (0), 00318 max_size_ (0), 00319 flags_ (ACE_Message_Block::DONT_DELETE), 00320 base_ (0), 00321 allocator_strategy_ (0), 00322 locking_strategy_ (0), 00323 reference_count_ (1), 00324 data_block_allocator_ (0) 00325 { 00326 ACE_TRACE ("ACE_Data_Block::ACE_Data_Block"); 00327 ACE_FUNCTION_TIMEPROBE (ACE_DATA_BLOCK_CTOR1_ENTER); 00328 00329 ACE_ALLOCATOR (this->allocator_strategy_, 00330 ACE_Allocator::instance ()); 00331 00332 ACE_ALLOCATOR (this->data_block_allocator_, 00333 ACE_Allocator::instance ()); 00334 }
| ACE_Data_Block::ACE_Data_Block | ( | size_t | size, | |
| ACE_Message_Block::ACE_Message_Type | msg_type, | |||
| const char * | msg_data, | |||
| ACE_Allocator * | allocator_strategy, | |||
| ACE_Lock * | locking_strategy, | |||
| ACE_Message_Block::Message_Flags | flags, | |||
| ACE_Allocator * | data_block_allocator | |||
| ) |
Initialize.
Definition at line 336 of file Message_Block.cpp.
00343 : type_ (msg_type), 00344 cur_size_ (0), // Reset later if memory alloc'd ok 00345 max_size_ (0), 00346 flags_ (flags), 00347 base_ (const_cast <char *> (msg_data)), 00348 allocator_strategy_ (allocator_strategy), 00349 locking_strategy_ (locking_strategy), 00350 reference_count_ (1), 00351 data_block_allocator_ (data_block_allocator) 00352 { 00353 ACE_TRACE ("ACE_Data_Block::ACE_Data_Block"); 00354 ACE_FUNCTION_TIMEPROBE (ACE_DATA_BLOCK_CTOR2_ENTER); 00355 00356 // If the user didn't pass one in, let's use the 00357 // <ACE_Allocator::instance>. 00358 if (this->allocator_strategy_ == 0) 00359 ACE_ALLOCATOR (this->allocator_strategy_, 00360 ACE_Allocator::instance ()); 00361 00362 if (this->data_block_allocator_ == 0) 00363 ACE_ALLOCATOR (this->data_block_allocator_, 00364 ACE_Allocator::instance ()); 00365 00366 if (msg_data == 0) 00367 { 00368 ACE_ALLOCATOR (this->base_, 00369 (char *) this->allocator_strategy_->malloc (size)); 00370 #if defined (ACE_INITIALIZE_MEMORY_BEFORE_USE) 00371 (void) ACE_OS::memset (this->base_, 00372 '\0', 00373 size); 00374 #endif /* ACE_INITIALIZE_MEMORY_BEFORE_USE */ 00375 } 00376 00377 // ACE_ALLOCATOR returns on alloc failure but we cant throw, so setting 00378 // the size to 0 (i.e. "bad bit") ... 00379 if (this->base_ == 0) 00380 { 00381 size = 0; 00382 } 00383 00384 // The memory is legit, whether passed in or allocated, so set 00385 // the size. 00386 this->cur_size_ = this->max_size_ = size; 00387 }
| ACE_Data_Block::~ACE_Data_Block | ( | void | ) | [virtual] |
Delete all the resources held in the message.
Definition at line 758 of file Message_Block.cpp.
00759 { 00760 // Sanity check... 00761 ACE_ASSERT (this->reference_count_ <= 1); 00762 00763 // Just to be safe... 00764 this->reference_count_ = 0; 00765 00766 if (ACE_BIT_DISABLED (this->flags_, 00767 ACE_Message_Block::DONT_DELETE)) 00768 { 00769 this->allocator_strategy_->free ((void *) this->base_); 00770 this->base_ = 0; 00771 } 00772 }
| ACE_Data_Block::ACE_Data_Block | ( | const ACE_Data_Block & | ) | [private] |
| ACE_Allocator * ACE_Data_Block::allocator_strategy | ( | void | ) | const |
Obtain the allocator strategy.
Definition at line 469 of file Message_Block.inl.
00470 { 00471 ACE_TRACE ("ACE_Data_Block::allocator_strategy"); 00472 return this->allocator_strategy_; 00473 }
| void ACE_Data_Block::base | ( | char * | data, | |
| size_t | size, | |||
| ACE_Message_Block::Message_Flags | mflags = ACE_Message_Block::DONT_DELETE | |||
| ) |
Set message data pointer (doesn't reallocate).
Definition at line 1264 of file Message_Block.cpp.
01267 { 01268 if (ACE_BIT_DISABLED (this->flags_, 01269 ACE_Message_Block::DONT_DELETE)) 01270 this->allocator_strategy_->free (this->base_); 01271 01272 this->max_size_ = msg_length; 01273 this->cur_size_ = msg_length; 01274 this->base_ = msg_data; 01275 this->flags_ = msg_flags; 01276 }
| char * ACE_Data_Block::base | ( | void | ) | const |
Get message data pointer.
Definition at line 52 of file Message_Block.inl.
| size_t ACE_Data_Block::capacity | ( | void | ) | const |
Get the total amount of allocated space.
Definition at line 66 of file Message_Block.inl.
| ACE_Data_Block * ACE_Data_Block::clone | ( | ACE_Message_Block::Message_Flags | mask = 0 |
) | const [virtual] |
Return an exact "deep copy" of the message, i.e., create fresh new copies of all the Data_Blocks and continuations. Notice that Data_Blocks can act as "Prototypes", i.e. derived classes can override this method and create instances of themselves.
Definition at line 1107 of file Message_Block.cpp.
01108 { 01109 ACE_TRACE ("ACE_Data_Block::clone"); 01110 01111 ACE_Data_Block *nb = this->clone_nocopy (mask); 01112 01113 // Copy all of the payload memory into the new object. The new block 01114 // was allocated with max_size_ (and, thus, it's cur_size_ is the same 01115 // as max_size_). Maintain the same "has been written" boundary in the 01116 // new block by only copying cur_size_ bytes. 01117 if (nb != 0) 01118 { 01119 ACE_OS::memcpy (nb->base_, 01120 this->base_, 01121 this->cur_size_); 01122 } 01123 01124 return nb; 01125 }
| ACE_Data_Block * ACE_Data_Block::clone_nocopy | ( | ACE_Message_Block::Message_Flags | mask = 0, |
|
| size_t | max_size = 0 | |||
| ) | const [virtual] |
As clone above, but it does not copy the contents of the buffer, i.e., create a new Data_Block of the same dynamic type, with the same allocator, locking_strategy, and with the same amount of storage available (if max_size is zero) but the buffer is unitialized. If max_size is specified other than zero, it will be used when creating the new data block.
Reimplemented in ACE_Locked_Data_Block< ACE_LOCK >.
Definition at line 1128 of file Message_Block.cpp.
01130 { 01131 ACE_FUNCTION_TIMEPROBE(ACE_DATA_BLOCK_CLONE_ENTER); 01132 01133 ACE_TRACE ("ACE_Data_Block::clone_nocopy"); 01134 01135 // You always want to clear this one to prevent memory leaks but you 01136 // might add some others later. 01137 const ACE_Message_Block::Message_Flags always_clear = 01138 ACE_Message_Block::DONT_DELETE; 01139 01140 const size_t newsize = 01141 max_size == 0 ? this->max_size_ : max_size; 01142 01143 ACE_Data_Block *nb = 0; 01144 01145 ACE_NEW_MALLOC_RETURN (nb, 01146 static_cast<ACE_Data_Block*> ( 01147 this->data_block_allocator_->malloc (sizeof (ACE_Data_Block))), 01148 ACE_Data_Block (newsize, // size 01149 this->type_, // type 01150 0, // data 01151 this->allocator_strategy_, // allocator 01152 this->locking_strategy_, // locking strategy 01153 this->flags_, // flags 01154 this->data_block_allocator_), 01155 0); 01156 01157 // Message block initialization may fail while the construction 01158 // succeds. Since as a matter of policy, ACE may throw no 01159 // exceptions, we have to do a separate check like this. 01160 if (nb != 0 && nb->size () < newsize) 01161 { 01162 nb->ACE_Data_Block::~ACE_Data_Block(); // placement destructor ... 01163 this->data_block_allocator_->free (nb); // free ... 01164 errno = ENOMEM; 01165 return 0; 01166 } 01167 01168 01169 // Set new flags minus the mask... 01170 nb->clr_flags (mask | always_clear); 01171 return nb; 01172 }
| ACE_Message_Block::Message_Flags ACE_Data_Block::clr_flags | ( | ACE_Message_Block::Message_Flags | less_flags | ) |
Clear the message flag bits specified in <less_flags> and return the new value.
Definition at line 82 of file Message_Block.inl.
| ACE_Allocator * ACE_Data_Block::data_block_allocator | ( | void | ) | const |
Get the allocator used to create this object.
Definition at line 98 of file Message_Block.inl.
00099 { 00100 ACE_TRACE ("ACE_Data_Block::data_block_allocator"); 00101 return this->data_block_allocator_; 00102 }
| void ACE_Data_Block::dump | ( | void | ) | const |
Dump the state of an object.
Definition at line 146 of file Message_Block.cpp.
00147 { 00148 #if defined (ACE_HAS_DUMP) 00149 ACE_TRACE ("ACE_Data_Block::dump"); 00150 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00151 ACE_DEBUG ((LM_DEBUG, 00152 ACE_TEXT ("-----( Data Block )-----\n") 00153 ACE_TEXT ("type_ = %d\n") 00154 ACE_TEXT ("cur_size_ = %u\n") 00155 ACE_TEXT ("max_size_ = %u\n") 00156 ACE_TEXT ("flags_ = %u\n") 00157 ACE_TEXT ("base_ = %@\n") 00158 ACE_TEXT ("locking_strategy_ = %u\n") 00159 ACE_TEXT ("reference_count_ = %u\n") 00160 ACE_TEXT ("---------------------------\n"), 00161 this->type_, 00162 this->cur_size_, 00163 this->max_size_, 00164 this->flags_, 00165 this->base_, 00166 this->locking_strategy_, 00167 this->reference_count_)); 00168 this->allocator_strategy_->dump (); 00169 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00170 #endif /* ACE_HAS_DUMP */ 00171 }
| ACE_Data_Block * ACE_Data_Block::duplicate | ( | void | ) |
Return a "shallow" copy that increments our reference count by 1.
Definition at line 991 of file Message_Block.cpp.
00992 { 00993 ACE_TRACE ("ACE_Data_Block::duplicate"); 00994 00995 // Create a new <ACE_Message_Block>, but share the <base_> pointer 00996 // data (i.e., don't copy that). 00997 if (this->locking_strategy_) 00998 { 00999 // We need to acquire the lock before incrementing the count. 01000 ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->locking_strategy_, 0); 01001 ++this->reference_count_; 01002 } 01003 else 01004 ++this->reference_count_; 01005 01006 return this; 01007 }
| char * ACE_Data_Block::end | ( | void | ) | const |
Return a pointer to 1 past the end of the allocated data in a message.
Definition at line 333 of file Message_Block.inl.
| ACE_Message_Block::Message_Flags ACE_Data_Block::flags | ( | void | ) | const |
Get the current message flags.
Definition at line 91 of file Message_Block.inl.
Set a new locking strategy and return the hold one.
Definition at line 483 of file Message_Block.inl.
00484 { 00485 ACE_TRACE ("ACE_Data_Block::locking_strategy"); 00486 ACE_Lock *ols = this->locking_strategy_; 00487 00488 this->locking_strategy_ = nls; 00489 return ols; 00490 }
| ACE_Lock * ACE_Data_Block::locking_strategy | ( | void | ) |
Get the locking strategy.
Definition at line 476 of file Message_Block.inl.
00477 { 00478 ACE_TRACE ("ACE_Data_Block::locking_strategy"); 00479 return this->locking_strategy_; 00480 }
| char * ACE_Data_Block::mark | ( | void | ) | const |
Return a pointer to 1 past the end of the allotted data in a message. The allotted data may be less than allocated data if <size()> is passed an argument less than <capacity()>.
Definition at line 319 of file Message_Block.inl.
| void ACE_Data_Block::msg_type | ( | ACE_Message_Block::ACE_Message_Type | type | ) |
Set type of the message.
Definition at line 168 of file Message_Block.inl.
| ACE_Message_Block::ACE_Message_Type ACE_Data_Block::msg_type | ( | void | ) | const |
Get type of the message.
Definition at line 161 of file Message_Block.inl.
| ACE_Data_Block& ACE_Data_Block::operator= | ( | const ACE_Data_Block & | ) | [private] |
| int ACE_Data_Block::reference_count | ( | void | ) | const |
Get the current reference count.
Definition at line 200 of file Message_Block.cpp.
00201 { 00202 if (this->locking_strategy_) 00203 { 00204 // We need to acquire the lock before retrieving the count 00205 ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->locking_strategy_, 0); 00206 00207 return this->reference_count_i (); 00208 } 00209 00210 return this->reference_count_i (); 00211 }
| int ACE_Data_Block::reference_count_i | ( | void | ) | const [protected] |
Internal get the current reference count.
Definition at line 40 of file Message_Block.inl.
00041 { 00042 return reference_count_; 00043 }
| ACE_Data_Block * ACE_Data_Block::release | ( | ACE_Lock * | lock = 0 |
) |
Decrease the shared reference count by 1. If the reference count is > 0 then return this; else if reference count == 0 then delete this and mb and return 0. Behavior is undefined if reference count < 0.
Definition at line 840 of file Message_Block.cpp.
00841 { 00842 ACE_TRACE ("ACE_Data_Block::release"); 00843 00844 ACE_Allocator *allocator = this->data_block_allocator_; 00845 00846 ACE_Data_Block *result = this->release_no_delete (lock); 00847 00848 // We must delete this outside the scope of the locking_strategy_ 00849 // since otherwise we'd be trying to "release" through a deleted 00850 // pointer! 00851 if (result == 0) 00852 ACE_DES_FREE (this, 00853 allocator->free, 00854 ACE_Data_Block); 00855 return result; 00856 }
| ACE_Data_Block * ACE_Data_Block::release_i | ( | void | ) | [protected, virtual] |
Internal release implementation.
Definition at line 775 of file Message_Block.cpp.
00776 { 00777 ACE_TRACE ("ACE_Data_Block::release_i"); 00778 00779 ACE_ASSERT (this->reference_count_ > 0); 00780 00781 ACE_Data_Block *result = 0; 00782 00783 // decrement reference count 00784 --this->reference_count_; 00785 00786 if (this->reference_count_ == 0) 00787 // this will cause deletion of this 00788 result = 0; 00789 else 00790 result = this; 00791 00792 return result; 00793 }
| ACE_Data_Block * ACE_Data_Block::release_no_delete | ( | ACE_Lock * | lock | ) | [protected] |
Definition at line 796 of file Message_Block.cpp.
00797 { 00798 ACE_TRACE ("ACE_Data_Block::release_no_delete"); 00799 00800 ACE_Data_Block *result = 0; 00801 ACE_Lock *lock_to_be_used = 0; 00802 00803 // Check if we were passed in a lock 00804 if (lock != 0) 00805 { 00806 // Make sure that the lock passed in and our lock are the same 00807 if (lock == this->locking_strategy_) 00808 // In this case no locking is required. 00809 lock_to_be_used = 0; 00810 00811 // The lock passed in does not match our lock 00812 else 00813 // Lock to be used is our lock 00814 lock_to_be_used = this->locking_strategy_; 00815 } 00816 // This is the case when no lock was passed in 00817 else 00818 { 00819 // Lock to be used is our lock 00820 lock_to_be_used = this->locking_strategy_; 00821 } 00822 00823 // If there's a locking strategy then we need to acquire the lock 00824 // before decrementing the count. 00825 if (lock_to_be_used != 0) 00826 { 00827 ACE_GUARD_RETURN (ACE_Lock, ace_mon, *lock_to_be_used, 0); 00828 00829 result = this->release_i (); 00830 } 00831 else 00832 { 00833 result = this->release_i (); 00834 } 00835 00836 return result; 00837 }
| ACE_Message_Block::Message_Flags ACE_Data_Block::set_flags | ( | ACE_Message_Block::Message_Flags | more_flags | ) |
Bitwise-or the <more_flags> into the existing message flags and return the new value.
Definition at line 73 of file Message_Block.inl.
| int ACE_Data_Block::size | ( | size_t | length | ) |
Set the total amount of space in the message. Returns 0 if successful, else -1.
Definition at line 214 of file Message_Block.cpp.
00215 { 00216 ACE_TRACE ("ACE_Data_Block::size"); 00217 00218 if (length <= this->max_size_) 00219 this->cur_size_ = length; 00220 else 00221 { 00222 // We need to resize! 00223 char *buf = 0; 00224 ACE_ALLOCATOR_RETURN (buf, 00225 (char *) this->allocator_strategy_->malloc (length), 00226 -1); 00227 00228 ACE_OS::memcpy (buf, 00229 this->base_, 00230 this->cur_size_); 00231 if (ACE_BIT_DISABLED (this->flags_, 00232 ACE_Message_Block::DONT_DELETE)) 00233 this->allocator_strategy_->free ((void *) this->base_); 00234 else 00235 // We now assume ownership. 00236 ACE_CLR_BITS (this->flags_, 00237 ACE_Message_Block::DONT_DELETE); 00238 this->max_size_ = length; 00239 this->cur_size_ = length; 00240 this->base_ = buf; 00241 } 00242 return 0; 00243 }
| size_t ACE_Data_Block::size | ( | void | ) | const |
Get the total amount of allotted space in the message. The amount of allotted space may be less than allocated space.
Definition at line 59 of file Message_Block.inl.
friend class ACE_Message_Block [friend] |
Decrease the reference count, but don't delete the object. Returns 0 if the object should be removed. If lock is equal to the locking strategy then we assume that the lock is beign held by the current thread; this is used to release all the data blocks in a chain while holding a single lock.
Definition at line 810 of file Message_Block.h.
ACE_Allocator* ACE_Data_Block::allocator_strategy_ [protected] |
Pointer to the allocator defined for this ACE_Data_Block. Note that this pointer is shared by all owners of this ACE_Data_Block.
Definition at line 834 of file Message_Block.h.
char* ACE_Data_Block::base_ [protected] |
Pointer To beginning of message payload.
Definition at line 826 of file Message_Block.h.
size_t ACE_Data_Block::cur_size_ [protected] |
Current size of message block.
Definition at line 817 of file Message_Block.h.
ACE_Allocator* ACE_Data_Block::data_block_allocator_ [protected] |
The allocator use to destroy ourselves.
Definition at line 853 of file Message_Block.h.
Misc flags (e.g., DONT_DELETE and USER_FLAGS).
Definition at line 823 of file Message_Block.h.
ACE_Lock* ACE_Data_Block::locking_strategy_ [protected] |
Pointer to the locking strategy defined for this ACE_Data_Block. This is used to protect regions of code that access shared ACE_Data_Block state. Note that this lock is shared by all owners of the ACE_Data_Block's data.
Definition at line 842 of file Message_Block.h.
size_t ACE_Data_Block::max_size_ [protected] |
Total size of buffer.
Definition at line 820 of file Message_Block.h.
int ACE_Data_Block::reference_count_ [protected] |
Reference count for this ACE_Data_Block, which is used to avoid deep copies (i.e., <clone>). Note that this pointer value is shared by all owners of the <Data_Block>'s data, i.e., all the ACE_Message_Blocks.
Definition at line 850 of file Message_Block.h.
Type of message.
Definition at line 814 of file Message_Block.h.
1.6.1