[glib/wip/free: 2/6] alternate version, freeing mutexes and stuff too
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/free: 2/6] alternate version, freeing mutexes and stuff too
- Date: Thu, 31 Oct 2013 15:33:46 +0000 (UTC)
commit 31fb060f6edbb311f573741f514986e284bd0805
Author: Dan Winship <danw gnome org>
Date: Tue Aug 28 16:27:02 2012 -0400
alternate version, freeing mutexes and stuff too
glib/gcharset.c | 1 +
glib/gdataset.c | 3 +++
glib/gdate.c | 1 +
glib/glib-init.c | 3 +++
glib/glib-init.h | 3 +++
glib/gmain.c | 4 ++++
glib/gmessages.c | 6 ++++++
glib/grand.c | 1 +
glib/gslice.c | 1 +
glib/gthread-posix.c | 36 ++++++++++++++++++++++++++++++++----
glib/gthread.c | 3 +++
glib/gtimezone.c | 1 +
glib/gutils.c | 4 ++++
glib/gvarianttypeinfo.c | 6 ++++++
glib/tests/cond.c | 12 +++++++++++-
glib/tests/mainloop.c | 6 ++++++
glib/tests/mutex.c | 6 ++++++
glib/tests/rec-mutex.c | 6 ++++++
glib/tests/rwlock.c | 15 +++++++++++++++
19 files changed, 113 insertions(+), 5 deletions(-)
---
diff --git a/glib/gcharset.c b/glib/gcharset.c
index 9326773..78ede0b 100644
--- a/glib/gcharset.c
+++ b/glib/gcharset.c
@@ -606,4 +606,5 @@ g_charset_cleanup (void)
#endif
g_private_replace (&charset_cache_private, NULL);
g_private_replace (&langnames_cache_private, NULL);
+ g_mutex_clear (&G_LOCK_NAME (aliases));
}
diff --git a/glib/gdataset.c b/glib/gdataset.c
index 83200c2..d7a9d95 100644
--- a/glib/gdataset.c
+++ b/glib/gdataset.c
@@ -1075,6 +1075,7 @@ g_dataset_cleanup (void)
{
g_clear_pointer (&g_dataset_location_ht, g_hash_table_unref);
g_dataset_cached = NULL;
+ g_mutex_clear (&G_LOCK_NAME (g_dataset_global));
}
/**
@@ -1326,6 +1327,8 @@ g_quark_cleanup (void)
g_slist_free_full (quark_blocks, g_free);
quark_blocks = NULL;
+
+ g_mutex_clear (&G_LOCK_NAME (g_quark_global));
}
/**
diff --git a/glib/gdate.c b/glib/gdate.c
index a734a4b..97c8e96 100644
--- a/glib/gdate.c
+++ b/glib/gdate.c
@@ -2561,4 +2561,5 @@ g_date_cleanup (void)
g_clear_pointer (&long_month_names[i], g_free);
}
g_clear_pointer (¤t_locale, g_free);
+ g_mutex_clear (&G_LOCK_NAME (g_date_global));
}
diff --git a/glib/glib-init.c b/glib/glib-init.c
index cb8a0dd..d5d8123 100644
--- a/glib/glib-init.c
+++ b/glib/glib-init.c
@@ -248,9 +248,12 @@ glib_cleanup (void)
g_rand_cleanup ();
g_time_zone_cleanup ();
g_utils_cleanup ();
+ g_variant_type_info_cleanup ();
+ g_messages_cleanup ();
g_threading_cleanup ();
g_slice_cleanup ();
+ g_system_thread_cleanup ();
}
#if defined (G_OS_WIN32)
diff --git a/glib/glib-init.h b/glib/glib-init.h
index b471f87..bcf23bd 100644
--- a/glib/glib-init.h
+++ b/glib/glib-init.h
@@ -42,12 +42,15 @@ G_GNUC_INTERNAL void g_convert_cleanup (void);
G_GNUC_INTERNAL void g_dataset_cleanup (void);
G_GNUC_INTERNAL void g_date_cleanup (void);
G_GNUC_INTERNAL void g_main_cleanup (void);
+G_GNUC_INTERNAL void g_messages_cleanup (void);
G_GNUC_INTERNAL void g_quark_cleanup (void);
G_GNUC_INTERNAL void g_rand_cleanup (void);
G_GNUC_INTERNAL void g_slice_cleanup (void);
+G_GNUC_INTERNAL void g_system_thread_cleanup (void);
G_GNUC_INTERNAL void g_test_cleanup (void);
G_GNUC_INTERNAL void g_threading_cleanup (void);
G_GNUC_INTERNAL void g_time_zone_cleanup (void);
G_GNUC_INTERNAL void g_utils_cleanup (void);
+G_GNUC_INTERNAL void g_variant_type_info_cleanup (void);
#endif /* __GLIB_INIT_H__ */
diff --git a/glib/gmain.c b/glib/gmain.c
index de943ff..7b83fc0 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -5082,4 +5082,8 @@ g_main_cleanup (void)
g_clear_pointer (&default_main_context, g_main_context_unref);
g_private_replace (&depth_private, NULL);
+
+ g_mutex_clear (&G_LOCK_NAME (main_loop));
+ g_mutex_clear (&G_LOCK_NAME (main_context_list));
+ g_mutex_clear (&G_LOCK_NAME (unix_signal_lock));
}
diff --git a/glib/gmessages.c b/glib/gmessages.c
index decda04..6d538e0 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -1545,3 +1545,9 @@ g_printf_string_upper_bound (const gchar *format,
gchar c;
return _g_vsnprintf (&c, 1, format, args) + 1;
}
+
+void
+g_messages_cleanup (void)
+{
+ g_mutex_clear (&g_messages_lock);
+}
diff --git a/glib/grand.c b/glib/grand.c
index f193253..81e8c2b 100644
--- a/glib/grand.c
+++ b/glib/grand.c
@@ -157,6 +157,7 @@ void
g_rand_cleanup (void)
{
g_clear_pointer (&global_random, g_rand_free);
+ g_mutex_clear (&G_LOCK_NAME (global_random));
}
struct _GRand
diff --git a/glib/gslice.c b/glib/gslice.c
index a102b67..c456712 100644
--- a/glib/gslice.c
+++ b/glib/gslice.c
@@ -1750,4 +1750,5 @@ g_slice_cleanup (void)
g_mutex_clear (&allocator->magazine_mutex);
g_mutex_clear (&allocator->slab_mutex);
+ g_mutex_clear (&init_mutex);
}
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index b38aaa5..bd48c6b 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -45,6 +45,7 @@
#include "gthreadprivate.h"
#include "gslice.h"
+#include "gmem.h"
#include "gmessages.h"
#include "gstrfuncs.h"
@@ -184,7 +185,8 @@ g_mutex_init (GMutex *mutex)
void
g_mutex_clear (GMutex *mutex)
{
- g_mutex_impl_free (mutex->p);
+ if (G_LIKELY (mutex->p != NULL))
+ g_mutex_impl_free (mutex->p);
}
/**
@@ -355,7 +357,8 @@ g_rec_mutex_init (GRecMutex *rec_mutex)
void
g_rec_mutex_clear (GRecMutex *rec_mutex)
{
- g_rec_mutex_impl_free (rec_mutex->p);
+ if (G_LIKELY (rec_mutex->p != NULL))
+ g_rec_mutex_impl_free (rec_mutex->p);
}
/**
@@ -512,7 +515,8 @@ g_rw_lock_init (GRWLock *rw_lock)
void
g_rw_lock_clear (GRWLock *rw_lock)
{
- g_rw_lock_impl_free (rw_lock->p);
+ if (G_LIKELY (rw_lock->p != NULL))
+ g_rw_lock_impl_free (rw_lock->p);
}
/**
@@ -716,7 +720,8 @@ g_cond_init (GCond *cond)
void
g_cond_clear (GCond *cond)
{
- g_cond_impl_free (cond->p);
+ if (G_LIKELY (cond->p != NULL))
+ g_cond_impl_free (cond->p);
}
/**
@@ -939,6 +944,9 @@ g_cond_wait_until (GCond *cond,
* Since: 2.32
**/
+static GPrivate **g_privates;
+static gint g_privates_len;
+
static pthread_key_t *
g_private_impl_new (GDestroyNotify notify)
{
@@ -979,6 +987,12 @@ g_private_get_impl (GPrivate *key)
g_private_impl_free (impl);
impl = key->p;
}
+
+ if G_UNLIKELY (g_mem_do_cleanup)
+ {
+ g_privates = realloc (g_privates, sizeof (GPrivate *) * (g_privates_len + 1));
+ g_privates[g_privates_len++] = key;
+ }
}
return impl;
@@ -1178,5 +1192,19 @@ g_system_thread_set_name (const gchar *name)
#endif
}
+void
+g_system_thread_cleanup (void)
+{
+ gint i;
+
+ if (g_privates)
+ {
+ for (i = 0; i < g_privates_len; i++)
+ g_private_impl_free (g_privates[i]->p);
+ free (g_privates);
+ g_privates = NULL;
+ }
+}
+
/* {{{1 Epilogue */
/* vim:set foldmethod=marker: */
diff --git a/glib/gthread.c b/glib/gthread.c
index 651388d..dd60abe 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -1014,6 +1014,9 @@ void
g_threading_cleanup (void)
{
g_private_replace (&g_thread_specific_private, NULL);
+ g_mutex_clear (&g_once_mutex);
+ g_cond_clear (&g_once_cond);
+ g_mutex_clear (&G_LOCK_NAME (g_thread_new));
}
/* Epilogue {{{1 */
diff --git a/glib/gtimezone.c b/glib/gtimezone.c
index 5b49d76..fa12dda 100644
--- a/glib/gtimezone.c
+++ b/glib/gtimezone.c
@@ -817,6 +817,7 @@ void
g_time_zone_cleanup (void)
{
g_clear_pointer (&time_zones, g_hash_table_unref);
+ g_mutex_clear (&G_LOCK_NAME (time_zones));
}
/* Epilogue {{{1 */
diff --git a/glib/gutils.c b/glib/gutils.c
index 95bc83d..c30b56f 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -972,6 +972,8 @@ g_get_any_cleanup (void)
g_clear_pointer (&g_user_special_dirs, g_free);
}
+
+ g_mutex_clear (&G_LOCK_NAME (g_utils_global));
}
/**
@@ -1844,7 +1846,9 @@ void
g_utils_cleanup (void)
{
g_clear_pointer (&g_prgname, g_free);
+ g_mutex_clear (&G_LOCK_NAME (g_prgname));
g_clear_pointer (&g_application_name, g_free);
+ g_mutex_clear (&G_LOCK_NAME (g_application_name));
g_get_any_cleanup ();
}
diff --git a/glib/gvarianttypeinfo.c b/glib/gvarianttypeinfo.c
index 7a76d27..2a9b975 100644
--- a/glib/gvarianttypeinfo.c
+++ b/glib/gvarianttypeinfo.c
@@ -867,3 +867,9 @@ g_variant_type_info_assert_no_infos (void)
{
g_assert (g_variant_type_info_table == NULL);
}
+
+void
+g_variant_type_info_cleanup (void)
+{
+ g_rec_mutex_clear (&g_variant_type_info_lock);
+}
diff --git a/glib/tests/cond.c b/glib/tests/cond.c
index 4046ab0..2b5f289 100644
--- a/glib/tests/cond.c
+++ b/glib/tests/cond.c
@@ -234,10 +234,20 @@ test_cond2 (void)
int
main (int argc, char *argv[])
{
+ int ret;
+
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/thread/cond1", test_cond1);
g_test_add_func ("/thread/cond2", test_cond2);
- return g_test_run ();
+ ret = g_test_run ();
+
+ if (g_mem_do_cleanup)
+ {
+ g_mutex_clear (&mutex);
+ g_cond_clear (&cond);
+ }
+
+ return ret;
}
diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c
index 3b78c65..373df64 100644
--- a/glib/tests/mainloop.c
+++ b/glib/tests/mainloop.c
@@ -344,6 +344,12 @@ test_invoke (void)
g_assert_cmpint (count, ==, 3);
g_main_context_unref (ctx);
+
+ if (g_mem_do_cleanup)
+ {
+ g_mutex_clear (&mutex);
+ g_cond_clear (&cond);
+ }
}
static gboolean
diff --git a/glib/tests/mutex.c b/glib/tests/mutex.c
index 3bd2e2f..ad7d57b 100644
--- a/glib/tests/mutex.c
+++ b/glib/tests/mutex.c
@@ -49,6 +49,9 @@ test_mutex2 (void)
g_mutex_unlock (&mutex);
g_mutex_lock (&mutex);
g_mutex_unlock (&mutex);
+
+ if (g_mem_do_cleanup)
+ g_mutex_clear (&mutex);
}
static void
@@ -78,6 +81,9 @@ test_mutex4 (void)
g_mutex_unlock (&mutex);
g_mutex_unlock (&mutex);
+
+ if (g_mem_do_cleanup)
+ g_mutex_clear (&mutex);
}
#define LOCKS 48
diff --git a/glib/tests/rec-mutex.c b/glib/tests/rec-mutex.c
index 95ac03f..caa53fc 100644
--- a/glib/tests/rec-mutex.c
+++ b/glib/tests/rec-mutex.c
@@ -49,6 +49,9 @@ test_rec_mutex2 (void)
g_rec_mutex_unlock (&mutex);
g_rec_mutex_lock (&mutex);
g_rec_mutex_unlock (&mutex);
+
+ if (g_mem_do_cleanup)
+ g_rec_mutex_clear (&mutex);
}
static void
@@ -65,6 +68,9 @@ test_rec_mutex3 (void)
g_rec_mutex_unlock (&mutex);
g_rec_mutex_unlock (&mutex);
+
+ if (g_mem_do_cleanup)
+ g_rec_mutex_clear (&mutex);
}
#define LOCKS 48
diff --git a/glib/tests/rwlock.c b/glib/tests/rwlock.c
index 658009d..9af021a 100644
--- a/glib/tests/rwlock.c
+++ b/glib/tests/rwlock.c
@@ -47,6 +47,9 @@ test_rwlock2 (void)
g_rw_lock_writer_unlock (&lock);
g_rw_lock_writer_lock (&lock);
g_rw_lock_writer_unlock (&lock);
+
+ if (g_mem_do_cleanup)
+ g_rw_lock_clear (&lock);
}
static void
@@ -61,6 +64,9 @@ test_rwlock3 (void)
g_assert (!ret);
g_rw_lock_writer_unlock (&lock);
+
+ if (g_mem_do_cleanup)
+ g_rw_lock_clear (&lock);
}
static void
@@ -72,6 +78,9 @@ test_rwlock4 (void)
g_rw_lock_reader_unlock (&lock);
g_rw_lock_reader_lock (&lock);
g_rw_lock_reader_unlock (&lock);
+
+ if (g_mem_do_cleanup)
+ g_rw_lock_clear (&lock);
}
static void
@@ -87,6 +96,9 @@ test_rwlock5 (void)
g_rw_lock_reader_unlock (&lock);
g_rw_lock_reader_unlock (&lock);
+
+ if (g_mem_do_cleanup)
+ g_rw_lock_clear (&lock);
}
static void
@@ -104,6 +116,9 @@ test_rwlock6 (void)
ret = g_rw_lock_writer_trylock (&lock);
g_assert (!ret);
g_rw_lock_reader_unlock (&lock);
+
+ if (g_mem_do_cleanup)
+ g_rw_lock_clear (&lock);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]