*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
This commit is contained in:
@@ -1,27 +1,19 @@
|
||||
#include "ace/Message_Block.h"
|
||||
|
||||
#if !defined (__ACE_INLINE__)
|
||||
#include "ace/Message_Block.inl"
|
||||
#endif /* __ACE_INLINE__ */
|
||||
|
||||
#include "ace/Guard_T.h"
|
||||
#include "ace/Log_Msg.h"
|
||||
#include "ace/Malloc_Base.h"
|
||||
#include "ace/OS_NS_string.h"
|
||||
|
||||
//#define ACE_ENABLE_TIMEPROBES
|
||||
#include "ace/Timeprobe.h"
|
||||
|
||||
ACE_RCSID (ace,
|
||||
Message_Block,
|
||||
"$Id: Message_Block.cpp 80826 2008-03-04 14:51:23Z wotte $")
|
||||
|
||||
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
ACE_ALLOC_HOOK_DEFINE (ACE_Message_Block)
|
||||
|
||||
#if defined (ACE_ENABLE_TIMEPROBES)
|
||||
|
||||
static const char *ACE_MB_Timeprobe_Description[] =
|
||||
{
|
||||
"Message_Block::init_i - enter",
|
||||
@@ -35,7 +27,6 @@ static const char *ACE_MB_Timeprobe_Description[] =
|
||||
"Data_Block::clone - enter",
|
||||
"Data_Block::clone - leave"
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ACE_MESSAGE_BLOCK_INIT_I_ENTER = 3000,
|
||||
@@ -50,13 +41,10 @@ enum
|
||||
ACE_DATA_BLOCK_CLONE_LEAVE
|
||||
};
|
||||
|
||||
|
||||
// Setup Timeprobes
|
||||
ACE_TIMEPROBE_EVENT_DESCRIPTIONS (ACE_MB_Timeprobe_Description,
|
||||
ACE_MESSAGE_BLOCK_INIT_I_ENTER);
|
||||
|
||||
#endif /* ACE_ENABLE_TIMEPROBES */
|
||||
|
||||
void
|
||||
ACE_Message_Block::data_block (ACE_Data_Block *db)
|
||||
{
|
||||
@@ -65,24 +53,19 @@ ACE_Message_Block::data_block (ACE_Data_Block *db)
|
||||
ACE_Message_Block::DONT_DELETE)
|
||||
&& this->data_block_ != 0)
|
||||
this->data_block_->release ();
|
||||
|
||||
this->data_block_ = db;
|
||||
|
||||
// Set the read and write pointers in the <Message_Block> to point
|
||||
// to the buffer in the <ACE_Data_Block>.
|
||||
this->rd_ptr (this->data_block ()->base ());
|
||||
this->wr_ptr (this->data_block ()->base ());
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Message_Block::copy (const char *buf, size_t n)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::copy");
|
||||
|
||||
/*size_t len = static_cast<size_t> (this->end () - this->wr_ptr ());*/
|
||||
// Note that for this to work correct, end () *must* be >= mark ().
|
||||
size_t len = this->space ();
|
||||
|
||||
if (len < n)
|
||||
{
|
||||
errno = ENOSPC;
|
||||
@@ -97,18 +80,14 @@ ACE_Message_Block::copy (const char *buf, size_t n)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Message_Block::copy (const char *buf)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::copy");
|
||||
|
||||
/* size_t len = static_cast<size_t> (this->end () - this->wr_ptr ()); */
|
||||
// Note that for this to work correct, end() *must* be >= wr_ptr().
|
||||
size_t len = this->space ();
|
||||
|
||||
size_t buflen = ACE_OS::strlen (buf) + 1;
|
||||
|
||||
if (len < buflen)
|
||||
{
|
||||
errno = ENOSPC;
|
||||
@@ -123,7 +102,6 @@ ACE_Message_Block::copy (const char *buf)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Message_Block::crunch (void)
|
||||
{
|
||||
@@ -131,7 +109,6 @@ ACE_Message_Block::crunch (void)
|
||||
{
|
||||
if (this->rd_ptr_ > this->wr_ptr_)
|
||||
return -1;
|
||||
|
||||
size_t const len = this->length ();
|
||||
(void) ACE_OS::memmove (this->base (),
|
||||
this->rd_ptr (),
|
||||
@@ -141,7 +118,6 @@ ACE_Message_Block::crunch (void)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Data_Block::dump (void) const
|
||||
{
|
||||
@@ -169,7 +145,6 @@ ACE_Data_Block::dump (void) const
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
|
||||
#endif /* ACE_HAS_DUMP */
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Message_Block::dump (void) const
|
||||
{
|
||||
@@ -195,7 +170,6 @@ ACE_Message_Block::dump (void) const
|
||||
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
|
||||
#endif /* ACE_HAS_DUMP */
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Data_Block::reference_count (void) const
|
||||
{
|
||||
@@ -203,18 +177,14 @@ ACE_Data_Block::reference_count (void) const
|
||||
{
|
||||
// We need to acquire the lock before retrieving the count
|
||||
ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->locking_strategy_, 0);
|
||||
|
||||
return this->reference_count_i ();
|
||||
}
|
||||
|
||||
return this->reference_count_i ();
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Data_Block::size (size_t length)
|
||||
{
|
||||
ACE_TRACE ("ACE_Data_Block::size");
|
||||
|
||||
if (length <= this->max_size_)
|
||||
this->cur_size_ = length;
|
||||
else
|
||||
@@ -224,7 +194,6 @@ ACE_Data_Block::size (size_t length)
|
||||
ACE_ALLOCATOR_RETURN (buf,
|
||||
(char *) this->allocator_strategy_->malloc (length),
|
||||
-1);
|
||||
|
||||
ACE_OS::memcpy (buf,
|
||||
this->base_,
|
||||
this->cur_size_);
|
||||
@@ -241,25 +210,20 @@ ACE_Data_Block::size (size_t length)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Message_Block::size (size_t length)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::size");
|
||||
|
||||
// Resize the underlying <ACE_Data_Block>.
|
||||
if (this->data_block ()->size (length) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Message_Block::total_size_and_length (size_t &mb_size,
|
||||
size_t &mb_length) const
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::total_size_and_length");
|
||||
|
||||
for (const ACE_Message_Block *i = this;
|
||||
i != 0;
|
||||
i = i->cont ())
|
||||
@@ -268,50 +232,39 @@ ACE_Message_Block::total_size_and_length (size_t &mb_size,
|
||||
mb_length += i->length ();
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
ACE_Message_Block::total_size (void) const
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::total_size");
|
||||
|
||||
size_t size = 0;
|
||||
for (const ACE_Message_Block *i = this;
|
||||
i != 0;
|
||||
i = i->cont ())
|
||||
size += i->size ();
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
size_t
|
||||
ACE_Message_Block::total_length (void) const
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::total_length");
|
||||
|
||||
size_t length = 0;
|
||||
for (const ACE_Message_Block *i = this;
|
||||
i != 0;
|
||||
i = i->cont ())
|
||||
length += i->length ();
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
size_t
|
||||
ACE_Message_Block::total_capacity (void) const
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::total_capacity");
|
||||
|
||||
size_t size = 0;
|
||||
|
||||
for (const ACE_Message_Block *i = this;
|
||||
i != 0;
|
||||
i = i->cont ())
|
||||
size += i->capacity ();
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
ACE_Data_Block::ACE_Data_Block (void)
|
||||
: type_ (ACE_Message_Block::MB_DATA),
|
||||
cur_size_ (0),
|
||||
@@ -325,14 +278,11 @@ ACE_Data_Block::ACE_Data_Block (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_Data_Block::ACE_Data_Block");
|
||||
ACE_FUNCTION_TIMEPROBE (ACE_DATA_BLOCK_CTOR1_ENTER);
|
||||
|
||||
ACE_ALLOCATOR (this->allocator_strategy_,
|
||||
ACE_Allocator::instance ());
|
||||
|
||||
ACE_ALLOCATOR (this->data_block_allocator_,
|
||||
ACE_Allocator::instance ());
|
||||
}
|
||||
|
||||
ACE_Data_Block::ACE_Data_Block (size_t size,
|
||||
ACE_Message_Block::ACE_Message_Type msg_type,
|
||||
const char *msg_data,
|
||||
@@ -352,17 +302,14 @@ ACE_Data_Block::ACE_Data_Block (size_t size,
|
||||
{
|
||||
ACE_TRACE ("ACE_Data_Block::ACE_Data_Block");
|
||||
ACE_FUNCTION_TIMEPROBE (ACE_DATA_BLOCK_CTOR2_ENTER);
|
||||
|
||||
// If the user didn't pass one in, let's use the
|
||||
// <ACE_Allocator::instance>.
|
||||
if (this->allocator_strategy_ == 0)
|
||||
ACE_ALLOCATOR (this->allocator_strategy_,
|
||||
ACE_Allocator::instance ());
|
||||
|
||||
if (this->data_block_allocator_ == 0)
|
||||
ACE_ALLOCATOR (this->data_block_allocator_,
|
||||
ACE_Allocator::instance ());
|
||||
|
||||
if (msg_data == 0)
|
||||
{
|
||||
ACE_ALLOCATOR (this->base_,
|
||||
@@ -373,19 +320,16 @@ ACE_Data_Block::ACE_Data_Block (size_t size,
|
||||
size);
|
||||
#endif /* ACE_INITIALIZE_MEMORY_BEFORE_USE */
|
||||
}
|
||||
|
||||
// ACE_ALLOCATOR returns on alloc failure but we cant throw, so setting
|
||||
// the size to 0 (i.e. "bad bit") ...
|
||||
if (this->base_ == 0)
|
||||
{
|
||||
size = 0;
|
||||
}
|
||||
|
||||
// The memory is legit, whether passed in or allocated, so set
|
||||
// the size.
|
||||
this->cur_size_ = this->max_size_ = size;
|
||||
}
|
||||
|
||||
ACE_Message_Block::ACE_Message_Block (const char *data,
|
||||
size_t size,
|
||||
unsigned long priority)
|
||||
@@ -393,7 +337,6 @@ ACE_Message_Block::ACE_Message_Block (const char *data,
|
||||
data_block_ (0)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
|
||||
|
||||
if (this->init_i (size, // size
|
||||
MB_DATA, // type
|
||||
0, // cont
|
||||
@@ -410,13 +353,11 @@ ACE_Message_Block::ACE_Message_Block (const char *data,
|
||||
ACE_ERROR ((LM_ERROR,
|
||||
ACE_TEXT ("ACE_Message_Block")));
|
||||
}
|
||||
|
||||
ACE_Message_Block::ACE_Message_Block (ACE_Allocator *message_block_allocator)
|
||||
: flags_ (0),
|
||||
data_block_ (0)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
|
||||
|
||||
if (this->init_i (0, // size
|
||||
MB_DATA, // type
|
||||
0, // cont
|
||||
@@ -433,7 +374,6 @@ ACE_Message_Block::ACE_Message_Block (ACE_Allocator *message_block_allocator)
|
||||
ACE_ERROR ((LM_ERROR,
|
||||
ACE_TEXT ("ACE_Message_Block")));
|
||||
}
|
||||
|
||||
ACE_Message_Block::ACE_Message_Block (size_t size,
|
||||
ACE_Message_Type msg_type,
|
||||
ACE_Message_Block *msg_cont,
|
||||
@@ -449,7 +389,6 @@ ACE_Message_Block::ACE_Message_Block (size_t size,
|
||||
data_block_ (0)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
|
||||
|
||||
if (this->init_i (size,
|
||||
msg_type,
|
||||
msg_cont,
|
||||
@@ -466,7 +405,6 @@ ACE_Message_Block::ACE_Message_Block (size_t size,
|
||||
ACE_ERROR ((LM_ERROR,
|
||||
ACE_TEXT ("ACE_Message_Block")));
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Message_Block::init (size_t size,
|
||||
ACE_Message_Type msg_type,
|
||||
@@ -481,7 +419,6 @@ ACE_Message_Block::init (size_t size,
|
||||
ACE_Allocator *message_block_allocator)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::init");
|
||||
|
||||
return this->init_i (size,
|
||||
msg_type,
|
||||
msg_cont,
|
||||
@@ -496,14 +433,12 @@ ACE_Message_Block::init (size_t size,
|
||||
data_block_allocator,
|
||||
message_block_allocator);
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Message_Block::init (const char *data,
|
||||
size_t size)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::init");
|
||||
// Should we also initialize all the other fields, as well?
|
||||
|
||||
return this->init_i (size, // size
|
||||
MB_DATA, // type
|
||||
0, // cont
|
||||
@@ -518,7 +453,6 @@ ACE_Message_Block::init (const char *data,
|
||||
0, // data_block allocator
|
||||
0); // message_block allocator
|
||||
}
|
||||
|
||||
ACE_Message_Block::ACE_Message_Block (size_t size,
|
||||
ACE_Message_Type msg_type,
|
||||
ACE_Message_Block *msg_cont,
|
||||
@@ -536,7 +470,6 @@ ACE_Message_Block::ACE_Message_Block (size_t size,
|
||||
data_block_ (0)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
|
||||
|
||||
if (this->init_i (size,
|
||||
msg_type,
|
||||
msg_cont,
|
||||
@@ -553,7 +486,6 @@ ACE_Message_Block::ACE_Message_Block (size_t size,
|
||||
ACE_ERROR ((LM_ERROR,
|
||||
ACE_TEXT ("ACE_Message_Block")));
|
||||
}
|
||||
|
||||
ACE_Message_Block::ACE_Message_Block (ACE_Data_Block *data_block,
|
||||
ACE_Message_Block::Message_Flags flags,
|
||||
ACE_Allocator *message_block_allocator)
|
||||
@@ -561,7 +493,6 @@ ACE_Message_Block::ACE_Message_Block (ACE_Data_Block *data_block,
|
||||
data_block_ (0)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
|
||||
|
||||
if (this->init_i (0, // size
|
||||
MB_NORMAL, // type
|
||||
0, // cont
|
||||
@@ -578,14 +509,12 @@ ACE_Message_Block::ACE_Message_Block (ACE_Data_Block *data_block,
|
||||
ACE_ERROR ((LM_ERROR,
|
||||
ACE_TEXT ("ACE_Message_Block")));
|
||||
}
|
||||
|
||||
ACE_Message_Block::ACE_Message_Block (const ACE_Message_Block &mb,
|
||||
size_t align)
|
||||
:flags_ (0),
|
||||
data_block_ (0)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
|
||||
|
||||
if (ACE_BIT_DISABLED (mb.flags_,
|
||||
ACE_Message_Block::DONT_DELETE))
|
||||
{
|
||||
@@ -611,11 +540,9 @@ ACE_Message_Block::ACE_Message_Block (const ACE_Message_Block &mb,
|
||||
#else
|
||||
char *start = this->base ();
|
||||
#endif /* ACE_LACKS_CDR_ALIGNMENT */
|
||||
|
||||
// Set our rd & wr pointers
|
||||
this->rd_ptr (start);
|
||||
this->wr_ptr (start);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -634,7 +561,6 @@ ACE_Message_Block::ACE_Message_Block (const ACE_Message_Block &mb,
|
||||
mb.message_block_allocator_) == -1)
|
||||
ACE_ERROR ((LM_ERROR,
|
||||
ACE_TEXT ("ACE_Message_Block")));
|
||||
|
||||
#if !defined (ACE_LACKS_CDR_ALIGNMENT)
|
||||
// Align ourselves
|
||||
char *start = ACE_ptr_align_binary (this->base (),
|
||||
@@ -642,11 +568,9 @@ ACE_Message_Block::ACE_Message_Block (const ACE_Message_Block &mb,
|
||||
#else
|
||||
char *start = this->base ();
|
||||
#endif /* ACE_LACKS_CDR_ALIGNMENT */
|
||||
|
||||
// Set our rd & wr pointers
|
||||
this->rd_ptr (start);
|
||||
this->wr_ptr (start);
|
||||
|
||||
#if !defined (ACE_LACKS_CDR_ALIGNMENT)
|
||||
// Get the alignment offset of the incoming ACE_Message_Block
|
||||
start = ACE_ptr_align_binary (mb.base (),
|
||||
@@ -654,25 +578,20 @@ ACE_Message_Block::ACE_Message_Block (const ACE_Message_Block &mb,
|
||||
#else
|
||||
start = mb.base ();
|
||||
#endif /* ACE_LACKS_CDR_ALIGNMENT */
|
||||
|
||||
// Actual offset for the incoming message block assuming that it
|
||||
// is also aligned to the same "align" byte
|
||||
size_t const wr_offset = mb.wr_ptr_ - (start - mb.base ());
|
||||
|
||||
// Copy wr_offset amount of data in to <this->data_block>
|
||||
(void) ACE_OS::memcpy (this->wr_ptr (),
|
||||
start,
|
||||
wr_offset);
|
||||
|
||||
// Dont move the write pointer, just leave it to the application
|
||||
// to do what it wants
|
||||
|
||||
}
|
||||
#if defined (ACE_LACKS_CDR_ALIGNMENT)
|
||||
ACE_UNUSED_ARG (align);
|
||||
#endif /* ACE_LACKS_CDR_ALIGNMENT */
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Message_Block::init_i (size_t size,
|
||||
ACE_Message_Type msg_type,
|
||||
@@ -690,7 +609,6 @@ ACE_Message_Block::init_i (size_t size,
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::init_i");
|
||||
ACE_FUNCTION_TIMEPROBE (ACE_MESSAGE_BLOCK_INIT_I_ENTER);
|
||||
|
||||
this->rd_ptr_ = 0;
|
||||
this->wr_ptr_ = 0;
|
||||
this->priority_ = priority;
|
||||
@@ -704,24 +622,19 @@ ACE_Message_Block::init_i (size_t size,
|
||||
this->cont_ = msg_cont;
|
||||
this->next_ = 0;
|
||||
this->prev_ = 0;
|
||||
|
||||
this->message_block_allocator_ = message_block_allocator;
|
||||
|
||||
if (this->data_block_ != 0)
|
||||
{
|
||||
this->data_block_->release ();
|
||||
this->data_block_ = 0;
|
||||
}
|
||||
|
||||
if (db == 0)
|
||||
{
|
||||
if (data_block_allocator == 0)
|
||||
ACE_ALLOCATOR_RETURN (data_block_allocator,
|
||||
ACE_Allocator::instance (),
|
||||
-1);
|
||||
|
||||
ACE_TIMEPROBE (ACE_MESSAGE_BLOCK_INIT_I_DB_ALLOC);
|
||||
|
||||
// Allocate the <ACE_Data_Block> portion, which is reference
|
||||
// counted.
|
||||
ACE_NEW_MALLOC_RETURN (db,
|
||||
@@ -736,7 +649,6 @@ ACE_Message_Block::init_i (size_t size,
|
||||
data_block_allocator),
|
||||
-1);
|
||||
ACE_TIMEPROBE (ACE_MESSAGE_BLOCK_INIT_I_DB_CTOR);
|
||||
|
||||
// Message block initialization may fail, while the construction
|
||||
// succeds. Since ACE may throw no exceptions, we have to do a
|
||||
// separate check and clean up, like this:
|
||||
@@ -748,21 +660,16 @@ ACE_Message_Block::init_i (size_t size,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the data_block_ pointer.
|
||||
this->data_block (db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACE_Data_Block::~ACE_Data_Block (void)
|
||||
{
|
||||
// Sanity check...
|
||||
ACE_ASSERT (this->reference_count_ <= 1);
|
||||
|
||||
// Just to be safe...
|
||||
this->reference_count_ = 0;
|
||||
|
||||
if (ACE_BIT_DISABLED (this->flags_,
|
||||
ACE_Message_Block::DONT_DELETE))
|
||||
{
|
||||
@@ -770,36 +677,27 @@ ACE_Data_Block::~ACE_Data_Block (void)
|
||||
this->base_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ACE_Data_Block *
|
||||
ACE_Data_Block::release_i (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_Data_Block::release_i");
|
||||
|
||||
ACE_ASSERT (this->reference_count_ > 0);
|
||||
|
||||
ACE_Data_Block *result = 0;
|
||||
|
||||
// decrement reference count
|
||||
--this->reference_count_;
|
||||
|
||||
if (this->reference_count_ == 0)
|
||||
// this will cause deletion of this
|
||||
result = 0;
|
||||
else
|
||||
result = this;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ACE_Data_Block *
|
||||
ACE_Data_Block::release_no_delete (ACE_Lock *lock)
|
||||
{
|
||||
ACE_TRACE ("ACE_Data_Block::release_no_delete");
|
||||
|
||||
ACE_Data_Block *result = 0;
|
||||
ACE_Lock *lock_to_be_used = 0;
|
||||
|
||||
// Check if we were passed in a lock
|
||||
if (lock != 0)
|
||||
{
|
||||
@@ -807,7 +705,6 @@ ACE_Data_Block::release_no_delete (ACE_Lock *lock)
|
||||
if (lock == this->locking_strategy_)
|
||||
// In this case no locking is required.
|
||||
lock_to_be_used = 0;
|
||||
|
||||
// The lock passed in does not match our lock
|
||||
else
|
||||
// Lock to be used is our lock
|
||||
@@ -817,30 +714,23 @@ ACE_Data_Block::release_no_delete (ACE_Lock *lock)
|
||||
else
|
||||
// Lock to be used is our lock
|
||||
lock_to_be_used = this->locking_strategy_;
|
||||
|
||||
// If there's a locking strategy then we need to acquire the lock
|
||||
// before decrementing the count.
|
||||
if (lock_to_be_used != 0)
|
||||
{
|
||||
ACE_GUARD_RETURN (ACE_Lock, ace_mon, *lock_to_be_used, 0);
|
||||
|
||||
result = this->release_i ();
|
||||
}
|
||||
else
|
||||
result = this->release_i ();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ACE_Data_Block *
|
||||
ACE_Data_Block::release (ACE_Lock *lock)
|
||||
{
|
||||
ACE_TRACE ("ACE_Data_Block::release");
|
||||
|
||||
ACE_Allocator *allocator = this->data_block_allocator_;
|
||||
|
||||
ACE_Data_Block *result = this->release_no_delete (lock);
|
||||
|
||||
// We must delete this outside the scope of the locking_strategy_
|
||||
// since otherwise we'd be trying to "release" through a deleted
|
||||
// pointer!
|
||||
@@ -850,34 +740,27 @@ ACE_Data_Block::release (ACE_Lock *lock)
|
||||
ACE_Data_Block);
|
||||
return result;
|
||||
}
|
||||
|
||||
ACE_Message_Block *
|
||||
ACE_Message_Block::release (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::release");
|
||||
|
||||
// We want to hold the data block in a temporary variable because we
|
||||
// invoked "delete this;" at some point, so using this->data_block_
|
||||
// could be a bad idea.
|
||||
ACE_Data_Block *tmp = this->data_block ();
|
||||
|
||||
// This flag is set to 1 when we have to destroy the data_block
|
||||
int destroy_dblock = 0;
|
||||
|
||||
ACE_Lock *lock = 0;
|
||||
|
||||
// Do we have a valid data block
|
||||
if (this->data_block ())
|
||||
{
|
||||
// Grab the lock that belongs to my data block
|
||||
lock = this->data_block ()->locking_strategy ();
|
||||
|
||||
// if we have a lock
|
||||
if (lock != 0)
|
||||
{
|
||||
// One guard for all
|
||||
ACE_GUARD_RETURN (ACE_Lock, ace_mon, *lock, 0);
|
||||
|
||||
// Call non-guarded release with <lock>
|
||||
destroy_dblock = this->release_i (lock);
|
||||
}
|
||||
@@ -889,7 +772,6 @@ ACE_Message_Block::release (void)
|
||||
else
|
||||
// This is the case when we don't even have a valid data block
|
||||
destroy_dblock = this->release_i (0);
|
||||
|
||||
if (destroy_dblock != 0)
|
||||
{
|
||||
ACE_Allocator *allocator = tmp->data_block_allocator ();
|
||||
@@ -897,27 +779,22 @@ ACE_Message_Block::release (void)
|
||||
allocator->free,
|
||||
ACE_Data_Block);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ACE_Message_Block::release_i (ACE_Lock *lock)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::release_i");
|
||||
|
||||
// Free up all the continuation messages.
|
||||
if (this->cont_)
|
||||
{
|
||||
ACE_Message_Block *mb = this->cont_;
|
||||
ACE_Message_Block *tmp = 0;
|
||||
|
||||
do
|
||||
{
|
||||
tmp = mb;
|
||||
mb = mb->cont_;
|
||||
tmp->cont_ = 0;
|
||||
|
||||
ACE_Data_Block *db = tmp->data_block ();
|
||||
if (tmp->release_i (lock) != 0)
|
||||
{
|
||||
@@ -928,12 +805,9 @@ ACE_Message_Block::release_i (ACE_Lock *lock)
|
||||
}
|
||||
}
|
||||
while (mb);
|
||||
|
||||
this->cont_ = 0;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
|
||||
if (ACE_BIT_DISABLED (this->flags_,
|
||||
ACE_Message_Block::DONT_DELETE) &&
|
||||
this->data_block ())
|
||||
@@ -942,7 +816,6 @@ ACE_Message_Block::release_i (ACE_Lock *lock)
|
||||
result = 1;
|
||||
this->data_block_ = 0;
|
||||
}
|
||||
|
||||
// We will now commit suicide: this object *must* have come from the
|
||||
// allocator given.
|
||||
if (this->message_block_allocator_ == 0)
|
||||
@@ -954,39 +827,31 @@ ACE_Message_Block::release_i (ACE_Lock *lock)
|
||||
allocator->free,
|
||||
ACE_Message_Block);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* static */ ACE_Message_Block *
|
||||
ACE_Message_Block::release (ACE_Message_Block *mb)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::release");
|
||||
|
||||
if (mb != 0)
|
||||
return mb->release ();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
ACE_Message_Block::~ACE_Message_Block (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::~ACE_Message_Block");
|
||||
|
||||
if (ACE_BIT_DISABLED (this->flags_,
|
||||
ACE_Message_Block::DONT_DELETE)&&
|
||||
this->data_block ())
|
||||
this->data_block ()->release ();
|
||||
|
||||
this->prev_ = 0;
|
||||
this->next_ = 0;
|
||||
}
|
||||
|
||||
ACE_Data_Block *
|
||||
ACE_Data_Block::duplicate (void)
|
||||
{
|
||||
ACE_TRACE ("ACE_Data_Block::duplicate");
|
||||
|
||||
// Create a new <ACE_Message_Block>, but share the <base_> pointer
|
||||
// data (i.e., don't copy that).
|
||||
if (this->locking_strategy_)
|
||||
@@ -997,10 +862,8 @@ ACE_Data_Block::duplicate (void)
|
||||
}
|
||||
else
|
||||
++this->reference_count_;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
#if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
|
||||
#define ACE_EXECUTION_TIME this->execution_time_
|
||||
#define ACE_DEADLINE_TIME this->deadline_time_
|
||||
@@ -1008,18 +871,14 @@ ACE_Data_Block::duplicate (void)
|
||||
#define ACE_EXECUTION_TIME ACE_Time_Value::zero
|
||||
#define ACE_DEADLINE_TIME ACE_Time_Value::max_time
|
||||
#endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
|
||||
|
||||
ACE_Message_Block *
|
||||
ACE_Message_Block::duplicate (void) const
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::duplicate");
|
||||
|
||||
ACE_Message_Block *nb = 0;
|
||||
|
||||
// Create a new <ACE_Message_Block> that contains unique copies of
|
||||
// the message block fields, but a reference counted duplicate of
|
||||
// the <ACE_Data_Block>.
|
||||
|
||||
// If there is no allocator, use the standard new and delete calls.
|
||||
if (this->message_block_allocator_ == 0)
|
||||
ACE_NEW_RETURN (nb,
|
||||
@@ -1063,19 +922,16 @@ ACE_Message_Block::duplicate (void) const
|
||||
this->data_block ()->data_block_allocator (),
|
||||
this->message_block_allocator_),
|
||||
0);
|
||||
|
||||
// Set the read and write pointers in the new <Message_Block> to the
|
||||
// same relative offset as in the existing <Message_Block>. Note
|
||||
// that we are assuming that the data_block()->base() pointer
|
||||
// doesn't change when it's duplicated.
|
||||
nb->rd_ptr (this->rd_ptr_);
|
||||
nb->wr_ptr (this->wr_ptr_);
|
||||
|
||||
// Increment the reference counts of all the continuation messages.
|
||||
if (this->cont_)
|
||||
{
|
||||
nb->cont_ = this->cont_->duplicate ();
|
||||
|
||||
// If things go wrong, release all of our resources and return
|
||||
// 0.
|
||||
if (nb->cont_ == 0)
|
||||
@@ -1084,10 +940,8 @@ ACE_Message_Block::duplicate (void) const
|
||||
nb = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return nb;
|
||||
}
|
||||
|
||||
ACE_Message_Block *
|
||||
ACE_Message_Block::duplicate (const ACE_Message_Block *mb)
|
||||
{
|
||||
@@ -1097,14 +951,11 @@ ACE_Message_Block::duplicate (const ACE_Message_Block *mb)
|
||||
else
|
||||
return mb->duplicate ();
|
||||
}
|
||||
|
||||
ACE_Data_Block *
|
||||
ACE_Data_Block::clone (ACE_Message_Block::Message_Flags mask) const
|
||||
{
|
||||
ACE_TRACE ("ACE_Data_Block::clone");
|
||||
|
||||
ACE_Data_Block *nb = this->clone_nocopy (mask);
|
||||
|
||||
// Copy all of the payload memory into the new object. The new block
|
||||
// was allocated with max_size_ (and, thus, it's cur_size_ is the same
|
||||
// as max_size_). Maintain the same "has been written" boundary in the
|
||||
@@ -1115,28 +966,21 @@ ACE_Data_Block::clone (ACE_Message_Block::Message_Flags mask) const
|
||||
this->base_,
|
||||
this->cur_size_);
|
||||
}
|
||||
|
||||
return nb;
|
||||
}
|
||||
|
||||
ACE_Data_Block *
|
||||
ACE_Data_Block::clone_nocopy (ACE_Message_Block::Message_Flags mask,
|
||||
size_t max_size) const
|
||||
{
|
||||
ACE_FUNCTION_TIMEPROBE(ACE_DATA_BLOCK_CLONE_ENTER);
|
||||
|
||||
ACE_TRACE ("ACE_Data_Block::clone_nocopy");
|
||||
|
||||
// You always want to clear this one to prevent memory leaks but you
|
||||
// might add some others later.
|
||||
const ACE_Message_Block::Message_Flags always_clear =
|
||||
ACE_Message_Block::DONT_DELETE;
|
||||
|
||||
const size_t newsize =
|
||||
max_size == 0 ? this->max_size_ : max_size;
|
||||
|
||||
ACE_Data_Block *nb = 0;
|
||||
|
||||
ACE_NEW_MALLOC_RETURN (nb,
|
||||
static_cast<ACE_Data_Block*> (
|
||||
this->data_block_allocator_->malloc (sizeof (ACE_Data_Block))),
|
||||
@@ -1148,7 +992,6 @@ ACE_Data_Block::clone_nocopy (ACE_Message_Block::Message_Flags mask,
|
||||
this->flags_, // flags
|
||||
this->data_block_allocator_),
|
||||
0);
|
||||
|
||||
// Message block initialization may fail while the construction
|
||||
// succeds. Since as a matter of policy, ACE may throw no
|
||||
// exceptions, we have to do a separate check like this.
|
||||
@@ -1160,26 +1003,20 @@ ACE_Data_Block::clone_nocopy (ACE_Message_Block::Message_Flags mask,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Set new flags minus the mask...
|
||||
nb->clr_flags (mask | always_clear);
|
||||
return nb;
|
||||
}
|
||||
|
||||
ACE_Message_Block *
|
||||
ACE_Message_Block::clone (Message_Flags mask) const
|
||||
{
|
||||
ACE_TRACE ("ACE_Message_Block::clone");
|
||||
|
||||
// Get a pointer to a "cloned" <ACE_Data_Block> (will copy the
|
||||
// values rather than increment the reference count).
|
||||
ACE_Data_Block *db = this->data_block ()->clone (mask);
|
||||
|
||||
if (db == 0)
|
||||
return 0;
|
||||
|
||||
ACE_Message_Block *nb = 0;
|
||||
|
||||
if(message_block_allocator_ == 0)
|
||||
{
|
||||
ACE_NEW_RETURN (nb,
|
||||
@@ -1225,18 +1062,15 @@ ACE_Message_Block::clone (Message_Flags mask) const
|
||||
db->data_block_allocator (),
|
||||
this->message_block_allocator_);
|
||||
}
|
||||
|
||||
if (nb == 0)
|
||||
{
|
||||
db->release ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Set the read and write pointers in the new <Message_Block> to the
|
||||
// same relative offset as in the existing <Message_Block>.
|
||||
nb->rd_ptr (this->rd_ptr_);
|
||||
nb->wr_ptr (this->wr_ptr_);
|
||||
|
||||
// Clone all the continuation messages if necessary.
|
||||
if (this->cont () != 0
|
||||
&& (nb->cont_ = this->cont ()->clone (mask)) == 0)
|
||||
@@ -1246,7 +1080,6 @@ ACE_Message_Block::clone (Message_Flags mask) const
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
// This is private.
|
||||
ACE_Message_Block &
|
||||
ACE_Message_Block::operator= (const ACE_Message_Block &)
|
||||
@@ -1254,7 +1087,6 @@ ACE_Message_Block::operator= (const ACE_Message_Block &)
|
||||
ACE_TRACE ("ACE_Message_Block::operator=");
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
ACE_Data_Block::base (char *msg_data,
|
||||
size_t msg_length,
|
||||
@@ -1263,12 +1095,10 @@ ACE_Data_Block::base (char *msg_data,
|
||||
if (ACE_BIT_DISABLED (this->flags_,
|
||||
ACE_Message_Block::DONT_DELETE))
|
||||
this->allocator_strategy_->free (this->base_);
|
||||
|
||||
this->max_size_ = msg_length;
|
||||
this->cur_size_ = msg_length;
|
||||
this->base_ = msg_data;
|
||||
this->flags_ = msg_flags;
|
||||
}
|
||||
|
||||
ACE_END_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user