|
|
cp_pooled_thread is a thread that lives in a thread_pool. The struct holds synchronization elements used to control the thread and actuation settings, i.e. a thread function and a parameter to be passed for the next starting thread. The pool initializes a bunch of threads and sets them in 'wait'. When a client requests threads from the pool, the next available thread is signalled out of 'wait', and runs the thread function requested by the client (see cp_thread_pool_get_impl). When the client thread function is done, the cp_pooled_thread returns to the thread pool and becomes available to pool clients. The cp_pooled_thread only exits when the pool exits, unless explicitly stopped (eg pthread_exit) by client code. Referenced by cp_pooled_thread_run(), cp_thread_pool_create(), and cp_thread_pool_stop(). |
|
|
cp_pooled_thread_client_interface acts as the link to the cp_pooled_thread_scheduler for clients that require a variable number of threads. This interface holds 3 functions pointers that must be supplied by a client: Referenced by cp_pooled_thread_client_interface_create(), cp_pooled_thread_client_interface_destroy(), cp_pooled_thread_client_negociate(), and cp_pooled_thread_scheduler_register_client(). |
|
|
Definitions for thread management framework follow. The framework is based on the cp_thread_pool and cp_pooled_thread types.
|
|
|
cp_thread_pool holds a list of free threads (in wait mode). The list grows up to max_size, after which subsequent calls to cp_thread_pool_get will block, and calls to cp_thread_pool_get_nb will return NULL - until clients return their threads to the pool. Referenced by cp_thread_pool_create(). |
|
|
a stop function for client threads Definition at line 32 of file thread.h. Referenced by cp_pooled_thread_client_interface_create(). |
|
|
convenience to abstract cp_thread_pool based implementation, see cp_pooled_thread_get and cp_pooled_thread_get_nb Definition at line 550 of file thread.c. References _cp_pooled_thread_client_interface::count, and cp_thread_pool_get(). |
|
|
convenience to abstract cp_thread_pool based implementation, see cp_pooled_thread_get and cp_pooled_thread_get_nb Definition at line 544 of file thread.c. References _cp_pooled_thread_client_interface::count, and cp_thread_pool_get_nb(). |
|
|
convenience to abstract cp_thread_pool based implementation, see cp_pooled_thread_get and cp_pooled_thread_get_nb Definition at line 562 of file thread.c. References _cp_pooled_thread_client_interface::count, and cp_thread_pool_get_stoppable(). |
|
|
convenience to abstract cp_thread_pool based implementation, see cp_pooled_thread_get and cp_pooled_thread_get_nb Definition at line 556 of file thread.c. References _cp_pooled_thread_client_interface::count, and cp_thread_pool_get_stoppable_nb(). |
|
||||||||||||||||||||||||||||||||||||||||||||
|
cp_pooled_thread_client_interface constructor Definition at line 457 of file thread.c. References cp_fatal(), cp_pooled_thread_client_interface, cp_pooled_thread_scheduler_register_client(), cp_thread_action, cp_thread_stop_fn, and _cp_pooled_thread_client_interface::owner. |
|
|
cp_pooled_thread_client_interface destructor Definition at line 491 of file thread.c. References cp_pooled_thread_client_interface. |
|
|
threads should call negociate when a change in the number of threads a client owns is required. Two possible scheduling approaches are - (1) centralized: Clients report their load factor to the thread manager. The thread manager grants requests for new threads to clients with higher loads first. (2) distributed: clients negociate with other clients requesting a thread based on their load factors. The client with the lower load factor releases a thread to the client with the higher load factor. The distributed approach saves some bookkeeping over head in the thread manager, reduces the number steps involved in acquiring a new thread or releasing an unused one, and makes a dedicated synchronization thread unnecessary. In the current implementation, the scheduler will randomly choose one other client to negociate with. If the load factors are different enough, one thread will be switched to the busier client. Definition at line 618 of file thread.c. References _cp_pooled_thread_client_interface::count, cp_pooled_thread_client_interface, and cp_thread_pool_get_nb(). |
|
|
thread constructor function Referenced by cp_thread_pool_create(). |
|
|
thread destructor Definition at line 113 of file thread.c. Referenced by cp_pooled_thread_run(), and cp_thread_pool_create(). |
|
|
return a thread id for this thread |
|
|
framework thread function Definition at line 169 of file thread.c. References cp_pooled_thread, cp_pooled_thread_destroy(), and _cp_pooled_thread::wait. |
|
||||||||||||||||||||||||
|
perform action with stop function Definition at line 158 of file thread.c. References cp_pooled_thread_run_task(). |
|
||||||||||||||||
|
sets the action and prm for this thread, then invokes 'action' Definition at line 131 of file thread.c. References cp_error(). Referenced by cp_pooled_thread_run_stoppable_task(). |
|
|
cp_pooled_thread_scheduler constructor Definition at line 496 of file thread.c. References cp_pooled_thread_scheduler::client_list, cp_fatal(), and cp_pooled_thread_scheduler::pool. |
|
|
cp_pooled_thread_scheduler destructor Definition at line 515 of file thread.c. References cp_pooled_thread_scheduler::client_list. |
|
||||||||||||
|
register client as a client of this scheduler Definition at line 522 of file thread.c. References cp_pooled_thread_client_interface. Referenced by cp_pooled_thread_client_interface_create(). |
|
|
signal a thread to stop Definition at line 90 of file thread.c. Referenced by cp_thread_pool_stop(). |
|
|
returns the number of available threads in the pool. Definition at line 442 of file thread.c. References cp_list_item_count(). |
|
||||||||||||
|
cp_thread_pool constructor Definition at line 262 of file thread.c. References cp_destructor_fn, cp_error(), cp_fatal(), cp_hash_compare_long(), cp_hash_long(), cp_hashlist_create, cp_hashlist_destroy_custom(), cp_list_append(), cp_list_create(), cp_list_destroy_custom(), cp_pooled_thread, cp_pooled_thread_create(), cp_pooled_thread_destroy(), cp_thread_pool, _cp_thread_pool::free_pool, _cp_thread_pool::in_use, _cp_thread_pool::max_size, _cp_thread_pool::min_size, _cp_thread_pool::pool_cond, _cp_thread_pool::pool_lock, and _cp_thread_pool::running. Referenced by cp_httpclient_ctl_create(), and cp_socket_listen(). |
|
|
cp_thread_pool destructor Definition at line 420 of file thread.c. References cp_hashlist_destroy(), cp_list_destroy(), and cp_thread_pool_stop(). Referenced by cp_httpclient_ctl_destroy(), and cp_socket_delete(). |
|
||||||||||||||||
|
request a thread from the pool. If no threads are available, this function will block until a thread becomes available. Definition at line 388 of file thread.c. Referenced by cp_pooled_thread_client_get(). |
|
||||||||||||||||
|
request a thread from the pool - non-blocking version. Returns a pointer to the requested thread if one is available or NULL if the pool is empty. Definition at line 404 of file thread.c. Referenced by cp_pooled_thread_client_get_nb(), and cp_pooled_thread_client_negociate(). |
|
||||||||||||||||||||||||
|
request a thread from the pool. If no threads are available, this function will block until a thread becomes available. Definition at line 395 of file thread.c. Referenced by cp_pooled_thread_client_get_stoppable(). |
|
||||||||||||||||||||||||
|
request a thread from the pool - non-blocking version. Returns a pointer to the requested thread if one is available or NULL if the pool is empty. Definition at line 411 of file thread.c. Referenced by cp_pooled_thread_client_get_stoppable_nb(). |
|
|
signal all threads in this pool to stop Definition at line 241 of file thread.c. References COLLECTION_LOCK_READ, cp_hashlist_create_iterator(), cp_hashlist_iterator, cp_hashlist_iterator_destroy(), cp_hashlist_iterator_next_value(), cp_list_create_iterator(), cp_list_iterator, cp_list_iterator_next(), cp_pooled_thread, and cp_pooled_thread_stop(). Referenced by cp_httpclient_ctl_destroy(), cp_socket_delete(), and cp_thread_pool_destroy(). |
|
|
wait for threads to finish processing client requests Definition at line 225 of file thread.c. References cp_hashlist_item_count(). |
|
|
a thread function Definition at line 28 of file thread.h. Referenced by cp_pooled_thread_client_interface_create(). |
1.3.9.1