* Copyright 1998-2001 Sebastian Wilhelmi; University of Karlsruhe
* Copyright 2001 Hans Breuer
*
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
}
/* Ditto, due to the unlocked access on the fast path */
- if (!g_atomic_pointer_compare_and_exchange (&key->p, NULL, impl))
+ if (!g_atomic_pointer_compare_and_exchange (&key->p, NULL, GUINT_TO_POINTER (impl)))
g_thread_abort (0, "g_private_get_impl(2)");
}
LeaveCriticalSection (&g_private_lock);
void
g_system_thread_exit (void)
{
+ /* In static compilation, DllMain doesn't exist and so DLL_THREAD_DETACH
+ * case is never called and thread destroy notifications are not triggered.
+ * To ensure that notifications are correctly triggered in static
+ * compilation mode, we call directly the "detach" function here right
+ * before terminating the thread.
+ * As all win32 threads initialized through the glib API are run through
+ * the same proxy function g_thread_win32_proxy() which calls systematically
+ * g_system_thread_exit() when finishing, we obtain the same behavior as
+ * with dynamic compilation.
+ *
+ * WARNING: unfortunately this mechanism cannot work with threads created
+ * directly from the Windows API using CreateThread() or _beginthread/ex().
+ * It only works with threads created by using the glib API with
+ * g_system_thread_new(). If users need absolutely to use a thread NOT
+ * created with glib API under Windows and in static compilation mode, they
+ * should not use glib functions within their thread or they may encounter
+ * memory leaks when the thread finishes.
+ */
+#ifdef GLIB_STATIC_COMPILATION
+ g_thread_win32_thread_detach ();
+#endif
+
_endthreadex (0);
}
return 0;
}
-gboolean
-g_system_thread_get_scheduler_settings (GThreadSchedulerSettings *scheduler_settings)
-{
- HANDLE current_thread = GetCurrentThread ();
- scheduler_settings->thread_prio = GetThreadPriority (current_thread);
-
- return TRUE;
-}
-
GRealThread *
g_system_thread_new (GThreadFunc proxy,
gulong stack_size,
- const GThreadSchedulerSettings *scheduler_settings,
const char *name,
GThreadFunc func,
gpointer data,
* On Windows, by default all new threads are created with NORMAL thread
* priority.
*/
-
- if (scheduler_settings)
- {
- thread_prio = scheduler_settings->thread_prio;
- }
- else
- {
- HANDLE current_thread = GetCurrentThread ();
- thread_prio = GetThreadPriority (current_thread);
- }
+ {
+ HANDLE current_thread = GetCurrentThread ();
+ thread_prio = GetThreadPriority (current_thread);
+ }
if (thread_prio == THREAD_PRIORITY_ERROR_RETURN)
{
goto error;
}
- if (ResumeThread (thread->handle) == -1)
+ if (ResumeThread (thread->handle) == (DWORD) -1)
{
message = "Error resuming new thread";
goto error;
typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE hThread,
PCWSTR lpThreadDescription);
static pSetThreadDescription SetThreadDescriptionFunc = NULL;
-HMODULE kernel32_module = NULL;
+static HMODULE kernel32_module = NULL;
static gboolean
g_thread_win32_load_library (void)