MINOR: initcall: use initcalls for most post_{check,deinit} and per_thread*

Most calls to hap_register_post_check(), hap_register_post_deinit(),
hap_register_per_thread_init(), hap_register_per_thread_deinit() can
be done using initcalls and will not require a constructor anymore.
Let's create a set of simplified macros for this, called respectively
REGISTER_POST_CHECK, REGISTER_POST_DEINIT, REGISTER_PER_THREAD_INIT,
and REGISTER_PER_THREAD_DEINIT.

Some files were not modified because they wouldn't benefit from this
or because they conditionally register (e.g. the pollers).
diff --git a/include/types/global.h b/include/types/global.h
index 85f5d25..74ebf14 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -251,6 +251,22 @@
 #define REGISTER_BUILD_OPTS(str) \
 	INITCALL2(STG_REGISTER, hap_register_build_opts, (str), 0)
 
+/* simplified way to declare a post-check callback in a file */
+#define REGISTER_POST_CHECK(fct) \
+	INITCALL1(STG_REGISTER, hap_register_post_check, (fct))
+
+/* simplified way to declare a post-deinit callback in a file */
+#define REGISTER_POST_DEINIT(fct) \
+	INITCALL1(STG_REGISTER, hap_register_post_deinit, (fct))
+
+/* simplified way to declare a per-thread init callback in a file */
+#define REGISTER_PER_THREAD_INIT(fct) \
+	INITCALL1(STG_REGISTER, hap_register_per_thread_init, (fct))
+
+/* simplified way to declare a per-thread deinit callback in a file */
+#define REGISTER_PER_THREAD_DEINIT(fct) \
+	INITCALL1(STG_REGISTER, hap_register_per_thread_deinit, (fct))
+
 #endif /* _TYPES_GLOBAL_H */
 
 /*
diff --git a/src/51d.c b/src/51d.c
index d709ec0..2a97867 100644
--- a/src/51d.c
+++ b/src/51d.c
@@ -687,11 +687,6 @@
 
 INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
 
-__attribute__((constructor))
-static void __51d_init(void)
-{
-	hap_register_post_check(init_51degrees);
-	hap_register_post_deinit(deinit_51degrees);
-}
-
+REGISTER_POST_CHECK(init_51degrees);
+REGISTER_POST_DEINIT(deinit_51degrees);
 REGISTER_BUILD_OPTS("Built with 51Degrees support.");
diff --git a/src/checks.c b/src/checks.c
index 5395093..55efb80 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -3517,12 +3517,11 @@
 __attribute__((constructor))
 static void __check_init(void)
 {
-	hap_register_post_check(start_checks);
-
 	pool_head_email_alert   = create_pool("email_alert",   sizeof(struct email_alert),   MEM_F_SHARED);
 	pool_head_tcpcheck_rule = create_pool("tcpcheck_rule", sizeof(struct tcpcheck_rule), MEM_F_SHARED);
 }
 
+REGISTER_POST_CHECK(start_checks);
 
 /*
  * Local variables:
diff --git a/src/chunk.c b/src/chunk.c
index 303d3fd..fa3fb71 100644
--- a/src/chunk.c
+++ b/src/chunk.c
@@ -92,10 +92,6 @@
 /* Initialize the trash buffers. It returns 0 if an error occurred. */
 int init_trash_buffers(int first)
 {
-	if (!first) {
-		hap_register_per_thread_init(init_trash_buffers_per_thread);
-		hap_register_per_thread_deinit(deinit_trash_buffers_per_thread);
-	}
 	pool_destroy(pool_head_trash);
 	pool_head_trash = create_pool("trash",
 				      sizeof(struct buffer) + global.tune.bufsize,
@@ -320,6 +316,9 @@
 	return diff;
 }
 
+REGISTER_PER_THREAD_INIT(init_trash_buffers_per_thread);
+REGISTER_PER_THREAD_DEINIT(deinit_trash_buffers_per_thread);
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff --git a/src/da.c b/src/da.c
index ee3d9af..61d6422 100644
--- a/src/da.c
+++ b/src/da.c
@@ -396,11 +396,6 @@
 
 INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
 
-__attribute__((constructor))
-static void __da_init(void)
-{
-	hap_register_post_check(init_deviceatlas);
-	hap_register_post_deinit(deinit_deviceatlas);
-}
-
+REGISTER_POST_CHECK(init_deviceatlas);
+REGISTER_POST_DEINIT(deinit_deviceatlas);
 REGISTER_BUILD_OPTS("Built with DeviceAtlas support.");
diff --git a/src/dns.c b/src/dns.c
index 2dfbdd5..255f15a 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -2060,5 +2060,6 @@
 	dns_resolution_pool  = create_pool("dns_resolution",  sizeof(struct dns_resolution),  MEM_F_SHARED);
 
 	cfg_register_postparser("dns runtime resolver", dns_finalize_config);
-	hap_register_post_deinit(dns_deinit);
 }
+
+REGISTER_POST_DEINIT(dns_deinit);
diff --git a/src/fd.c b/src/fd.c
index c467489..a787a09 100644
--- a/src/fd.c
+++ b/src/fd.c
@@ -526,8 +526,6 @@
 
 	fd_cache.first = fd_cache.last = -1;
 	update_list.first = update_list.last = -1;
-	hap_register_per_thread_init(init_pollers_per_thread);
-	hap_register_per_thread_deinit(deinit_pollers_per_thread);
 
 	for (p = 0; p < global.maxsock; p++) {
 		HA_SPIN_INIT(&fdtab[p].lock);
@@ -667,6 +665,9 @@
 	return 1;
 }
 
+REGISTER_PER_THREAD_INIT(init_pollers_per_thread);
+REGISTER_PER_THREAD_DEINIT(deinit_pollers_per_thread);
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff --git a/src/filters.c b/src/filters.c
index edce603..1c47256 100644
--- a/src/filters.c
+++ b/src/filters.c
@@ -1197,9 +1197,6 @@
 __filters_init(void)
 {
         pool_head_filter = create_pool("filter", sizeof(struct filter), MEM_F_SHARED);
-	hap_register_post_check(flt_init_all);
-	hap_register_per_thread_init(flt_init_all_per_thread);
-	hap_register_per_thread_deinit(flt_deinit_all_per_thread);
 }
 
 __attribute__((destructor))
@@ -1209,6 +1206,10 @@
 	pool_destroy(pool_head_filter);
 }
 
+REGISTER_POST_CHECK(flt_init_all);
+REGISTER_PER_THREAD_INIT(flt_init_all_per_thread);
+REGISTER_PER_THREAD_DEINIT(flt_deinit_all_per_thread);
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff --git a/src/log.c b/src/log.c
index 5c6b8df..77d58e2 100644
--- a/src/log.c
+++ b/src/log.c
@@ -2809,12 +2809,9 @@
 
 INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
 
-__attribute__((constructor))
-static void __log_init(void)
-{
-	hap_register_per_thread_init(init_log_buffers_per_thread);
-	hap_register_per_thread_deinit(deinit_log_buffers_per_thread);
-}
+REGISTER_PER_THREAD_INIT(init_log_buffers_per_thread);
+REGISTER_PER_THREAD_DEINIT(deinit_log_buffers_per_thread);
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff --git a/src/mux_h1.c b/src/mux_h1.c
index c9bfaa3..252395f 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -1835,10 +1835,12 @@
 __attribute__((constructor))
 static void __h1_init(void)
 {
-	hap_register_post_deinit(__h1_deinit);
 	pool_head_h1c = create_pool("h1c", sizeof(struct h1c), MEM_F_SHARED);
 	pool_head_h1s = create_pool("h1s", sizeof(struct h1s), MEM_F_SHARED);
 }
+
+REGISTER_POST_DEINIT(__h1_deinit);
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff --git a/src/mux_h2.c b/src/mux_h2.c
index c3cd1e1..e4005a2 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -3854,7 +3854,8 @@
 __attribute__((constructor))
 static void __h2_init(void)
 {
-	hap_register_post_deinit(__h2_deinit);
 	pool_head_h2c = create_pool("h2c", sizeof(struct h2c), MEM_F_SHARED);
 	pool_head_h2s = create_pool("h2s", sizeof(struct h2s), MEM_F_SHARED);
 }
+
+REGISTER_POST_DEINIT(__h2_deinit);
diff --git a/src/wurfl.c b/src/wurfl.c
index cd6abef..75dcf00 100644
--- a/src/wurfl.c
+++ b/src/wurfl.c
@@ -691,13 +691,6 @@
 
 INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
 
-__attribute__((constructor))
-static void __wurfl_init(void)
-{
-	hap_register_post_check(ha_wurfl_init);
-	hap_register_post_deinit(ha_wurfl_deinit);
-}
-
 // WURFL properties wrapper functions
 static const char *ha_wurfl_get_wurfl_root_id (wurfl_handle wHandle, wurfl_device_handle dHandle)
 {
@@ -802,4 +795,6 @@
 	return ((ha_wurfl_header_t *)wh)->header_value;
 }
 
+REGISTER_POST_CHECK(ha_wurfl_init);
+REGISTER_POST_DEINIT(ha_wurfl_deinit);
 REGISTER_BUILD_OPTS("Built with WURFL support.");