1 #include "tao/CSD_ThreadPool/CSD_TP_Queue.h"
2 #include "tao/CSD_ThreadPool/CSD_TP_Request.h"
3 #include "tao/CSD_ThreadPool/CSD_TP_Queue_Visitor.h"
5 #if !defined (__ACE_INLINE__)
6 # include "tao/CSD_ThreadPool/CSD_TP_Queue.inl"
7 #endif /* ! __ACE_INLINE__ */
9 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 TAO::CSD::TP_Queue::put(TP_Request
* request
)
14 // The request is passed in as an "in" argument, and we would like to
15 // hold on to a "copy" within the queue (the linked list). We will
16 // perform an _add_ref() on the request now to make the queue's "copy".
21 // The tail_ is a NULL pointer only when the queue is empty.
22 // Make the request be the only element in the queue.
23 this->head_
= this->tail_
= request
;
25 // Make sure the request's prev_ and next_ pointers are set to NULL.
26 request
->prev_
= request
->next_
= 0;
30 // There is at least one request already in the queue. "Append" the
31 // supplied request object to the end of the queue.
32 request
->prev_
= this->tail_
;
34 this->tail_
->next_
= request
;
35 this->tail_
= request
;
42 TAO::CSD::TP_Queue::accept_visitor(TP_Queue_Visitor
& visitor
)
44 TP_Request
* cur
= this->head_
;
48 TP_Request
* prev
= cur
->prev_
;
49 TP_Request
* next
= cur
->next_
;
51 // Pass the current request to the visitor. Also pass-in a reference
52 // to the remove_from_queue flag. The visitor may decide that it
53 // wants to keep the current request for itself, and desires that the
54 // request be (surgically) removed from the queue. The visitor also
55 // gets to decide, via its return value, whether or not visitation
56 // should continue (or cease to continue).
57 bool remove_from_queue
= false;
59 bool continue_visitation
= visitor
.visit_request(cur
,remove_from_queue
);
61 if (remove_from_queue
)
63 // Create a local handle to release the current request once
64 // the handle falls out of scope. We need to do this because the
65 // queue "owns" a "copy" of each request in the queue.
66 TP_Request_Handle handle
= cur
;
68 if (this->head_
== cur
)
70 // The current request is at the front (the head_) of the queue.
72 // Move the head_ to the next request in the queue.
77 // Not only was the current request at the front of the
78 // queue - it was the *only* request in the queue.
79 // Update the tail_ pointer now that the queue is empty.
84 // Set the (new) head_ request's prev_ pointer to be NULL.
85 this->head_
->prev_
= 0;
88 else if (this->tail_
== cur
)
90 // The current request is not at the front of the queue,
91 // but it is at the back of the queue. This implies that
92 // the queue currently contains at least two requests -
93 // the current request (cur), and the previous request (prev).
94 // The point is that we can now assume that the 'prev' pointer
95 // is never NULL in this case.
97 this->tail_
->next_
= 0;
101 // The current request is not at the front or at the back.
102 // This implies that there are at least three requests in
103 // the queue. We can assume that the 'next' and 'prev'
104 // pointers are never NULL in this case.
110 if (!continue_visitation
)
112 // The visitor doesn't want to procede with any further visitation.
113 // Break out of the visitation loop now.
117 // Move on to the next request in the queue.
122 TAO_END_VERSIONED_NAMESPACE_DECL