#define __no_sanitize_or_inline #define __no_kasan_or_inline #include #include #include #include #include // write(), read(), close(), sleep() int main(void) { struct hwspinlock *hwlock; // dynamically assign a hwspinlock without device tree usage hwlock = hwspin_lock_request(); if (!hwlock) { printf("Semaphore failed to create.\n"); } else { printf("Semaphore successfuly created.\n"); } int ret; while(1) { // take semaphore for 5 seconds (max), spin for 5 sec if it is already taken ret = hwspin_lock_timeout(hwlock, 5000); if (ret) { printf("Semaphore taken, and holding...\n"); } printf("3 ... seconds waiting..."); //wait for 3 seconds sleep(1); printf(" 2..."); sleep(1); printf(" 1...\n"); sleep(1); // release the lock hwspin_unlock(hwlock); // free the lock ret = hwspin_lock_free(hwlock); printf("Semaphore released."); printf("Waiting another 3 seconds.\n"); sleep(3); } return 0; }