network: fixed pthread compatible tls initialization
#define SOL_TCP IPPROTO_TCP
#endif
+static pthread_once_t local_thread_net_dns_ctx_init = PTHREAD_ONCE_INIT;
FLB_TLS_DEFINE(struct flb_net_dns, flb_net_dns_ctx);
-void flb_net_dns_ctx_init()
+/*
+ * Initialize thread-local-storage, every worker thread has it owns
+ * dns context with relevant info populated inside the thread.
+ */
+
+static void flb_net_dns_ctx_init_private()
{
FLB_TLS_INIT(flb_net_dns_ctx);
}
+void flb_net_dns_ctx_init()
+{
+ pthread_once(&local_thread_net_dns_ctx_init, flb_net_dns_ctx_init_private);
+}
+
struct flb_net_dns *flb_net_dns_ctx_get()
{
return FLB_TLS_GET(flb_net_dns_ctx);
