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 #define TAO_RTCORBA_SAFE_INCLUDE
00027 #include "tao/RTCORBA/RTCORBAC.h"
00028 #undef TAO_RTCORBA_SAFE_INCLUDE
00029
00030 #include "ace/Hash_Map_Manager.h"
00031 #include "tao/Thread_Lane_Resources.h"
00032 #include "tao/New_Leader_Generator.h"
00033 #include "ace/Task.h"
00034 #include "ace/Null_Mutex.h"
00035
00036 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00037
00038 class TAO_Thread_Lane;
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 class TAO_RTCORBA_Export TAO_RT_New_Leader_Generator
00049 : public TAO_New_Leader_Generator
00050 {
00051 public:
00052
00053
00054 TAO_RT_New_Leader_Generator (TAO_Thread_Lane &lane);
00055
00056
00057
00058 void no_leaders_available (void);
00059
00060 private:
00061
00062
00063 TAO_Thread_Lane &lane_;
00064 };
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 class TAO_Thread_Pool_Threads : public ACE_Task_Base
00075 {
00076 public:
00077
00078
00079 TAO_Thread_Pool_Threads (TAO_Thread_Lane &lane);
00080
00081
00082 int svc (void);
00083
00084
00085 TAO_Thread_Lane &lane (void) const;
00086
00087
00088 static void set_tss_resources (TAO_ORB_Core &orb_core,
00089 TAO_Thread_Lane &thread_lane);
00090
00091 protected:
00092
00093 virtual int run (TAO_ORB_Core &orb_core ACE_ENV_ARG_PARAMETER);
00094
00095
00096 TAO_Thread_Lane &lane_;
00097 };
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 class TAO_Dynamic_Thread_Pool_Threads : public TAO_Thread_Pool_Threads
00108 {
00109 public:
00110
00111 TAO_Dynamic_Thread_Pool_Threads (TAO_Thread_Lane &lane);
00112
00113 protected:
00114
00115 virtual int run (TAO_ORB_Core &orb_core ACE_ENV_ARG_PARAMETER);
00116 };
00117
00118 class TAO_Thread_Pool;
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 class TAO_RTCORBA_Export TAO_Thread_Lane
00129 {
00130 public:
00131
00132
00133 TAO_Thread_Lane (TAO_Thread_Pool &pool,
00134 CORBA::ULong id,
00135 CORBA::Short lane_priority,
00136 CORBA::ULong static_threads,
00137 CORBA::ULong dynamic_threads,
00138 ACE_Time_Value const &dynamic_thread_idle_timeout
00139 ACE_ENV_ARG_DECL);
00140
00141
00142 ~TAO_Thread_Lane (void);
00143
00144
00145 void open (ACE_ENV_SINGLE_ARG_DECL);
00146
00147
00148 void finalize (void);
00149
00150
00151 void shutdown_reactor (void);
00152
00153
00154 void wait (void);
00155
00156
00157 int is_collocated (const TAO_MProfile &mprofile);
00158
00159
00160 int create_static_threads (void);
00161
00162
00163
00164
00165
00166 void shutting_down (void);
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 bool new_dynamic_thread (void);
00178
00179
00180
00181
00182 TAO_Thread_Pool &pool (void) const;
00183 CORBA::ULong id (void) const;
00184
00185 CORBA::Short lane_priority (void) const;
00186 CORBA::ULong static_threads (void) const;
00187 CORBA::ULong dynamic_threads (void) const;
00188
00189 CORBA::ULong current_threads (void) const;
00190
00191 CORBA::Short native_priority (void) const;
00192
00193 TAO_Thread_Lane_Resources &resources (void);
00194
00195 ACE_Time_Value const &dynamic_thread_idle_timeout (void) const;
00196
00197
00198 private:
00199
00200
00201 void validate_and_map_priority (ACE_ENV_SINGLE_ARG_DECL);
00202
00203 int create_threads_i (TAO_Thread_Pool_Threads &thread_pool,
00204 CORBA::ULong number_of_threads,
00205 long thread_flags);
00206
00207
00208
00209 int create_dynamic_threads (CORBA::ULong number_of_threads);
00210
00211
00212 TAO_Thread_Pool &pool_;
00213
00214
00215 CORBA::ULong const id_;
00216
00217 CORBA::Short lane_priority_;
00218
00219
00220
00221 bool shutdown_;
00222
00223
00224 CORBA::ULong const static_threads_number_;
00225
00226
00227 CORBA::ULong const dynamic_threads_number_;
00228
00229
00230 TAO_Thread_Pool_Threads static_threads_;
00231
00232
00233 TAO_Dynamic_Thread_Pool_Threads dynamic_threads_;
00234
00235 TAO_RT_New_Leader_Generator new_thread_generator_;
00236
00237 TAO_Thread_Lane_Resources resources_;
00238
00239 CORBA::Short native_priority_;
00240
00241 ACE_Time_Value const dynamic_thread_idle_timeout_;
00242
00243
00244 mutable ACE_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 ACE_Time_Value const &dynamic_thread_idle_timeout
00273 ACE_ENV_ARG_DECL);
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 ACE_Time_Value const &dynamic_thread_idle_timeout
00285 ACE_ENV_ARG_DECL);
00286
00287
00288 ~TAO_Thread_Pool (void);
00289
00290
00291 void open (ACE_ENV_SINGLE_ARG_DECL);
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
00331 private:
00332
00333 TAO_Thread_Pool_Manager &manager_;
00334 CORBA::ULong id_;
00335
00336 CORBA::ULong stack_size_;
00337 CORBA::Boolean allow_borrowing_;
00338 CORBA::Boolean allow_request_buffering_;
00339 CORBA::ULong max_buffered_requests_;
00340 CORBA::ULong max_request_buffer_size_;
00341 ACE_Time_Value const dynamic_thread_idle_timeout_;
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 ACE_Time_Value const &dynamic_thread_idle_timeout
00390 ACE_ENV_ARG_DECL)
00391 ACE_THROW_SPEC ((CORBA::SystemException));
00392
00393
00394 RTCORBA::ThreadpoolId
00395 create_threadpool_with_lanes (CORBA::ULong stacksize,
00396 const RTCORBA::ThreadpoolLanes & lanes,
00397 CORBA::Boolean allow_borrowing,
00398 CORBA::Boolean allow_request_buffering,
00399 CORBA::ULong max_buffered_requests,
00400 CORBA::ULong max_request_buffer_size,
00401 ACE_Time_Value const &dynamic_thread_idle_timeout
00402 ACE_ENV_ARG_DECL)
00403 ACE_THROW_SPEC ((CORBA::SystemException));
00404
00405
00406 void destroy_threadpool (RTCORBA::ThreadpoolId threadpool
00407 ACE_ENV_ARG_DECL)
00408 ACE_THROW_SPEC ((CORBA::SystemException,
00409 RTCORBA::RTORB::InvalidThreadpool));
00410
00411 TAO_Thread_Pool *get_threadpool (RTCORBA::ThreadpoolId thread_pool_id ACE_ENV_ARG_DECL);
00412
00413
00414 typedef ACE_Hash_Map_Manager<RTCORBA::ThreadpoolId, TAO_Thread_Pool *, ACE_Null_Mutex> THREAD_POOLS;
00415
00416
00417
00418
00419 TAO_ORB_Core &orb_core (void) const;
00420
00421
00422
00423 private:
00424
00425
00426
00427
00428 RTCORBA::ThreadpoolId
00429 create_threadpool_i (CORBA::ULong stacksize,
00430 CORBA::ULong static_threads,
00431 CORBA::ULong dynamic_threads,
00432 RTCORBA::Priority default_priority,
00433 CORBA::Boolean allow_request_buffering,
00434 CORBA::ULong max_buffered_requests,
00435 CORBA::ULong max_request_buffer_size,
00436 ACE_Time_Value const &dynamic_thread_idle_timeout
00437 ACE_ENV_ARG_DECL)
00438 ACE_THROW_SPEC ((CORBA::SystemException));
00439
00440 RTCORBA::ThreadpoolId
00441 create_threadpool_with_lanes_i (CORBA::ULong stacksize,
00442 const RTCORBA::ThreadpoolLanes & lanes,
00443 CORBA::Boolean allow_borrowing,
00444 CORBA::Boolean allow_request_buffering,
00445 CORBA::ULong max_buffered_requests,
00446 CORBA::ULong max_request_buffer_size,
00447 ACE_Time_Value const &dynamic_thread_idle_timeout
00448 ACE_ENV_ARG_DECL)
00449 ACE_THROW_SPEC ((CORBA::SystemException));
00450
00451 RTCORBA::ThreadpoolId
00452 create_threadpool_helper (TAO_Thread_Pool *thread_pool
00453 ACE_ENV_ARG_DECL)
00454 ACE_THROW_SPEC ((CORBA::SystemException));
00455
00456
00457
00458 private:
00459
00460 TAO_ORB_Core &orb_core_;
00461
00462 THREAD_POOLS thread_pools_;
00463 RTCORBA::ThreadpoolId thread_pool_id_counter_;
00464 ACE_SYNCH_MUTEX lock_;
00465 };
00466
00467 TAO_END_VERSIONED_NAMESPACE_DECL
00468
00469 #if defined (__ACE_INLINE__)
00470 #include "tao/RTCORBA/Thread_Pool.inl"
00471 #endif
00472
00473 #endif
00474
00475 #include "ace/post.h"
00476
00477 #endif