mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-30 20:33:08 +02:00
Add some more rw lock tests
These test some simple mixed reader/writer api usage.
This commit is contained in:
parent
81b3708184
commit
798a7d5abe
@ -63,6 +63,53 @@ test_rwlock3 (void)
|
|||||||
g_rw_lock_clear (&lock);
|
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
|
int
|
||||||
main (int argc, char *argv[])
|
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/rwlock1", test_rwlock1);
|
||||||
g_test_add_func ("/thread/rwlock2", test_rwlock2);
|
g_test_add_func ("/thread/rwlock2", test_rwlock2);
|
||||||
g_test_add_func ("/thread/rwlock3", test_rwlock3);
|
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 ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user