2009-04-23 19:23:13 +04:00
/*
* Unix SMB / CIFS implementation .
* threadpool implementation based on pthreads
2011-04-24 00:25:36 +04:00
* Copyright ( C ) Volker Lendecke 2009 , 2011
2009-04-23 19:23:13 +04:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef __PTHREADPOOL_H__
# define __PTHREADPOOL_H__
struct pthreadpool ;
2011-04-24 00:25:36 +04:00
/**
* @ defgroup pthreadpool The pthreadpool API
*
* This API provides a way to run threadsafe functions in a helper
* thread . It is initially intended to run getaddrinfo asynchronously .
*/
/**
* @ brief Create a pthreadpool
*
* A struct pthreadpool is the basis for for running threads in the
* background .
*
* @ param [ in ] max_threads Maximum parallelism in this pool
* @ param [ out ] presult Pointer to the threadpool returned
* @ return success : 0 , failure : errno
2011-04-25 22:05:31 +04:00
*
* max_threads = 0 means unlimited parallelism . The caller has to take
* care to not overload the system .
2011-04-24 00:25:36 +04:00
*/
2009-04-23 19:23:13 +04:00
int pthreadpool_init ( unsigned max_threads , struct pthreadpool * * presult ) ;
2011-04-24 00:25:36 +04:00
/**
* @ brief Destroy a pthreadpool
*
* Destroy a pthreadpool . If jobs are still active , this returns
* EBUSY .
*
* @ param [ in ] pool The pool to destroy
* @ return success : 0 , failure : errno
*/
2009-04-23 19:23:13 +04:00
int pthreadpool_destroy ( struct pthreadpool * pool ) ;
2011-04-24 00:25:36 +04:00
/**
* @ brief Add a job to a pthreadpool
*
* This adds a job to a pthreadpool . The job can be identified by
* job_id . This integer will be returned from
2014-03-24 14:39:56 +04:00
* pthreadpool_finished_jobs ( ) then the job is completed .
2011-04-24 00:25:36 +04:00
*
* @ param [ in ] pool The pool to run the job on
* @ param [ in ] job_id A custom identifier
* @ param [ in ] fn The function to run asynchronously
* @ param [ in ] private_data Pointer passed to fn
* @ return success : 0 , failure : errno
2009-04-23 19:23:13 +04:00
*/
int pthreadpool_add_job ( struct pthreadpool * pool , int job_id ,
void ( * fn ) ( void * private_data ) , void * private_data ) ;
2011-04-24 00:25:36 +04:00
/**
* @ brief Get the signalling fd from a pthreadpool
*
2012-01-19 15:10:38 +04:00
* Completion of a job is indicated by readability of the fd returned
2011-04-24 12:09:45 +04:00
* by pthreadpool_signal_fd ( ) .
2011-04-24 00:25:36 +04:00
*
* @ param [ in ] pool The pool in question
* @ return The fd to listen on for readability
2009-04-23 19:23:13 +04:00
*/
2011-04-24 12:09:45 +04:00
int pthreadpool_signal_fd ( struct pthreadpool * pool ) ;
2011-04-24 00:25:36 +04:00
/**
2014-03-24 14:39:56 +04:00
* @ brief Get the job_ids of finished jobs
2011-04-24 00:25:36 +04:00
*
* This blocks until a job has finished unless the fd returned by
2011-04-24 12:09:45 +04:00
* pthreadpool_signal_fd ( ) is readable .
2011-04-24 00:25:36 +04:00
*
* @ param [ in ] pool The pool to query for finished jobs
2014-03-24 14:39:56 +04:00
* @ param [ out ] jobids The job_ids of the finished job
* @ param [ int ] num_jobids The job_ids array size
* @ return success : > = 0 , number of finished jobs
* failure : - errno
2011-04-24 00:25:36 +04:00
*/
2014-03-24 14:39:56 +04:00
int pthreadpool_finished_jobs ( struct pthreadpool * pool , int * jobids ,
unsigned num_jobids ) ;
2009-04-23 19:23:13 +04:00
# endif