Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Activation_Queue.cpp
blob628ae2e7a8ea7af3a74a06c8e8b266ad449e5e1c
1 #include "ace/Activation_Queue.h"
3 #if !defined (__ACE_INLINE__)
4 #include "ace/Activation_Queue.inl"
5 #endif /* __ACE_INLINE__ */
7 #include "ace/Log_Category.h"
8 #include "ace/Method_Request.h"
9 #include "ace/Malloc_Base.h"
10 #include "ace/Time_Value.h"
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_ALLOC_HOOK_DEFINE (ACE_Activation_Queue)
16 void
17 ACE_Activation_Queue::dump () const
19 #if defined (ACE_HAS_DUMP)
20 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
21 ACELIB_DEBUG ((LM_DEBUG,
22 ACE_TEXT ("delete_queue_ = %d\n"),
23 this->delete_queue_));
24 ACELIB_DEBUG ((LM_INFO, ACE_TEXT ("queue_:\n")));
25 if (this->queue_)
26 this->queue_->dump();
27 else
28 //FUZZ: disable check_for_NULL
29 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("(NULL)\n")));
30 //FUZZ: enable check_for_NULL
32 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
33 #endif /* ACE_HAS_DUMP */
36 ACE_Activation_Queue::ACE_Activation_Queue (ACE_Message_Queue<ACE_SYNCH> *new_queue,
37 ACE_Allocator *alloc,
38 ACE_Allocator *db_alloc)
39 : delete_queue_ (false)
40 , allocator_(alloc)
41 , data_block_allocator_(db_alloc)
43 if (this->allocator_ == 0)
44 this->allocator_ = ACE_Allocator::instance ();
46 if (new_queue)
47 this->queue_ = new_queue;
48 else
50 ACE_NEW (this->queue_,
51 ACE_Message_Queue<ACE_SYNCH>);
52 this->delete_queue_ = true;
56 void
57 ACE_Activation_Queue::queue (ACE_Message_Queue<ACE_SYNCH> *q)
59 // Destroy the internal queue if one exist.
60 if (this->delete_queue_)
62 // Destroy the current queue.
63 delete this->queue_;
65 // Set the flag to false. NOTE that the delete_queue_ flag is a
66 // flag used to only indicate whether or not if an internal
67 // ACE_Message_Queue has been created, therefore, it will not
68 // affect the user if the user decided to replace the queue with
69 // their own queue no matter how many time they call on this
70 // function.
71 this->delete_queue_ = false;
74 queue_ = q;
77 ACE_Activation_Queue::~ACE_Activation_Queue ()
79 if (this->delete_queue_)
80 delete this->queue_;
83 ACE_Method_Request *
84 ACE_Activation_Queue::dequeue (ACE_Time_Value *tv)
86 ACE_Message_Block *mb = 0;
88 // Dequeue the message.
89 if (this->queue_->dequeue_head (mb, tv) != -1)
91 // Get the next <Method_Request>.
92 ACE_Method_Request *mr =
93 reinterpret_cast<ACE_Method_Request *> (mb->base ());
94 // Delete the message block.
95 mb->release ();
96 return mr;
98 else
99 return 0;
103 ACE_Activation_Queue::enqueue (ACE_Method_Request *mr,
104 ACE_Time_Value *tv)
106 ACE_Message_Block *mb = 0;
108 // We pass sizeof (*mr) here so that flow control will work
109 // correctly. Since we also pass <mr> note that no unnecessary
110 // memory is actually allocated -- just the size field is set.
111 ACE_NEW_MALLOC_RETURN (mb,
112 static_cast<ACE_Message_Block *> (this->allocator_->malloc (sizeof (ACE_Message_Block))),
113 ACE_Message_Block (sizeof (*mr), // size
114 ACE_Message_Block::MB_DATA, // type
115 0, // cont
116 (char *) mr, // data
117 0, // allocator
118 0, // locking strategy
119 mr->priority (), // priority
120 ACE_Time_Value::zero, // execution time
121 ACE_Time_Value::max_time, // absolute time of deadline
122 this->data_block_allocator_, // data_block allocator
123 this->allocator_), // message_block allocator
124 -1);
126 // Enqueue in priority order.
127 int const result = this->queue_->enqueue_prio (mb, tv);
129 // Free ACE_Message_Block if enqueue_prio failed.
130 if (result == -1)
131 ACE_DES_FREE (mb, this->allocator_->free, ACE_Message_Block);
133 return result;
136 ACE_END_VERSIONED_NAMESPACE_DECL