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.

Changes between revision 2 and 3

1 2 3
1 2 3

  1. /trunk/main/threadpool.c: Loading...
/trunk/main/threadpool.c
Diff Revision 2 Diff Revision 3
[20] 863 lines
[+20] [+] struct ast_threadpool *ast_threadpool_create(const char *name,
864
	RAII_VAR(struct ast_threadpool *, pool, threadpool_alloc(name, options), ao2_cleanup);
864
	RAII_VAR(struct ast_threadpool *, pool, threadpool_alloc(name, options), ao2_cleanup);
865

    
   
865

   
866
	if (!pool) {
866
	if (!pool) {
867
		return NULL;
867
		return NULL;
868
	}
868
	}
869
	
869

   
870
	tps_listener = ast_taskprocessor_listener_alloc(&threadpool_tps_listener_callbacks, pool);
870
	tps_listener = ast_taskprocessor_listener_alloc(&threadpool_tps_listener_callbacks, pool);
871
	if (!tps_listener) {
871
	if (!tps_listener) {
872
		return NULL;
872
		return NULL;
873
	}
873
	}
874

    
   
874

   
[+20] [20] 233 lines
[+20] [+] struct serializer {
1108
};
1108
};
1109

    
   
1109

   
1110
static void serializer_dtor(void *obj)
1110
static void serializer_dtor(void *obj)
1111
{
1111
{
1112
	struct serializer *ser = obj;
1112
	struct serializer *ser = obj;

    
   
1113
	ao2_cleanup(ser->pool);
1113
	ser->pool = NULL;
1114
	ser->pool = NULL;
1114
}
1115
}
1115

    
   
1116

   
1116
static struct serializer *serializer_create(struct ast_threadpool *pool)
1117
static struct serializer *serializer_create(struct ast_threadpool *pool)
1117
{
1118
{
1118
	struct serializer *ser = ao2_alloc(sizeof(*ser), serializer_dtor);
1119
	struct serializer *ser = ao2_alloc(sizeof(*ser), serializer_dtor);
1119
	if (!ser) {
1120
	if (!ser) {
1120
		return NULL;
1121
		return NULL;
1121
	}
1122
	}

    
   
1123
	ao2_ref(pool, +1);
1122
	ser->pool = pool;
1124
	ser->pool = pool;
1123
	return ser;
1125
	return ser;
1124
}
1126
}
1125

    
   
1127

   
1126
static int execute_tasks(void *data)
1128
static int execute_tasks(void *data)
[+20] [20] 62 lines
  1. /trunk/main/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.