aboutsummaryrefslogtreecommitdiff
path: root/lib/init.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2021-05-09 17:33:48 -0300
committerDavid Bremner <david@tethera.net>2021-05-13 22:21:57 -0300
commit8410be8e0867820c9814d06b49ff6da822d384a3 (patch)
tree7e5f132d32eba50b3688d37d96a9f685e1216209 /lib/init.cc
parenta34d7b41444ad2fb50cc7def25659c88d439780a (diff)
lib: make glib initialization thread-safe
In principle this could be done without depending on C++11 features, but these features should be available since gcc 4.8.1, and this localized usage is easy to replace if it turns out to be problematic for portability.
Diffstat (limited to 'lib/init.cc')
-rw-r--r--lib/init.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/init.cc b/lib/init.cc
new file mode 100644
index 00000000..cf29200f
--- /dev/null
+++ b/lib/init.cc
@@ -0,0 +1,21 @@
+#include "notmuch-private.h"
+
+#include <mutex>
+
+static void do_init ()
+{
+ /* Initialize the GLib type system and threads */
+#if ! GLIB_CHECK_VERSION (2, 35, 1)
+ g_type_init ();
+#endif
+
+ g_mime_init ();
+ _notmuch_filter_init ();
+}
+
+void
+_notmuch_init ()
+{
+ static std::once_flag initialized;
+ std::call_once (initialized, do_init);
+}