lib: sbi: Replace test-and-set locks by ticket locks
authorChristoph Muellner <cmuellner@linux.com>
Tue, 6 Apr 2021 01:53:54 +0000 (03:53 +0200)
committerAnup Patel <anup@brainfault.org>
Fri, 9 Apr 2021 13:18:50 +0000 (18:48 +0530)
commit4d8e2f135d659697337f8d4a33fec60cd475f0dc
tree9f1bd8ef91f5b6a52123db13b5f80437e62ba197
parentd0e406fa44a108210d29b26281777206961cd772
lib: sbi: Replace test-and-set locks by ticket locks

Replace the test-and-set spinlock implementation with ticket locks
in order to get fairness (in form of FIFO order).

The implementation uses a 32-bit wide struct, which consists of
two 16-bit counters (owner and next). This is inspired by similar
spinlock implementations on other architectures.
This allows that the code works for both, RV32 and RV64.

Signed-off-by: Christoph Muellner <cmuellner@linux.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
include/sbi/riscv_locks.h
lib/sbi/riscv_locks.c