summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Chalupa <mchqwerty@gmail.com>2014-08-29 11:21:29 +0200
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2014-09-04 15:47:04 +0300
commitaa49a79d7a1cf2b0c94f2b172b770dac05bd1c35 (patch)
tree9479812dcdce869d1f2ac75cdbf928e3c500b116
parentclient: add display_wakeup_threads function (diff)
downloadwayland-aa49a79d7a1cf2b0c94f2b172b770dac05bd1c35.tar
wayland-aa49a79d7a1cf2b0c94f2b172b770dac05bd1c35.tar.gz
wayland-aa49a79d7a1cf2b0c94f2b172b770dac05bd1c35.tar.bz2
wayland-aa49a79d7a1cf2b0c94f2b172b770dac05bd1c35.tar.lz
wayland-aa49a79d7a1cf2b0c94f2b172b770dac05bd1c35.tar.xz
wayland-aa49a79d7a1cf2b0c94f2b172b770dac05bd1c35.tar.zst
wayland-aa49a79d7a1cf2b0c94f2b172b770dac05bd1c35.zip
display-test: make use of create_thread function
This function is used in one test only, but its functionality can be used in another tests to (create thread and wait until it is sleeping). We just need to pass the starting function for the thread as an argument. Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
-rw-r--r--tests/display-test.c55
1 files changed, 26 insertions, 29 deletions
diff --git a/tests/display-test.c b/tests/display-test.c
index c420cbe..1289866 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -333,6 +333,28 @@ register_reading(struct wl_display *display)
assert(wl_display_flush(display) >= 0);
}
+/* create thread that will call prepare+read so that
+ * it will block */
+static pthread_t
+create_thread(struct client *c, void *(*func)(void*))
+{
+ pthread_t thread;
+
+ c->display_stopped = 0;
+ /* func must set display->stopped to 1 before sleeping */
+ assert(pthread_create(&thread, NULL, func, c) == 0);
+
+ /* make sure the thread is sleeping. It's a little bit racy
+ * (setting display_stopped to 1 and calling wl_display_read_events)
+ * so call usleep once again after the loop ends - it should
+ * be sufficient... */
+ while (c->display_stopped == 0)
+ usleep(500);
+ usleep(10000);
+
+ return thread;
+}
+
static void *
thread_read_error(void *data)
{
@@ -369,16 +391,7 @@ threading_post_err(void)
c->display_stopped = 0;
/* create new thread that will register its intention too */
- assert(pthread_create(&thread, NULL, thread_read_error, c) == 0);
-
- /* make sure thread is sleeping. It's a little bit racy
- * (setting display_stopped to 1 and calling wl_display_read_events)
- * so call usleep once again after the loop ends - it should
- * be sufficient... */
- while (c->display_stopped == 0)
- usleep(500);
-
- usleep(10000);
+ thread = create_thread(c, thread_read_error);
/* so now we have sleeping thread waiting for a pthread_cond signal.
* The main thread must call wl_display_read_events().
@@ -429,22 +442,6 @@ thread_prepare_and_read(void *data)
pthread_exit(NULL);
}
-static pthread_t
-create_thread(struct client *c)
-{
- pthread_t thread;
-
- c->display_stopped = 0;
- assert(pthread_create(&thread, NULL, thread_prepare_and_read, c) == 0);
-
- /* make sure thread is sleeping */
- while (c->display_stopped == 0)
- usleep(500);
- usleep(10000);
-
- return thread;
-}
-
/* test cancel read*/
static void
threading_cancel_read(void)
@@ -454,9 +451,9 @@ threading_cancel_read(void)
register_reading(c->wl_display);
- th1 = create_thread(c);
- th2 = create_thread(c);
- th3 = create_thread(c);
+ th1 = create_thread(c, thread_prepare_and_read);
+ th2 = create_thread(c, thread_prepare_and_read);
+ th3 = create_thread(c, thread_prepare_and_read);
/* all the threads are sleeping, waiting until read or cancel
* is called. Cancel the read and let the threads proceed */