[glib] Add some more rw lock tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add some more rw lock tests
- Date: Fri, 23 Sep 2011 10:32:50 +0000 (UTC)
commit 798a7d5abee46eb8b1ddb1c72ffa17a9cefc4ab0
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Sep 23 06:31:12 2011 -0400
Add some more rw lock tests
These test some simple mixed reader/writer api usage.
glib/tests/rwlock.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/rwlock.c b/glib/tests/rwlock.c
index 95a1dd1..17869ca 100644
--- a/glib/tests/rwlock.c
+++ b/glib/tests/rwlock.c
@@ -63,6 +63,53 @@ test_rwlock3 (void)
g_rw_lock_clear (&lock);
}
+static void
+test_rwlock4 (void)
+{
+ GRWLock lock = G_RW_LOCK_INIT;
+
+ g_rw_lock_reader_lock (&lock);
+ g_rw_lock_reader_unlock (&lock);
+ g_rw_lock_reader_lock (&lock);
+ g_rw_lock_reader_unlock (&lock);
+ g_rw_lock_clear (&lock);
+}
+
+static void
+test_rwlock5 (void)
+{
+ GRWLock lock = G_RW_LOCK_INIT;
+ gboolean ret;
+
+ ret = g_rw_lock_reader_trylock (&lock);
+ g_assert (ret);
+ ret = g_rw_lock_reader_trylock (&lock);
+ g_assert (ret);
+
+ g_rw_lock_reader_unlock (&lock);
+ g_rw_lock_reader_unlock (&lock);
+
+ g_rw_lock_clear (&lock);
+}
+
+static void
+test_rwlock6 (void)
+{
+ GRWLock lock = G_RW_LOCK_INIT;
+ gboolean ret;
+
+ g_rw_lock_writer_lock (&lock);
+ ret = g_rw_lock_reader_trylock (&lock);
+ g_assert (!ret);
+ g_rw_lock_writer_unlock (&lock);
+
+ g_rw_lock_reader_lock (&lock);
+ ret = g_rw_lock_writer_trylock (&lock);
+ g_assert (!ret);
+ g_rw_lock_reader_unlock (&lock);
+
+ g_rw_lock_clear (&lock);
+}
int
main (int argc, char *argv[])
@@ -72,6 +119,9 @@ main (int argc, char *argv[])
g_test_add_func ("/thread/rwlock1", test_rwlock1);
g_test_add_func ("/thread/rwlock2", test_rwlock2);
g_test_add_func ("/thread/rwlock3", test_rwlock3);
+ g_test_add_func ("/thread/rwlock4", test_rwlock4);
+ g_test_add_func ("/thread/rwlock5", test_rwlock5);
+ g_test_add_func ("/thread/rwlock6", test_rwlock6);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]