summaryrefslogtreecommitdiff
path: root/glib/gthread-win32.c
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2020-11-20 14:55:03 +0000
committerPhilip Withnall <philip@tecnocode.co.uk>2020-11-20 14:55:03 +0000
commit936a07173a7a307c7b91de70437cdcb423b72a6d (patch)
treec45181680ac1a9e61bba457c0f828075c44c2439 /glib/gthread-win32.c
parent066e68001e0b4f4a186be9e181031125504e3a5e (diff)
parent83e48d8ac1fee98059e2305d8909dca26190bddc (diff)
downloadglib-936a07173a7a307c7b91de70437cdcb423b72a6d.tar.gz
Merge branch '600-drop-volatile' into 'master'
Drop use of volatile Closes #600 See merge request GNOME/glib!1719
Diffstat (limited to 'glib/gthread-win32.c')
-rw-r--r--glib/gthread-win32.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index 0c37dc6c1..20aca6fa1 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -301,7 +301,7 @@ struct _GPrivateDestructor
GPrivateDestructor *next;
};
-static GPrivateDestructor * volatile g_private_destructors;
+static GPrivateDestructor *g_private_destructors; /* (atomic) prepend-only */
static CRITICAL_SECTION g_private_lock;
static DWORD
@@ -329,7 +329,7 @@ g_private_get_impl (GPrivate *key)
g_thread_abort (errno, "malloc");
destructor->index = impl;
destructor->notify = key->notify;
- destructor->next = g_private_destructors;
+ destructor->next = g_atomic_pointer_get (&g_private_destructors);
/* We need to do an atomic store due to the unlocked
* access to the destructor list from the thread exit
@@ -337,13 +337,14 @@ g_private_get_impl (GPrivate *key)
*
* It can double as a sanity check...
*/
- if (InterlockedCompareExchangePointer (&g_private_destructors, destructor,
- destructor->next) != destructor->next)
+ if (!g_atomic_pointer_compare_and_exchange (&g_private_destructors,
+ destructor->next,
+ destructor))
g_thread_abort (0, "g_private_get_impl(1)");
}
/* Ditto, due to the unlocked access on the fast path */
- if (InterlockedCompareExchangePointer (&key->p, impl, NULL) != NULL)
+ if (!g_atomic_pointer_compare_and_exchange (&key->p, NULL, impl))
g_thread_abort (0, "g_private_get_impl(2)");
}
LeaveCriticalSection (&g_private_lock);
@@ -635,7 +636,7 @@ g_thread_win32_thread_detach (void)
*/
dtors_called = FALSE;
- for (dtor = g_private_destructors; dtor; dtor = dtor->next)
+ for (dtor = g_atomic_pointer_get (&g_private_destructors); dtor; dtor = dtor->next)
{
gpointer value;