[apparmor] [PATCH v2 16/42] parser: Add support for atomic inc and dec
Tyler Hicks
tyhicks at canonical.com
Fri Mar 6 21:48:32 UTC 2015
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 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
More information about the AppArmor
mailing list