#include "project.h" 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); }