BUG/MEDIUM: threads: Run the poll loop on the main thread too
There was a flaw in the way the threads was created. the main one was just used
to create all the others and just wait to exit. Now, it is used to run a poll
loop. So we only create nbthread-1 threads.
This also fixes a bug about the compression filter when there is only 1 thread
(nbthread == 1 or no threads support). The bug was in the way thread-local
resources was initialized. per-thread init/deinit callbacks were never called
for the main process. So, with nthread set to 1, some buffers remained
uninitialized.
diff --git a/src/buffer.c b/src/buffer.c
index e892d1e..db2e053 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -83,19 +83,13 @@
pool_free2(pool2_buffer, buffer);
- if (global.nbthread > 1) {
- hap_register_per_thread_init(init_buffer_per_thread);
- hap_register_per_thread_deinit(deinit_buffer_per_thread);
- }
- else if (!init_buffer_per_thread())
- return 0;
-
+ hap_register_per_thread_init(init_buffer_per_thread);
+ hap_register_per_thread_deinit(deinit_buffer_per_thread);
return 1;
}
void deinit_buffer()
{
- deinit_buffer_per_thread();
pool_destroy2(pool2_buffer);
}