[sr-dev] rtpengine, proposal for threads according to number of cpus

Frederic-Philippe Metz frederic.metz at 1und1.de
Thu Oct 23 10:17:56 CEST 2014


Hi all,

I saw in the code (master branch) that 
'thread_create_detach(poller_loop, ctx.p);' in main() is executed 4 
times. I propose to create as many threads as cpus.

Patch below.

Cheers,
   Frédéric



diff --git a/daemon/main.c b/daemon/main.c
index 449db08..50e197c 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -625,6 +625,7 @@ static void poller_loop(void *d) {

  int main(int argc, char **argv) {
  	struct main_context ctx;
+	int idx=0, numCPU=0;

  	options(&argc, &argv);
  	init_everything();
@@ -634,10 +635,12 @@ int main(int argc, char **argv) {

  	thread_create_detach(sighandler, NULL);
  	thread_create_detach(timer_loop, ctx.p);
-	thread_create_detach(poller_loop, ctx.p);
-	thread_create_detach(poller_loop, ctx.p);
-	thread_create_detach(poller_loop, ctx.p);
-	thread_create_detach(poller_loop, ctx.p);
+
+	numCPU = sysconf( _SC_NPROCESSORS_ONLN );
+
+	for (;idx<numCPU;++idx) {
+	    thread_create_detach(poller_loop, ctx.p);
+	}

  	while (!global_shutdown) {
  		usleep(100000);



More information about the sr-dev mailing list