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 <tyhi...@canonical.com>
Acked-by: John Johansen <john.johan...@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 9dbc154..008027b 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 *));
 
-- 
2.1.4


-- 
AppArmor mailing list
AppArmor@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to