Home / Open source / Terimber 2.0
threadpool Class Referencedefines implementation of thread pool multiple clients can borrow the threads with the same id
More...
#include <threadpool.h>
List of all members.
|
Public Member Functions |
| threadpool (size_t capacity, size_t deactivate_time_msec) |
| constructor
|
| ~threadpool () |
| destructor
|
virtual bool | borrow_thread (size_t ident, void *data, terimber_thread_employer *client, size_t stay_on_alert_time_msec) |
| user can call function even inside v_do_real_job function - see above
|
virtual bool | borrow_from_range (size_t from, size_t to, void *data, terimber_thread_employer *client, size_t stay_on_alert_time_msec) |
| user can ask for a little help and wake up any available thread in the provided range of idents
|
virtual void | revoke_client (terimber_thread_employer *client) |
| sometimes we need to stop calling client functions immideately however the client function calles already in progress should be completed
|
virtual void | doxray () |
| does xray
|
bool | on () |
| turns on
|
void | off () |
| turns off
|
Protected Member Functions |
virtual bool | v_has_job (size_t ident, void *user_data) |
| checks job
|
virtual void | v_do_job (size_t ident, void *user_data) |
| does job
|
Private Types |
typedef base_map< size_t,
client_thread_info > | ident_info_node_t |
| maps thread ident to client info
|
typedef node_allocator
< ident_info_node_t::_node > | ident_info_map_all_t |
| node allocator for ident_info_node_t map
|
typedef _map< size_t,
client_thread_info,
ident_info_map_all_t > | ident_info_map_t |
| maps thread ident to client info
|
typedef map
< terimber_thread_employer
*, ident_info_map_t > | client_info_map_t |
| map user callback pointer to ident_info_map_t
|
typedef list< client_thread_info > | queue_info_t |
| list pf client thread info prepared for disposal
|
Private Member Functions |
bool | _validate_client (size_t ident, terimber_thread_employer *client, client_info_map_t::iterator &it_client, ident_info_map_t::iterator &it_info) |
| validates the client callback pointer
|
void | _clean_up_clients (terimber_thread_employer *client) |
| disposes of all threads for the current user callback
|
Private Attributes |
bool | _on |
| flag on/off
|
size_t | _capacity |
| max thread pool capacity
|
size_t | _thread_in_use |
| thread counter
|
thread | _housekeeper |
| house keeping thread for disposal
|
thread_pool_t | _thread_pool |
| thread pool
|
queue_info_t | _dispose_queue |
| disposal queue
|
client_info_map_t | _clients_map |
| client map
|
ident_info_map_all_t | _map_allocator |
| map allocator
|
mutex | _clients_mtx |
| mutex
|
size_t | _deactivate_time_msec |
| deactivation time in milliseconds
|
Detailed Description
defines implementation of thread pool multiple clients can borrow the threads with the same id
Definition at line 68 of file threadpool.h.
Member Typedef Documentation
map user callback pointer to ident_info_map_t
Definition at line 82 of file threadpool.h.
Constructor & Destructor Documentation
BEGIN_TERIMBER_NAMESPACE threadpool::threadpool |
( |
size_t |
capacity, |
|
|
size_t |
deactivate_time_msec | |
|
) |
| | |
constructor
- Parameters:
-
capacity |
max capacity |
deactivate_time_msec |
deactivation interval in milliseconds |
Definition at line 64 of file threadpool.cpp.
threadpool::~threadpool |
( |
|
) |
|
Member Function Documentation
bool threadpool::borrow_thread |
( |
size_t |
ident, |
|
|
void * |
data, |
|
|
terimber_thread_employer * |
client, |
|
|
size_t |
stay_on_alert_time_msec | |
|
) |
| | [virtual] |
user can call function even inside v_do_real_job function - see above
- Parameters:
-
ident |
thread ident will be used as input parameter for client thread functions |
data |
user defined data will be used as input parameter for client thread functions |
client |
user callback |
stay_on_alert_time_msec |
time in milliseconds until unused thread will go back to the pool |
Implements terimber_threadpool.
Definition at line 297 of file threadpool.cpp.
References _capacity, _clients_map, _clients_mtx, _map_allocator, client_thread_info::_obj, _on, _thread_in_use, _thread_pool, _validate_client(), en_log_error, en_log_paranoid, map< K, T, Pr, M >::erase(), pair< T1, T2 >::first, terimber_log::format_logging(), map< K, T, Pr, M >::insert(), pool< C >::loan_object(), mutex_keeper::unlock(), and thread::wakeup().
Referenced by aiosock::_process_block(), aiofile::_process_block(), aiosock::complete_block(), aiofile::complete_block(), aiosock::on(), aiofile::on(), msg_user_connection::ping_notify(), msg_user_connection::process_income_message(), msg_user_connection::push_msg(), aiosock::v_do_job(), aiofile::v_do_job(), msg_user_connection::wakeup(), msg_connection::wakeup(), and msg_communicator::wakeup().
bool threadpool::borrow_from_range |
( |
size_t |
from, |
|
|
size_t |
to, |
|
|
void * |
data, |
|
|
terimber_thread_employer * |
client, |
|
|
size_t |
stay_on_alert_time_msec | |
|
) |
| | [virtual] |
user can ask for a little help and wake up any available thread in the provided range of idents
- Parameters:
-
from |
from ident |
to |
to ident |
data |
user defined data will be used as input parameter for client thread functions |
client |
user callback |
stay_on_alert_time_msec |
time in milliseconds until unused thread will go back to the pool |
Implements terimber_threadpool.
Definition at line 397 of file threadpool.cpp.
References _capacity, client_thread_info::_client, _clients_map, _clients_mtx, _map_allocator, client_thread_info::_obj, _on, _thread_in_use, _thread_pool, en_log_error, en_log_info, en_log_paranoid, map< K, T, Pr, M >::erase(), pair< T1, T2 >::first, terimber_log::format_logging(), map< K, T, Pr, M >::insert(), base_map< K, T, Pr, M >::const_iterator::key(), pool< C >::loan_object(), pair< T1, T2 >::second, THREAD_SLEEPING, mutex_keeper::unlock(), and thread::wakeup().
Referenced by aiosock::_process_block(), aiofile::_process_block(), aiosock::complete_block(), aiofile::complete_block(), msg_user_connection::process_income_message(), aiosock::v_do_job(), aiofile::v_do_job(), and msg_user_connection::wakeup().
void threadpool::doxray |
( |
|
) |
[virtual] |
does xray
Implements terimber_threadpool.
Definition at line 576 of file threadpool.cpp.
References _capacity, _clients_map, _clients_mtx, _dispose_queue, _thread_in_use, en_log_xray, terimber_log::format_logging(), list< T >::size(), base_map< K, T, Pr, M >::size(), and mutex_keeper::unlock().
Referenced by msg_communicator::doxray(), aiosock::doxray(), and aiofile::doxray().
turns off
Definition at line 96 of file threadpool.cpp.
References _clean_up_clients(), _clients_mtx, _dispose_queue, _housekeeper, client_thread_info::_obj, _on, _thread_pool, thread::cancel_job(), pool< C >::clear(), base_list< T >::empty(), en_log_info, terimber_log::format_logging(), base_list< T >::front(), mutex_keeper::lock(), list< T >::pop_front(), pool< C >::return_object(), thread::stop(), and mutex_keeper::unlock().
Referenced by aiosock::off(), aiofile::off(), msg_communicator::v_off(), and ~threadpool().
bool threadpool::v_has_job |
( |
size_t |
ident, |
|
|
void * |
user_data | |
|
) |
| | [protected, virtual] |
checks job
- Parameters:
-
ident |
thread ident |
user_data |
user defined data |
Implements terimber_thread_employer.
Definition at line 141 of file threadpool.cpp.
References client_thread_info::_client, _clients_map, _clients_mtx, client_thread_info::_data, _deactivate_time_msec, _dispose_queue, client_thread_info::_ident, _map_allocator, _on, _thread_pool, _validate_client(), pool< C >::deactivate(), base_list< T >::empty(), en_log_error, map< K, T, Pr, M >::erase(), terimber_log::format_logging(), mutex_keeper::lock(), list< T >::push_back(), mutex_keeper::unlock(), and terimber_thread_employer::v_has_job().
void threadpool::v_do_job |
( |
size_t |
ident, |
|
|
void * |
user_data | |
|
) |
| | [protected, virtual] |
does job
- Parameters:
-
ident |
thread ident |
user_data |
user defined data |
Implements terimber_thread_employer.
Definition at line 226 of file threadpool.cpp.
References client_thread_info::_client, _clients_mtx, client_thread_info::_data, _dispose_queue, client_thread_info::_ident, _on, _thread_in_use, _thread_pool, _validate_client(), base_list< T >::empty(), en_log_error, en_log_info, en_log_paranoid, terimber_log::format_logging(), base_list< T >::front(), list< T >::pop_front(), pool< C >::return_object(), mutex_keeper::unlock(), and terimber_thread_employer::v_do_job().
validates the client callback pointer
- Parameters:
-
ident |
thread ident |
client |
user callback pointer |
it_client |
correspondent iterator |
it_info |
found iterator |
Definition at line 289 of file threadpool.cpp.
References _clients_map, base_map< K, T, Pr, M >::end(), and base_map< K, T, Pr, M >::find().
Referenced by borrow_thread(), v_do_job(), and v_has_job().
disposes of all threads for the current user callback
- Parameters:
-
Definition at line 535 of file threadpool.cpp.
References _clients_map, _dispose_queue, _housekeeper, _map_allocator, base_map< K, T, Pr, M >::begin(), base_map< K, T, Pr, M >::empty(), base_map< K, T, Pr, M >::end(), map< K, T, Pr, M >::erase(), base_map< K, T, Pr, M >::find(), list< T >::push_back(), and thread::wakeup().
Referenced by off(), and revoke_client().
Member Data Documentation
The documentation for this class was generated from the following files:
|
|