199 {
200 pthread_mutex_init (&_mutex, NULL);
201 pthread_cond_init (&_waitQ, NULL);
202 pthread_cond_init (&_timeQ, NULL);
203 pthread_cond_init (&_termwait, NULL);
204
205 pthread_key_create (&_llkey, NULL);
206
207 pthread_attr_init (&_threadattrs);
208
209 const size_t TWOMEG = (2*1024*1024);
210 size_t default_stacksize = 0;
211
212 if ( pthread_attr_getstacksize (&_threadattrs,
213 &default_stacksize) != 0 )
214 default_stacksize = TWOMEG;
215
216 if ( thread_stacksize != 0 ) {
217 default_stacksize = thread_stacksize;
218 } else if ( default_stacksize < TWOMEG ) {
219 default_stacksize = TWOMEG;
220 }
221
222 if ( default_stacksize < PTHREAD_STACK_MIN )
223 default_stacksize = PTHREAD_STACK_MIN;
224
225 pthread_attr_setstacksize (&_threadattrs, default_stacksize);
226
227 pthread_attr_setdetachstate (&_threadattrs, PTHREAD_CREATE_DETACHED);
228
229 _running = false;
230 _terminating = false;
231
232 _nthreads = 0;
233 _nactive = 0;
234 _nblocked = 0;
235 _ntimer = 0;
236 _nwait = 0;
237
238 _duetime.tv_sec = 0;
239 _duetime.tv_nsec = 0;
240
241 long config_cpu, online_cpu;
242
243 isode_cpucount (&config_cpu, &online_cpu, 0, 0);
244
245 if ( num_threads != 0 )
246 online_cpu = num_threads;
247
248 _activelimit = online_cpu > 2 ? online_cpu : 2;
249 _threadlimit = _activelimit > 10 ? 2*_activelimit : 20;
250
251 if ( _threadlimit < thread_limit )
252 _threadlimit = thread_limit;
253
254 _mainQ = new AsyncEventPriorityQueue;
255 _timerQ = new AsyncEventTimerQueue;
256 _atExitQ = new AsyncEventPlainQueue;
257
258 LOG_DEBUG (("ThreadManager created"));
259 }