1 #include "ace/OS_NS_stdlib.h"
2 #include "ace/Message_Block.h"
8 #include "jaws3/Concurrency.h"
9 #include "jaws3/THYBRID_Concurrency.h"
10 #include "jaws3/Protocol_Handler.h"
11 #include "jaws3/Options.h"
14 JAWS_THYBRID_Concurrency::JAWS_THYBRID_Concurrency ()
16 , min_number_of_threads_ (1)
17 , max_number_of_threads_ (-1)
23 value
= JAWS_Options::instance ()->getenv ("JAWS_MIN_THYBRID_THREADS");
25 this->min_number_of_threads_
= ACE_OS::atoi (value
);
27 this->min_number_of_threads_
=
28 ACE_OS::atoi (JAWS_DEFAULT_MIN_THYBRID_THREADS
);
30 if (this->min_number_of_threads_
<= 0)
31 this->min_number_of_threads_
= 1;
33 value
= JAWS_Options::instance ()->getenv ("JAWS_MAX_THYBRID_THREADS");
35 this->max_number_of_threads_
= ACE_OS::atoi (value
);
37 this->max_number_of_threads_
=
38 ACE_OS::atoi (JAWS_DEFAULT_MAX_THYBRID_THREADS
);
40 if (this->max_number_of_threads_
<= 0)
41 this->max_number_of_threads_
= -1;
42 else if (this->max_number_of_threads_
< this->min_number_of_threads_
)
43 this->max_number_of_threads_
= this->min_number_of_threads_
;
46 r
= this->activate (THR_BOUND
| THR_JOINABLE
, this->min_number_of_threads_
);
49 this->shutdown_task_
= 1;
55 JAWS_THYBRID_Concurrency::putq (JAWS_Protocol_Handler
*ph
)
60 JAWS_CONCURRENCY_TASK
*task
= this;
61 int result
= task
->putq (& ph
->mb_
);
65 if (this->getting_
< this->min_number_of_threads_
66 && (this->max_number_of_threads_
< 0
67 || this->thr_count () < (size_t) this->max_number_of_threads_
))
70 r
= this->activate ( THR_BOUND
| THR_JOINABLE
71 , 1 // number of threads
86 JAWS_THYBRID_Concurrency::getq (JAWS_Protocol_Handler
*&ph
)
90 JAWS_CONCURRENCY_TASK
*task
= this;
92 if (this->shutdown_task_
&& task
->msg_queue ()->message_count () == 0)
95 int getting
= ++(this->getting_
);
97 if (getting
> this->min_number_of_threads_
)
99 if (task
->msg_queue ()->message_count () == 0)
106 ACE_Message_Block
*mb
= 0;
107 int result
= task
->getq (mb
);
111 ph
= (JAWS_Protocol_Handler
*) mb
->base ();
115 // Shutdown this task;
116 this->shutdown_task_
= 1;
117 if (this->getting_
> 1)