[glib/wip/gcleanup: 5/10] GPrivate: add g_private_reset()
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gcleanup: 5/10] GPrivate: add g_private_reset()
- Date: Thu, 31 Oct 2013 09:17:39 +0000 (UTC)
commit be4ca9cc6c0cc7c26d80569677dc23ef862736c5
Author: Ryan Lortie <desrt desrt ca>
Date: Sun Mar 24 21:15:11 2013 -0400
GPrivate: add g_private_reset()
This frees the data in the TLS for the current thread.
glib/gthread-posix.c | 25 +++++++++++++++++++++++++
glib/gthread-win32.c | 12 ++++++++++++
glib/gthread.h | 2 ++
3 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index c7b68a0..a09b7a2 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -1070,6 +1070,31 @@ g_private_replace (GPrivate *key,
g_thread_abort (status, "pthread_setspecific");
}
+/**
+ * g_private_reset:
+ * @key: a #GPrivate
+ *
+ * Unsets the thread local variable @key to have the value @value in the
+ * current thread. If the previous value was non-%NULL then the
+ * #GDestroyNotify handler for @key is run on it.
+ *
+ * Since: 2.32
+ **/
+void
+g_private_reset (GPrivate *key)
+{
+ pthread_key_t *impl = g_private_get_impl (key);
+ gpointer old;
+ gint status;
+
+ old = pthread_getspecific (*impl);
+ if (old && key->notify)
+ key->notify (old);
+
+ if G_UNLIKELY ((status = pthread_setspecific (*impl, NULL)) != 0)
+ g_thread_abort (status, "pthread_setspecific");
+}
+
/* {{{1 GThread */
#define posix_check_err(err, name) G_STMT_START{ \
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index c54f2bd..58c0692 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -408,6 +408,18 @@ g_private_replace (GPrivate *key,
TlsSetValue (impl, value);
}
+void
+g_private_reset (GPrivate *key)
+{
+ DWORD impl = g_private_get_impl (key);
+ gpointer old;
+
+ old = TlsGetValue (impl);
+ if (old && key->notify)
+ key->notify (old);
+ TlsSetValue (impl, NULL);
+}
+
/* {{{1 GThread */
#define win32_check_for_error(what) G_STMT_START{ \
diff --git a/glib/gthread.h b/glib/gthread.h
index 43c7891..a4a0030 100644
--- a/glib/gthread.h
+++ b/glib/gthread.h
@@ -224,6 +224,8 @@ void g_private_set (GPrivate *key,
GLIB_AVAILABLE_IN_2_32
void g_private_replace (GPrivate *key,
gpointer value);
+GLIB_AVAILABLE_IN_2_36
+void g_private_reset (GPrivate *key);
GLIB_AVAILABLE_IN_ALL
gpointer g_once_impl (GOnce *once,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]