[apparmor] [PATCH 15/31] parser: Add support for atomic inc and dec
John Johansen
john.johansen at canonical.com
Tue Jan 27 18:12:16 UTC 2015
On 12/05/2014 04:22 PM, Tyler Hicks wrote:
> These operations will be used for grabbing and releasing references to
> objects. They leverage the GCC builtins for atomic operations.
>
> Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
Acked-by: John Johansen <john.johansen at canonical.com>
> ---
> parser/lib.c | 10 ++++++++++
> parser/lib.h | 3 +++
> 2 files changed, 13 insertions(+)
>
> diff --git a/parser/lib.c b/parser/lib.c
> index 602848c..37d0172 100644
> --- a/parser/lib.c
> +++ b/parser/lib.c
> @@ -57,6 +57,16 @@ void __autofclose(FILE **f)
> }
> }
>
> +void atomic_inc(unsigned int *v)
> +{
> + __sync_add_and_fetch(v, 1);
> +}
> +
> +bool atomic_dec_and_test(unsigned int *v)
> +{
> + return __sync_sub_and_fetch(v, 1) == 0;
> +}
> +
> /**
> * dirat_for_each: iterate over a directory calling cb for each entry
> * @dir: already opened directory (MAY BE NULL)
> diff --git a/parser/lib.h b/parser/lib.h
> index 4cdf428..bfe53f8 100644
> --- a/parser/lib.h
> +++ b/parser/lib.h
> @@ -10,6 +10,9 @@ void __autofree(void *p);
> void __autoclose(int *fd);
> void __autofclose(FILE **f);
>
> +void atomic_inc(unsigned int *v);
> +bool atomic_dec_and_test(unsigned int *v);
> +
> int dirat_for_each(DIR *dir, const char *name, void *data,
> int (* cb)(DIR *, const char *, struct stat *, void *));
>
>
More information about the AppArmor
mailing list