[cairo] [PATCH V3 1/4] cairo_rwlock: introduce rwlock.
Zhigang Gong
zhigang.gong at linux.intel.com
Wed May 30 02:05:29 PDT 2012
On Tue, May 29, 2012 at 11:13:48AM +0800, Zhigang Gong wrote:
>
> diff --git a/build/configure.ac.pthread b/build/configure.ac.pthread
> index 29c930d..72ed03a 100644
> --- a/build/configure.ac.pthread
> +++ b/build/configure.ac.pthread
> @@ -76,6 +76,19 @@ int test_mutex_attr (void)
> x |= pthread_mutex_destroy (&mutex);
> x |= pthread_mutexattr_destroy (&attr);
> return x;
> +}
> +
> +pthread_rwlock_t test_rwlock_initializer = PTHREAD_RWLOCK_INITIALIZER;
> +int test_rwlock (void)
> +{
> + int x = 0;
> + pthread_rwlock_t rwlock;
> + x |= pthread_rwlock_init(&rwlock, NULL);
> + x |= pthread_rwlock_wrlock(&rwlock);
> + x |= pthread_rwlock_unlock(&rwlock);
> + x |= pthread_rwlock_rdlock(&rwlock);
> + x |= pthread_rwlock_unlock(&rwlock);
> + x |= pthread_rwlock_destroy(&rwlock);
Should return a value here, otherwise it trigger a warning message during
autoconf phase. Some platform may treat warning as error, thus will cause
build problem here. Reported by SeongWon Cho.
+ return x;
> diff --git a/src/cairo-rwlock-impl-private.h b/src/cairo-rwlock-impl-private.h
> new file mode 100644
> index 0000000..53aa6c5
> --- /dev/null
> +++ b/src/cairo-rwlock-impl-private.h
> @@ -0,0 +1,90 @@
> +/* cairo - a vector graphics library with display and print output
> + *
> + * Copyright © 2002 University of Southern California
> + * Copyright © 2005,2007 Red Hat, Inc.
> + * Copyright © 2007 Mathias Hasselmann
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it either under the terms of the GNU Lesser General Public
> + * License version 2.1 as published by the Free Software Foundation
> + * (the "LGPL") or, at your option, under the terms of the Mozilla
> + * Public License Version 1.1 (the "MPL"). If you do not alter this
> + * notice, a recipient may use your version of this file under either
> + * the MPL or the LGPL.
> + *
> + * You should have received a copy of the LGPL along with this library
> + * in the file COPYING-LGPL-2.1; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
> + * You should have received a copy of the MPL along with this library
> + * in the file COPYING-MPL-1.1
> + *
> + * The contents of this file are subject to the Mozilla Public License
> + * Version 1.1 (the "License"); you may not use this file except in
> + * compliance with the License. You may obtain a copy of the License at
> + * http://www.mozilla.org/MPL/
> + *
> + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
> + * OF ANY KIND, either express or implied. See the LGPL or the MPL for
> + * the specific language governing rights and limitations.
> + *
> + * The Original Code is the cairo graphics library.
> + *
> + * The Initial Developer of the Original Code is University of Southern
> + * California.
> + *
> + * Contributor(s):
> + * Zhigang Gong <zhigang.gong at linux.intel.com>
> + */
> +
> +#ifndef CAIRO_RWLOCK_IMPL_PRIVATE_H
> +#define CAIRO_RWLOCK_IMPL_PRIVATE_H
> +#include "cairo.h"
> +
> +#if HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +/* And one that evaluates its argument once */
> +#define CAIRO_RWLOCK_IMPL_NOOP1(expr) do { (void)(expr); } while (0)
> +/* Note: 'if (expr) {}' is an alternative to '(void)(expr);' that will 'use' the
> + * result of __attribute__((warn_used_result)) functions. */
> +
> +#if CAIRO_NO_RWLOCK
> +
> +/* No rwlocks */
> +
> + typedef int cairo_rwlock_impl_t;
> +
> +# define CAIRO_RWLOCK_IMPL_NO 1
> +# define CAIRO_RWLOCK_IMPL_LOCK(rwlock) CAIRO_RWLOCK_IMPL_NOOP1(rwlock)
> +# define CAIRO_RWLOCK_IMPL_UNLOCK(rwlock) CAIRO_RWLOCK_IMPL_NOOP1(rwlock)
> +# define CAIRO_RWLOCK_IMPL_NIL_INITIALIZER 0
> +
> +#elif !CAIRO_HAS_PTHREAD /* use mutex as rwlock ********/
> +#include "cairo-mutex-private.h"
> + typedef cairo_mutex_t cairo_rwlock_impl_t;
> +
> +# define CAIRO_RWLOCK_IMPL_MUTEX 1
> +# define CAIRO_RWLOCK_IMPL_INIT(rwlock) CAIRO_MUTEX_INIT ((rwlock))
> +# define CAIRO_RWLOCK_IMPL_RDLOCK(rwlock) CAIRO_MUTEX_LOCK ((rwlock))
> +# define CAIRO_RWLOCK_IMPL_WRLOCK(rwlock) CAIRO_MUTEX_LOCK ((rwlock))
> +# define CAIRO_RWLOCK_IMPL_UNLOCK(rwlock) CAIRO_MUTEX_UNLOCK ((rwlock))
> +# define CAIRO_RWLOCK_IMPL_FINI(rwlock) CAIRO_MUTEX_FINI ((rwlock))
> +# define CAIRO_RWLOCK_IMPL_NIL_INITIALIZER CAIRO_MUTEX_NIL_INITIALIZER
> +
> +#elif CAIRO_HAS_PTHREAD /* and finally if there are no native rwlocks ********/
Fix the above comment as below, reported by Behdad Esfahbod, thx.
-#elif CAIRO_HAS_PTHREAD /* and finally if there are no native rwlocks ********/
+#elif CAIRO_HAS_PTHREAD /* and finally if there is pthread rwlocks ********/
More information about the cairo
mailing list