summaryrefslogtreecommitdiffstats
path: root/src/plist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-09-13 18:41:59 +0200
committerGravatar Nikias Bassen2021-09-13 18:41:59 +0200
commit677b0c03f8fca937f6b16da3341602637d092179 (patch)
tree7a653c83ed13835081b2a556c18a0e325a706bc7 /src/plist.c
parent68f1d4a136fca04665a209f2a215b27bee377003 (diff)
downloadlibplist-677b0c03f8fca937f6b16da3341602637d092179.tar.gz
libplist-677b0c03f8fca937f6b16da3341602637d092179.tar.bz2
Check availability of constructor attribute and use it on Windows in favor of DllMain
Diffstat (limited to 'src/plist.c')
-rw-r--r--src/plist.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/plist.c b/src/plist.c
index 454d08c..d0e6c77 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -63,7 +63,6 @@ static void internal_plist_deinit(void)
}
#ifdef WIN32
-
typedef volatile struct {
LONG lock;
int state;
@@ -83,7 +82,29 @@ static void thread_once(thread_once_t *once_control, void (*init_routine)(void))
}
InterlockedExchange(&(once_control->lock), 0);
}
+#else
+static pthread_once_t init_once = PTHREAD_ONCE_INIT;
+static pthread_once_t deinit_once = PTHREAD_ONCE_INIT;
+#define thread_once pthread_once
+#endif
+
+#ifndef HAVE_ATTRIBUTE_CONSTRUCTOR
+ #if defined(__llvm__) || defined(__GNUC__)
+ #define HAVE_ATTRIBUTE_CONSTRUCTOR
+ #endif
+#endif
+
+#ifdef HAVE_ATTRIBUTE_CONSTRUCTOR
+static void __attribute__((constructor)) libplist_initialize(void)
+{
+ thread_once(&init_once, internal_plist_init);
+}
+static void __attribute__((destructor)) libplist_deinitialize(void)
+{
+ thread_once(&deinit_once, internal_plist_deinit);
+}
+#elif defined(WIN32)
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason) {
@@ -98,22 +119,8 @@ BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved)
}
return 1;
}
-
#else
-
-static pthread_once_t init_once = PTHREAD_ONCE_INIT;
-static pthread_once_t deinit_once = PTHREAD_ONCE_INIT;
-
-static void __attribute__((constructor)) libplist_initialize(void)
-{
- pthread_once(&init_once, internal_plist_init);
-}
-
-static void __attribute__((destructor)) libplist_deinitialize(void)
-{
- pthread_once(&deinit_once, internal_plist_deinit);
-}
-
+#warning No compiler support for constructor/destructor attributes, some features might not be available.
#endif
#ifndef HAVE_MEMMEM