1 #include "Server_Thread_Pool.h"
3 #include "ace/OS_NS_unistd.h"
8 Thread_Pool::close (u_long
)
11 "(%t) worker thread closing down\n"));
15 Thread_Pool::Thread_Pool (CORBA::ORB_ptr orb
,
16 ACE_Thread_Manager
*thr_mgr
,
18 : ACE_Task
<ACE_SYNCH
> (thr_mgr
),
19 orb_(CORBA::ORB::_duplicate(orb
)),
22 if (this->activate (THR_NEW_LWP
,
26 "activate failed\n"));
29 Thread_Pool::~Thread_Pool ()
34 Thread_Pool::shutdown ()
36 thr_mgr_
->cancel_grp (grp_id_
);
38 int n_threads
= nt_
.value ();
39 for (int i
= 0; i
< n_threads
; ++i
)
42 "(%t) eof, sending block for thread=%d\n",
44 ACE_Message_Block
*mb1
;
46 ACE_Message_Block ((char*) Test::Echo::_nil ()),
50 if (this->put (mb1
) == -1)
55 // this sleep helps to shutdown correctly -> was an error!
62 // Simply enqueue the Message_Block into the end of the queue.
64 Thread_Pool::put (Test::Echo_ptr echoptr
)
66 char * charData
= (char *) Test::Echo::_duplicate (echoptr
);
68 ACE_Message_Block
*mb
= 0;
69 ACE_NEW_RETURN(mb
, ACE_Message_Block(charData
), -1);
70 return this->put (mb
);
74 Thread_Pool::put (ACE_Message_Block
*mb
,
77 return this->putq (mb
, tv
);
80 // Iterate <n_iterations> time printing off a message and "waiting"
81 // for all other threads to complete this iteration.
86 // Note that the <ACE_Task::svc_run> method automatically adds us to
87 // the Thread_Manager when the thread begins.
91 // Keep looping, reading a message out of the queue, until we get a
92 // message with a length == 0, which signals us to quit.
96 ACE_Message_Block
*mb
= 0;
100 "(%t) in iteration %d before getq ()\n",
104 if (this->getq (mb
) == -1)
106 ACE_ERROR ((LM_ERROR
,
107 "(%t) in iteration %d, got result -1, exiting\n",
113 if (mb
->length() == 0)
115 //FUZZ: disable check_for_NULL
116 ACE_DEBUG ((LM_DEBUG
,
117 "(%t) in iteration %d, got NULL message, exiting\n",
119 //FUZZ: enable check_for_NULL
124 Test::Echo_var echo
= (Test::Echo_ptr
)mb
->base();
128 if (CORBA::is_nil(echo
.in()))
130 //FUZZ: disable check_for_NULL
131 ACE_DEBUG ((LM_DEBUG
,
132 "(%t) in iteration %d, got NULL message, exiting\n",
134 //FUZZ: enable check_for_NULL
138 // Keep calling a few times after receiving exceptions
139 for(int exception_count
= 50; exception_count
; --exception_count
)
143 // keep calling until get an exception
149 Test::Payload
pload (10);
151 ACE_OS::memset (pload
.get_buffer(), pload
.length(), 0);
152 echo
->echo_payload (pload
);
157 Test::Payload_var pout
;
158 echo
->echo_payload_out (pout
.out());
160 // time_t last_success = ACE_OS::time();
164 catch (const CORBA::Exception
&)
166 // Just forget the exception and continue
175 orb_
->shutdown (false);
178 // Note that the <ACE_Task::svc_run> method automatically removes us
179 // from the <ACE_Thread_Manager> when the thread exits.