From: Matthias Clasen Date: Fri, 23 Sep 2011 10:31:12 +0000 (-0400) Subject: Add some more rw lock tests X-Git-Tag: 2.31.0~380 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=798a7d5abee46eb8b1ddb1c72ffa17a9cefc4ab0;p=platform%2Fupstream%2Fglib.git Add some more rw lock tests These test some simple mixed reader/writer api usage. --- 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 (); }