The overhead of spinlok is less than mutext (mutex need to call
enter_critical section.)
After this patch, `down_write_trylock` and `down_read_trylock` can be
use in interrupt context.
The instruction is protected with mutex only one instruction so using
spinlock is better.
Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>
A new locking mechanism: read/write locks
When there is a writer it is not possible to put on a read lock or a write lock; when there is a reader it is possible to reenter the read lock but not the write lock.
Writers are exclusive locks, readers are shared locks.
At the same time through the waiter count to determine whether there is currently a blocked task, if there is then in the unlock time to wake up all the waiter, through the priority of the competition to complete the blocked lock execution.
For example:
When we have a reader blocking two waiter writers, when the reader is unlocked it wakes up both writers. The writer with higher priority wakes up and checks for a successful condition and locks the lock, the second writer wakes up and fails to check for a condition and continues to block the lock.
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>