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

"Bryce W. Harrington" <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
LGTM

Reviewed-by: Bryce Harrington <[email protected]>

On Fri, Apr 11, 2014 at 10:48:08AM +0200, Uli Schlachter wrote:
> This moves the code for joining a thread into a helper function.
> 
> Signed-off-by: Uli Schlachter <[email protected]>
> ---
>  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
> 
> -- 
> cairo mailing list
> [email protected]
> http://lists.cairographics.org/mailman/listinfo/cairo
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.