Review Board 1.7.16


Add a serializer interface to the threadpool

Review Request #2323 - Created Feb. 8, 2013 and submitted

David Lee
/trunk
Reviewers
asterisk-dev
mmichelson
Asterisk
This patch adds the ability to create a serializer from a thread pool. A
serializer is a ast_taskprocessor with the same contract as a default
taskprocessor (tasks execute serially) except instead of executing out
of a dedicated thread, execution occurs in a thread from a
ast_threadpool. Think of it as a lightweight thread.

While it guarantees that each task will complete before executing the
next, there is no guarantee as to which thread from the pool individual
tasks will execute. This normally only matters if your code relys on
thread specific information, such as thread locals.

This patch also fixes a bug in how the 'was_empty' parameter is computed
for the push callback.
Unit testing.

Diff revision 2

This is not the most recent revision of the diff. The latest diff is revision 3. See what's changed.

1 2 3
1 2 3

  1. /trunk/include/asterisk/threadpool.h: Loading...
  2. /trunk/main/taskprocessor.c: Loading...
  3. /trunk/main/threadpool.c: Loading...
  4. /trunk/tests/test_taskprocessor.c: Loading...
  5. /trunk/tests/test_threadpool.c: Loading...
/trunk/include/asterisk/threadpool.h
Revision 381085 New Change
[20] 174 lines
[+20] [+] int ast_threadpool_push(struct ast_threadpool *pool, int (*task)(void *data), void *data);
175
 * \brief Shut down a threadpool and destroy it
175
 * \brief Shut down a threadpool and destroy it
176
 *
176
 *
177
 * \param pool The pool to shut down
177
 * \param pool The pool to shut down
178
 */
178
 */
179
void ast_threadpool_shutdown(struct ast_threadpool *pool);
179
void ast_threadpool_shutdown(struct ast_threadpool *pool);

    
   
180

   

    
   
181
/*!

    
   
182
 * \brief Serialized execution of tasks within a \ref ast_threadpool.

    
   
183
 *

    
   
184
 * \since 12.0.0

    
   
185
 *

    
   
186
 * A \ref ast_taskprocessor with the same contract as a default taskprocessor

    
   
187
 * (tasks execute serially) except instead of executing out of a dedicated

    
   
188
 * thread, execution occurs in a thread from a \ref ast_threadpool. Think of it

    
   
189
 * as a lightweight thread.

    
   
190
 *

    
   
191
 * While it guarantees that each task will complete before executing the next,

    
   
192
 * there is no guarantee as to which thread from the \c pool individual tasks

    
   
193
 * will execute. This normally only matters if your code relys on thread

    
   
194
 * specific information, such as thread locals.

    
   
195
 *

    
   
196
 * Use ast_taskprocessor_unreference() to dispose of the returned \ref

    
   
197
 * ast_taskprocessor.

    
   
198
 *

    
   
199
 * Only a single taskprocessor with a given name may exist. This function will fail

    
   
200
 * if a taskprocessor with the given name already exists.

    
   
201
 *

    
   
202
 * \param name Name of the serializer. (must be unique)

    
   
203
 * \param pool \ref ast_threadpool for execution.

    
   
204
 * \return \ref ast_taskprocessor for enqueuing work.

    
   
205
 * \return \c NULL on error.

    
   
206
 */

    
   
207
struct ast_taskprocessor *ast_threadpool_serializer(const char *name, struct ast_threadpool *pool);

    
   
208

   
180
#endif /* ASTERISK_THREADPOOL_H */
209
#endif /* ASTERISK_THREADPOOL_H */
/trunk/main/taskprocessor.c
Revision 381085 New Change
 
/trunk/main/threadpool.c
Revision 381085 New Change
 
/trunk/tests/test_taskprocessor.c
Revision 381085 New Change
 
/trunk/tests/test_threadpool.c
Revision 381085 New Change
 
  1. /trunk/include/asterisk/threadpool.h: Loading...
  2. /trunk/main/taskprocessor.c: Loading...
  3. /trunk/main/threadpool.c: Loading...
  4. /trunk/tests/test_taskprocessor.c: Loading...
  5. /trunk/tests/test_threadpool.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.