api_lock.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include <furi/furi.h>
  3. /*
  4. Testing 10000 api calls
  5. No lock
  6. Time diff: 445269.218750 us
  7. Time per call: 44.526920 us
  8. furi_thread_flags
  9. Time diff: 430279.875000 us // lol wtf? smaller than no lock?
  10. Time per call: 43.027988 us // I tested it many times, it's always smaller
  11. FuriEventFlag
  12. Time diff: 831523.625000 us
  13. Time per call: 83.152359 us
  14. FuriSemaphore
  15. Time diff: 999807.125000 us
  16. Time per call: 99.980713 us
  17. FuriMutex
  18. Time diff: 1071417.500000 us
  19. Time per call: 107.141747 us
  20. */
  21. typedef FuriEventFlag* FuriApiLock;
  22. #define API_LOCK_EVENT (1U << 0)
  23. #define api_lock_alloc_locked() furi_event_flag_alloc()
  24. #define api_lock_wait_unlock(_lock) \
  25. furi_event_flag_wait(_lock, API_LOCK_EVENT, FuriFlagWaitAny, FuriWaitForever)
  26. #define api_lock_free(_lock) furi_event_flag_free(_lock)
  27. #define api_lock_unlock(_lock) furi_event_flag_set(_lock, API_LOCK_EVENT)
  28. #define api_lock_wait_unlock_and_free(_lock) \
  29. api_lock_wait_unlock(_lock); \
  30. api_lock_free(_lock);