Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS3 / jaws3 / TPOOL_Concurrency.cpp
blob1e78ef73a758006fa4168fa55c19384813ae5458
1 #include "ace/OS_NS_stdlib.h"
2 #include "ace/Message_Block.h"
4 #ifndef JAWS_BUILD_DLL
5 #define JAWS_BUILD_DLL
6 #endif
8 #include "jaws3/TPOOL_Concurrency.h"
9 #include "jaws3/Protocol_Handler.h"
10 #include "jaws3/Options.h"
12 JAWS_TPOOL_Concurrency::JAWS_TPOOL_Concurrency ()
13 : number_of_threads_ (5)
14 , shutdown_task_ (0)
15 , error_ (0)
17 const char *value = JAWS_Options::instance ()->getenv ("JAWS_TPOOL_THREADS");
18 if (value != 0)
19 this->number_of_threads_ = ACE_OS::atoi (value);
20 else
21 this->number_of_threads_ = ACE_OS::atoi (JAWS_DEFAULT_TPOOL_THREADS);
23 if (this->number_of_threads_ <= 0)
24 this->number_of_threads_ = 5;
26 int r;
27 r = this->activate ( THR_BOUND | THR_JOINABLE, this->number_of_threads_);
29 if (r < 0)
31 // ACE_ERROR
32 this->error_ = 1;
33 this->shutdown_task_ = 1;
37 int
38 JAWS_TPOOL_Concurrency::putq (JAWS_Protocol_Handler *ph)
40 if (this->error_)
41 return -1;
43 JAWS_CONCURRENCY_TASK *task = this;
44 return task->putq (& ph->mb_);
47 int
48 JAWS_TPOOL_Concurrency::getq (JAWS_Protocol_Handler *&ph)
50 ph = 0;
52 JAWS_CONCURRENCY_TASK *task = this;
54 if (this->shutdown_task_ && task->msg_queue ()->message_count () == 0)
55 return -1;
57 ACE_Message_Block *mb = 0;
59 int result = task->getq (mb);
61 if (result != -1)
63 ph = (JAWS_Protocol_Handler *) mb->base ();
65 if (ph == 0)
67 // Shutdown this task;
68 this->shutdown_task_ = 1;
69 if (this->number_of_threads_ && this->number_of_threads_-- > 1)
71 task->putq (mb);
72 result = -1;
77 return result;