On 3/30/2023 1:57 AM, 奇诺 wrote:
Hi, all:
I submitted a PR regarding mutex, the changes are as follows: 1. Move some
mutex operations to sched;2. Add mutex_clocklock, mutex_set_protocol, and
mutex_get_protocol interfaces;3. Remove cancellation point operations in mutex
because it is not a cancellation point.
As I recall in Linux, mutex logic is mostly implemented user space using
atomic test-and-set logic to take the mutex. The OS is only involved if
there is a failure to take the mutex. That greatly reduces the number
of system calls which are very expensive in KERNEL and PROTECTED modes.
In addition, there will be a series of modifications based on this PR in the
future.
1. pthread mutex is changed to depend on nxmutex instead of nxsem;
2. nxmutex no longer depends on nxsem and is implemented independently;
The mutex was originally based on counting semaphores to keep the size
down, rather than duplicating the logic.
3. Move priority inheritance from nxsem to nxmutex, and optimize the
performance of priority inheritance;
That will break every a lot of people's code. There is probably a lot
of application logic that depends on priority inheritance working on
counting semaphores. Removing that will problems for a lot of people.
This is, however, consistent with how Linux works.
If there are any issues with this modification, please inform me, thanks!
PR: https://github.com/apache/nuttx/pull/8645
BR