From d85f3aeeeefd6926fe71ec8e066adb74f62dc1cc Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Sat, 13 Jun 2020 21:05:45 +0100 Subject: fish --- app/i2c.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/i2c.c (limited to 'app/i2c.c') diff --git a/app/i2c.c b/app/i2c.c new file mode 100644 index 0000000..bf25256 --- /dev/null +++ b/app/i2c.c @@ -0,0 +1,20 @@ +static int mutex = 0; + +int +i2c_lock (void) +{ + if (__sync_add_and_fetch (&mutex, 1) != 1) + { + __sync_sub_and_fetch (&mutex, 1); + return -1; + } + + return 0; +} + + +void +i2c_unlock (void) +{ + __sync_sub_and_fetch (&mutex, 1); +} -- cgit v1.2.3