Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e941c9e2b8e7257be4b5163e9b036c9f9d8b3b7c
[simgrid.git] / include / xbt / threadpool.h
1 /* A thread pool.                                          */
2
3 /* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #ifndef _XBT_THREADPOOL_H
10 #define _XBT_THREADPOOL_H
11
12 #include "xbt/misc.h"           /* SG_BEGIN_DECL */
13 #include "xbt/function_types.h"
14
15 SG_BEGIN_DECL()
16
17 /** @addtogroup XBT_threadpool
18   * @brief Pool of threads.
19   *
20   * Jobs can be queued and the dispacher process can wait for the completion
21   * of all jobs.
22   * The call to "queue job" is non-blocking except the maximum amount of
23   * queued jobs is reached. In that case, it will block until a job is taken
24   * by a worker
25   * @{
26   */
27   /** \brief Queue data type (opaque type) */
28
29 typedef struct s_xbt_tpool *xbt_tpool_t;
30
31 XBT_PUBLIC(xbt_tpool_t) xbt_tpool_new(unsigned int num_workers,
32                                       unsigned int max_jobs);
33
34 XBT_PUBLIC(void) xbt_tpool_queue_job(xbt_tpool_t tpool, 
35                                      void_f_pvoid_t fun, 
36                                      void* fun_arg);
37
38 XBT_PUBLIC(void) xbt_tpool_wait_all(xbt_tpool_t tpool);
39
40 XBT_PUBLIC(void) xbt_tpool_destroy(xbt_tpool_t tpool);
41
42 /** @} */
43
44 SG_END_DECL()
45
46 #endif