00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef TAO_THREAD_POOL_H
00015 #define TAO_THREAD_POOL_H
00016
00017 #include "ace/pre.h"
00018 #include "tao/orbconf.h"
00019
00020 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00021
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif
00025
00026 #include "tao/RTCORBA/RTCORBA_includeC.h"
00027 #include "tao/RTCORBA/RT_ORBInitializer.h"
00028 #include "ace/Hash_Map_Manager.h"
00029 #include "tao/Thread_Lane_Resources.h"
00030 #include "tao/New_Leader_Generator.h"
00031 #include "ace/Task.h"
00032 #include "ace/Null_Mutex.h"
00033
00034 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00035
00036 class TAO_Thread_Lane;
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 class TAO_RTCORBA_Export TAO_RT_New_Leader_Generator
00047 : public TAO_New_Leader_Generator
00048 {
00049 public:
00050
00051
00052 TAO_RT_New_Leader_Generator (TAO_Thread_Lane &lane);
00053
00054
00055
00056 void no_leaders_available (void);
00057
00058 private:
00059
00060
00061 TAO_Thread_Lane &lane_;
00062 };
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 class TAO_Thread_Pool_Threads : public ACE_Task_Base
00073 {
00074 public:
00075
00076
00077 TAO_Thread_Pool_Threads (TAO_Thread_Lane &lane);
00078
00079
00080 int svc (void);
00081
00082
00083 TAO_Thread_Lane &lane (void) const;
00084
00085
00086 static void set_tss_resources (TAO_ORB_Core &orb_core,
00087 TAO_Thread_Lane &thread_lane);
00088
00089 protected:
00090
00091 virtual int run (TAO_ORB_Core &orb_core);
00092
00093
00094 TAO_Thread_Lane &lane_;
00095 };
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 class TAO_Dynamic_Thread_Pool_Threads : public TAO_Thread_Pool_Threads
00106 {
00107 public:
00108
00109 TAO_Dynamic_Thread_Pool_Threads (TAO_Thread_Lane &lane);
00110
00111 protected:
00112
00113 virtual int run (TAO_ORB_Core &orb_core);
00114 };
00115
00116 class TAO_Thread_Pool;
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 class TAO_RTCORBA_Export TAO_Thread_Lane
00127 {
00128 public:
00129
00130 TAO_Thread_Lane (TAO_Thread_Pool &pool,
00131 CORBA::ULong id,
00132 CORBA::Short lane_priority,
00133 CORBA::ULong static_threads,
00134 CORBA::ULong dynamic_threads,
00135 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00136 ACE_Time_Value const &dynamic_thread_time);
00137
00138
00139 ~TAO_Thread_Lane (void);
00140
00141
00142 void open (void);
00143
00144
00145 void finalize (void);
00146
00147
00148 void shutdown_reactor (void);
00149
00150
00151 void wait (void);
00152
00153
00154 int is_collocated (const TAO_MProfile &mprofile);
00155
00156
00157 int create_static_threads (void);
00158
00159
00160
00161
00162
00163 void shutting_down (void);
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 bool new_dynamic_thread (void);
00175
00176
00177
00178 TAO_Thread_Pool &pool (void) const;
00179 CORBA::ULong id (void) const;
00180
00181 CORBA::Short lane_priority (void) const;
00182 CORBA::ULong static_threads (void) const;
00183 CORBA::ULong dynamic_threads (void) const;
00184
00185 CORBA::ULong current_threads (void) const;
00186
00187 CORBA::Short native_priority (void) const;
00188
00189 TAO_Thread_Lane_Resources &resources (void);
00190
00191 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan (void) const;
00192
00193 ACE_Time_Value const &dynamic_thread_time (void) const;
00194
00195
00196 private:
00197
00198
00199 void validate_and_map_priority (void);
00200
00201 int create_threads_i (TAO_Thread_Pool_Threads &thread_pool,
00202 CORBA::ULong number_of_threads,
00203 long thread_flags);
00204
00205
00206
00207 int create_dynamic_threads (CORBA::ULong number_of_threads);
00208
00209
00210 TAO_Thread_Pool &pool_;
00211
00212
00213 CORBA::ULong const id_;
00214
00215 CORBA::Short lane_priority_;
00216
00217
00218
00219 bool shutdown_;
00220
00221
00222 CORBA::ULong const static_threads_number_;
00223
00224
00225 CORBA::ULong const dynamic_threads_number_;
00226
00227
00228 TAO_Thread_Pool_Threads static_threads_;
00229
00230
00231 TAO_Dynamic_Thread_Pool_Threads dynamic_threads_;
00232
00233 TAO_RT_New_Leader_Generator new_thread_generator_;
00234
00235 TAO_Thread_Lane_Resources resources_;
00236
00237 CORBA::Short native_priority_;
00238
00239 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan const lifespan_;
00240
00241 ACE_Time_Value const dynamic_thread_time_;
00242
00243
00244 mutable TAO_SYNCH_MUTEX lock_;
00245 };
00246
00247 class TAO_Thread_Pool_Manager;
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 class TAO_RTCORBA_Export TAO_Thread_Pool
00259 {
00260 public:
00261
00262
00263 TAO_Thread_Pool (TAO_Thread_Pool_Manager &manager,
00264 CORBA::ULong id,
00265 CORBA::ULong stack_size,
00266 CORBA::ULong static_threads,
00267 CORBA::ULong dynamic_threads,
00268 CORBA::Short default_priority,
00269 CORBA::Boolean allow_request_buffering,
00270 CORBA::ULong max_buffered_requests,
00271 CORBA::ULong max_request_buffer_size,
00272 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00273 ACE_Time_Value const &dynamic_thread_time);
00274
00275
00276 TAO_Thread_Pool (TAO_Thread_Pool_Manager &manager,
00277 CORBA::ULong id,
00278 CORBA::ULong stack_size,
00279 const RTCORBA::ThreadpoolLanes &lanes,
00280 CORBA::Boolean allow_borrowing,
00281 CORBA::Boolean allow_request_buffering,
00282 CORBA::ULong max_buffered_requests,
00283 CORBA::ULong max_request_buffer_size,
00284 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00285 ACE_Time_Value const &dynamic_thread_time);
00286
00287
00288 ~TAO_Thread_Pool (void);
00289
00290
00291 void open (void);
00292
00293
00294 void finalize (void);
00295
00296
00297 void shutdown_reactor (void);
00298
00299
00300 void wait (void);
00301
00302
00303 void shutting_down (void);
00304
00305
00306 int is_collocated (const TAO_MProfile &mprofile);
00307
00308
00309 int create_static_threads (void);
00310
00311
00312 bool with_lanes (void) const;
00313
00314
00315
00316
00317 TAO_Thread_Pool_Manager &manager (void) const;
00318 CORBA::ULong id (void) const;
00319
00320 CORBA::ULong stack_size (void) const;
00321 CORBA::Boolean allow_borrowing (void) const;
00322 CORBA::Boolean allow_request_buffering (void) const;
00323 CORBA::ULong max_buffered_requests (void) const;
00324 CORBA::ULong max_request_buffer_size (void) const;
00325
00326 TAO_Thread_Lane **lanes (void);
00327 CORBA::ULong number_of_lanes (void) const;
00328
00329
00330 private:
00331
00332 TAO_Thread_Pool_Manager &manager_;
00333 CORBA::ULong id_;
00334
00335 CORBA::ULong stack_size_;
00336 CORBA::Boolean allow_borrowing_;
00337 CORBA::Boolean allow_request_buffering_;
00338 CORBA::ULong max_buffered_requests_;
00339 CORBA::ULong max_request_buffer_size_;
00340 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan const lifespan_;
00341 ACE_Time_Value const dynamic_thread_time_;
00342
00343 TAO_Thread_Lane **lanes_;
00344 CORBA::ULong number_of_lanes_;
00345 bool with_lanes_;
00346 };
00347
00348 class TAO_ORB_Core;
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 class TAO_RTCORBA_Export TAO_Thread_Pool_Manager
00359 {
00360 public:
00361
00362
00363 TAO_Thread_Pool_Manager (TAO_ORB_Core &orb_core);
00364
00365
00366 ~TAO_Thread_Pool_Manager (void);
00367
00368
00369 void finalize (void);
00370
00371
00372 void shutdown_reactor (void);
00373
00374
00375 void wait (void);
00376
00377
00378 int is_collocated (const TAO_MProfile &mprofile);
00379
00380
00381 RTCORBA::ThreadpoolId
00382 create_threadpool (CORBA::ULong stacksize,
00383 CORBA::ULong static_threads,
00384 CORBA::ULong dynamic_threads,
00385 RTCORBA::Priority default_priority,
00386 CORBA::Boolean allow_request_buffering,
00387 CORBA::ULong max_buffered_requests,
00388 CORBA::ULong max_request_buffer_size,
00389 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00390 ACE_Time_Value const &dynamic_thread_time);
00391
00392
00393 RTCORBA::ThreadpoolId
00394 create_threadpool_with_lanes (CORBA::ULong stacksize,
00395 const RTCORBA::ThreadpoolLanes & lanes,
00396 CORBA::Boolean allow_borrowing,
00397 CORBA::Boolean allow_request_buffering,
00398 CORBA::ULong max_buffered_requests,
00399 CORBA::ULong max_request_buffer_size,
00400 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00401 ACE_Time_Value const &dynamic_thread_time);
00402
00403
00404 void destroy_threadpool (RTCORBA::ThreadpoolId threadpool);
00405
00406 TAO_Thread_Pool *get_threadpool (RTCORBA::ThreadpoolId thread_pool_id);
00407
00408
00409 typedef ACE_Hash_Map_Manager<RTCORBA::ThreadpoolId, TAO_Thread_Pool *, ACE_Null_Mutex> THREAD_POOLS;
00410
00411
00412
00413 TAO_ORB_Core &orb_core (void) const;
00414
00415
00416 private:
00417
00418
00419
00420
00421 RTCORBA::ThreadpoolId
00422 create_threadpool_i (CORBA::ULong stacksize,
00423 CORBA::ULong static_threads,
00424 CORBA::ULong dynamic_threads,
00425 RTCORBA::Priority default_priority,
00426 CORBA::Boolean allow_request_buffering,
00427 CORBA::ULong max_buffered_requests,
00428 CORBA::ULong max_request_buffer_size,
00429 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00430 ACE_Time_Value const &dynamic_thread_time);
00431
00432 RTCORBA::ThreadpoolId
00433 create_threadpool_with_lanes_i (CORBA::ULong stacksize,
00434 const RTCORBA::ThreadpoolLanes & lanes,
00435 CORBA::Boolean allow_borrowing,
00436 CORBA::Boolean allow_request_buffering,
00437 CORBA::ULong max_buffered_requests,
00438 CORBA::ULong max_request_buffer_size,
00439 TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan,
00440 ACE_Time_Value const &dynamic_thread_time);
00441
00442 RTCORBA::ThreadpoolId
00443 create_threadpool_helper (TAO_Thread_Pool *thread_pool);
00444
00445
00446 private:
00447
00448 TAO_ORB_Core &orb_core_;
00449
00450 THREAD_POOLS thread_pools_;
00451 RTCORBA::ThreadpoolId thread_pool_id_counter_;
00452 TAO_SYNCH_MUTEX lock_;
00453 };
00454
00455 TAO_END_VERSIONED_NAMESPACE_DECL
00456
00457 #if defined (__ACE_INLINE__)
00458 #include "tao/RTCORBA/Thread_Pool.inl"
00459 #endif
00460
00461 #endif
00462
00463 #include "ace/post.h"
00464
00465 #endif