Loading...
Searching...
No Matches
api_lock.h
1#pragma once
2#include <furi/furi.h>
3
4/*
5Testing 10000 api calls
6
7No lock
8 Time diff: 445269.218750 us
9 Time per call: 44.526920 us
10
11furi_thread_flags
12 Time diff: 430279.875000 us // lol wtf? smaller than no lock?
13 Time per call: 43.027988 us // I tested it many times, it's always smaller
14
15FuriEventFlag
16 Time diff: 831523.625000 us
17 Time per call: 83.152359 us
18
19FuriSemaphore
20 Time diff: 999807.125000 us
21 Time per call: 99.980713 us
22
23FuriMutex
24 Time diff: 1071417.500000 us
25 Time per call: 107.141747 us
26*/
27
29
30#define API_LOCK_EVENT (1U << 0)
31
32#define api_lock_alloc_locked() furi_event_flag_alloc()
33
34#define api_lock_wait_unlock(_lock) \
35 furi_event_flag_wait(_lock, API_LOCK_EVENT, FuriFlagWaitAny, FuriWaitForever)
36
37#define api_lock_free(_lock) furi_event_flag_free(_lock)
38
39#define api_lock_unlock(_lock) furi_event_flag_set(_lock, API_LOCK_EVENT)
40
41#define api_lock_wait_unlock_and_free(_lock) \
42 api_lock_wait_unlock(_lock); \
43 api_lock_free(_lock);
44
45#define api_lock_is_locked(_lock) (!(furi_event_flag_get(_lock) & API_LOCK_EVENT))
46
47#define api_lock_relock(_lock) furi_event_flag_clear(_lock, API_LOCK_EVENT)
Definition event_flag.c:14