summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-09-20 01:06:27 +0200
committerGravatar Nikias Bassen2021-09-20 01:06:27 +0200
commit6cc8d697ad95ae3878051e9d81fe072ce047ddf5 (patch)
treee381bd9dcfc3a1c5019db664fedbf23ab1851a9c /src
parent156fa95b0cc02f40060e3635edee6ef500f89964 (diff)
downloadlibideviceactivation-6cc8d697ad95ae3878051e9d81fe072ce047ddf5.tar.gz
libideviceactivation-6cc8d697ad95ae3878051e9d81fe072ce047ddf5.tar.bz2
Check availability of constructor attribute and use it on Windows in favor of DllMain
Diffstat (limited to 'src')
-rw-r--r--src/activation.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/activation.c b/src/activation.c
index ab1c204..ff71ef2 100644
--- a/src/activation.c
+++ b/src/activation.c
@@ -101,7 +101,6 @@ static void internal_libideviceactivation_deinit(void)
}
#ifdef WIN32
-
typedef volatile struct {
LONG lock;
int state;
@@ -121,7 +120,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)) libideviceactivation_initialize(void)
+{
+ thread_once(&init_once, internal_libideviceactivation_init);
+}
+static void __attribute__((destructor)) libideviceactivation_deinitialize(void)
+{
+ thread_once(&deinit_once, internal_libideviceactivation_deinit);
+}
+#elif defined(WIN32)
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason) {
@@ -136,25 +157,10 @@ 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)) libideviceactivation_initialize(void)
-{
- pthread_once(&init_once, internal_libideviceactivation_init);
-}
-
-static void __attribute__((destructor)) libideviceactivation_deinitialize(void)
-{
- pthread_once(&deinit_once, internal_libideviceactivation_deinit);
-}
-
+#warning No compiler support for constructor/destructor attributes, some features might not be available.
#endif
-
static int debug_level = 0;
IDEVICE_ACTIVATION_API void idevice_activation_set_debug_level(int level) {