Thread portable class


Gate portable class


Timer class


Pool class


Terimber 2.0


About C++


Downloads Products & Services Support Clients Open Source About



Home / Open source / Terimber 2.0

threadpool Class Reference

defines implementation of thread pool multiple clients can borrow the threads with the same id More...

#include <threadpool.h>

Inheritance diagram for threadpool:

terimber_threadpool terimber_thread_employer terimber_log_helper terimber_log

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_infoqueue_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

maps thread ident to client info

Definition at line 73 of file threadpool.h.

node allocator for ident_info_node_t map

Definition at line 76 of file threadpool.h.

maps thread ident to client info

Definition at line 79 of file threadpool.h.

map user callback pointer to ident_info_map_t

Definition at line 82 of file threadpool.h.

list pf client thread info prepared for disposal

Definition at line 85 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 (  ) 

destructor

Definition at line 73 of file threadpool.cpp.

References off().


Member Function Documentation

bool threadpool::borrow_thread ( size_t  ident,
void *  data,
terimber_thread_employer client,
size_t  stay_on_alert_time_msec 
) [virtual]

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]

void threadpool::revoke_client ( terimber_thread_employer client  )  [virtual]

sometimes we need to stop calling client functions immideately however the client function calles already in progress should be completed

Parameters:
client  user callback

Implements terimber_threadpool.

Definition at line 523 of file threadpool.cpp.

References _clean_up_clients(), _clients_mtx, en_log_info, and terimber_log::format_logging().

Referenced by aiosock::off(), aiofile::off(), msg_communicator::shutdown_connection(), and msg_queue_processor::v_off().

bool threadpool::on (  ) 

bool threadpool::_validate_client ( size_t  ident,
terimber_thread_employer client,
client_info_map_t::iterator it_client,
ident_info_map_t::iterator it_info 
) [private]

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().

void threadpool::_clean_up_clients ( terimber_thread_employer client  )  [private]


Member Data Documentation

bool threadpool::_on [private]

flag on/off

Definition at line 153 of file threadpool.h.

Referenced by borrow_from_range(), borrow_thread(), off(), on(), v_do_job(), and v_has_job().

size_t threadpool::_capacity [private]

max thread pool capacity

Definition at line 154 of file threadpool.h.

Referenced by borrow_from_range(), borrow_thread(), and doxray().

size_t threadpool::_thread_in_use [private]

thread counter

Definition at line 155 of file threadpool.h.

Referenced by borrow_from_range(), borrow_thread(), doxray(), and v_do_job().

house keeping thread for disposal

Definition at line 156 of file threadpool.h.

Referenced by _clean_up_clients(), off(), and on().

disposal queue

Definition at line 158 of file threadpool.h.

Referenced by _clean_up_clients(), doxray(), off(), v_do_job(), and v_has_job().

deactivation time in milliseconds

Definition at line 162 of file threadpool.h.

Referenced by v_has_job().


The documentation for this class was generated from the following files:


© Copyright Terimber 2003-.