[cairo] [PATCH 1/3] pthread-same-source: Restructure code slightly

Uli Schlachter psychon at znc.in
Fri Apr 11 01:48:08 PDT 2014


This moves the code for joining a thread into a helper function.

Signed-off-by: Uli Schlachter <psychon at znc.in>
---
 test/pthread-same-source.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/test/pthread-same-source.c b/test/pthread-same-source.c
index d0eda4a..5960ca0 100644
--- a/test/pthread-same-source.c
+++ b/test/pthread-same-source.c
@@ -108,6 +108,25 @@ create_source (cairo_surface_t *similar)
 }
 
 static cairo_test_status_t
+join_thread (cairo_t *cr, pthread_t thread)
+{
+    void *surface;
+
+    if (pthread_equal (thread, pthread_self ()))
+	return CAIRO_TEST_SUCCESS;
+
+    if (pthread_join (thread, &surface) != 0)
+	return CAIRO_TEST_FAILURE;
+
+    cairo_set_source_surface (cr, surface, 0, 0);
+    cairo_surface_destroy (surface);
+    cairo_paint (cr);
+
+    cairo_translate (cr, 0, 4 * HEIGHT);
+    return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
 {
     pthread_t threads[N_THREADS];
@@ -146,20 +165,9 @@ draw (cairo_t *cr, int width, int height)
     cairo_paint (cr);
 
     for (i = 0; i < N_THREADS; i++) {
-	void *surface;
-
-        if (pthread_equal (threads[i], pthread_self ()))
-            break;
-
-        if (pthread_join (threads[i], &surface) == 0) {
-	    cairo_set_source_surface (cr, surface, 0, 0);
-	    cairo_surface_destroy (surface);
-	    cairo_paint (cr);
-
-	    cairo_translate (cr, 0, 4 * HEIGHT);
-	} else {
-            test_status = CAIRO_TEST_FAILURE;
-	}
+	cairo_test_status_t status = join_thread (cr, threads[i]);
+	if (status != CAIRO_TEST_SUCCESS)
+	    test_status = status;
     }
 
     return test_status;
-- 
1.9.1



More information about the cairo mailing list