A configurable read-write priority strategy read-write lock implementation method of an MMU-free embedded real-time operating system
By employing a configurable read-write priority strategy in an MMU-less embedded real-time operating system, the problems of excessive memory usage, writer starvation, and priority inversion are solved, a lightweight read-write lock is implemented, and the real-time performance and stability of the system are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HUNAN BOJIANG INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2026-05-27
- Publication Date
- 2026-07-07
AI Technical Summary
Existing read-write lock schemes are not compatible with embedded real-time operating systems without a memory management unit (MMU), leading to problems such as excessive memory usage, writer starvation, and priority inversion.
It adopts a configurable read-write priority strategy, and implements a lightweight read-write lock through strategy binding at creation time, interrupt-free atomic operation, starvation elimination in write-priority mode, priority inheritance, dual wait queue design, static memory pool and single-field tri-state encoding, which is suitable for environments without MMU.
It implements a lightweight read-write lock in MMU-free embedded systems, supports flexible configuration, reduces memory consumption, avoids writer starvation and priority inversion, and improves system real-time performance and stability.
Smart Images

Figure CN122346366A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of synchronization primitives in embedded real-time operating systems, specifically to a method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system. Background Technology
[0002] In embedded real-time operating system applications without a memory management unit (MMU), read-write locks serve as the core synchronization primitives for ensuring concurrent access to shared resources by multiple tasks. Current mainstream implementations fall into three categories: First, the `rw_semaphore` read-write semaphore in Linux systems, implemented based on hardware exclusive access instructions and spinlock mechanisms, is a mature read-write lock solution in general-purpose systems; second, the `pthread_rwlock_t` read-write lock in commercial real-time operating systems such as QNX and VxWorks, relying on dynamic memory allocation and memory mapping mechanisms and adapting to the POSIX standard interface; and third, simulated read-write locks in lightweight embedded systems such as FreeRTOS, which encapsulate basic read-write synchronization functions using binary semaphores to meet the simple synchronization needs of low-end embedded devices. The aforementioned existing read-write lock solutions all have technical flaws that make them unsuitable for embedded microcontroller (MCU) scenarios without an MMU: Linuxrw_semaphore relies on dedicated hardware instructions and MMU process context switching, and its memory consumption far exceeds the RAM capacity of low-end MCUs, making it completely unportable; QNX and VxWorks read-write locks rely on dynamic memory allocation and MMU memory mapping, and priority inheritance only supports mutex locks, which cannot meet the hard real-time requirements of read-write locks. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention provides a configurable read-write priority strategy read-write lock implementation method for an MMU-less embedded real-time operating system, thus solving the problems mentioned in the background section.
[0004] To achieve the above objectives, the present invention provides the following technical solution: a method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system, comprising the following steps: S1. Read-write lock creation phase execution strategy binding: When creating the lock, select the read-first or write-first working strategy and solidify the strategy into a fixed field of the lock control block. All subsequent lock operations directly read this field, without runtime strategy switching overhead. S2. Atomic operations are achieved by disabling interrupts: multiple variable modifications to lock state count, waiting queue, holder information, and priority parameters are all guaranteed to be atomic by disabling interrupts → executing the modification → restoring interrupts, without the need for LDREX / STREX hardware instructions or MMU process context support. S3. Actively eliminate writer starvation in write priority mode: When the lock is a write priority strategy and there are waiting tasks in the write waiting queue, regardless of whether the current lock is idle or held by a reader, new read lock requests are blocked and new readers are added to the read waiting queue. S4. Priority inheritance is performed when a write lock is requested: When a high-priority task requests a write lock, if the lock is held by a low-priority task, the priority of the holder is automatically raised to the priority of the current task. When the write lock is released, the original priority of the holder is automatically restored to avoid priority inversion. S5. Adopt a dual waiting queue separation design: set up a reader waiting queue and a writer waiting queue independently. When the lock is released, the corresponding queue task is directly woken up according to the binding strategy. There is no need to traverse the queue. The time complexity of the wake-up operation is O(1). S6. Employs a static memory pool with zero dynamic allocation: The lock control block is stored through a pre-allocated static array, and the POSIX interface is encapsulated by handle index mapping. No malloc dynamic memory allocation is performed throughout the process. It is a pure physical address operation with no MMU dependency. S7. Use a single-field three-state encoding to mark the lock state: use a 32-bit signed number to represent the three states of the lock, greater than 0 means the reader holds the lock, equal to 0 means the lock is free, and equal to -1 means the writer holds the lock exclusively, replacing the two-field storage scheme and reducing memory usage.
[0005] Furthermore, in step S1, read-write lock instances with read-first and write-first strategies can be created and run simultaneously within the same embedded real-time operating system. The different instance strategies are independent of each other and do not interfere with each other.
[0006] Furthermore, in step S2, the interrupt disable operation will shield PendSV, SysTick and external interrupts to ensure that there is no task switching or interruption during the execution of the critical section, which is compatible with core chips of Cortex-M0 and Cortex-M0+ that do not have exclusive access instructions.
[0007] Furthermore, in step S3, the hunger elimination logic of the write priority strategy does not rely on a timeout mechanism or add any additional state fields, and directly blocks the path of writer hunger from the read lock application entry.
[0008] Furthermore, in step S4, priority inheritance only applies to write lock holders, and read lock holders do not trigger priority promotion operations; priority promotion and restoration are both automatically completed by the locking mechanism, and are completely transparent to upper-layer application tasks.
[0009] Furthermore, in step S5, the wake-up rule of the write priority strategy is: after the lock is released, the first task in the write waiting queue is woken up first, and when there are no write waiting tasks, all tasks in the read waiting queue are woken up in batches; the wake-up rule of the read priority strategy is: the first task in the write waiting queue is woken up only when the lock is completely idle, and completely idle is the state when there are no readers and no writers.
[0010] Furthermore, in step S6, the lock control block size is 32 bytes in a 32-bit system and 48 bytes in a 64-bit system; the size of the static memory pool is determined during system compilation, and only allocation and reclamation are performed during runtime; The POSIX wrapper layer ensures the security of lock operations and prevents illegal pointer access through triple verification: magic number verification, handle validity verification, and control block state verification.
[0011] Furthermore, in step S7, the lock state determination only requires a single numerical comparison, eliminating the need for multi-field reading and logical combination, thus shortening the critical section execution time and improving system real-time performance.
[0012] Furthermore, the lock supports recursive holding detection. When the same task repeatedly requests a write lock, a deadlock error is returned directly to avoid the task getting stuck.
[0013] This invention provides a configurable read-write priority strategy read-write lock implementation method for an MMU-less embedded real-time operating system, which has the following advantages: 1. This method for implementing a configurable read / write priority strategy read / write lock in an MMU-less embedded real-time operating system achieves a lightweight, configurable read / write lock by employing techniques such as creation-time strategy binding, interrupt-disabling atomic operations, proactive write starvation elimination, writer priority inheritance, dual-queue separate wake-up, single-field tri-state encoding, and static memory zero allocation. It supports flexible configuration of read / write priority strategies with zero runtime switching overhead, requires no dedicated hardware instructions or MMU context support, and is perfectly compatible with low-end MCUs such as Cortex-M0 / M0+ that lack exclusive access capabilities.
[0014] 2. The configurable read-write priority strategy read-write lock implementation method of the MMU-free embedded real-time operating system can block writer starvation from the source in write priority mode. Combined with the writer priority inheritance mechanism, it can effectively avoid priority inversion and reduce the waiting time of high-priority writers to the microsecond level, fully guaranteeing the hard real-time performance of the system. The independent read and write dual queues realize O(1) time complexity wake-up, with no queue traversal overhead and higher cache efficiency. The 32-byte compact control block and single-field tri-state encoding greatly reduce memory occupation. The static pool + POSIX encapsulation realizes zero dynamic memory allocation and pure physical address operation throughout the process. Attached Figure Description
[0015] Figure 1This is a flowchart illustrating the steps of a configurable read-write priority strategy read-write lock implementation method for an MMU-less embedded real-time operating system according to the present invention. Detailed Implementation
[0016] The embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and should not be construed as limiting the scope of the invention.
[0017] like Figure 1 As shown, the present invention provides a technical solution: a method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system, comprising the following steps: S1. Read-write lock creation phase execution strategy binding: When creating the lock, select the read-first or write-first working strategy and solidify the strategy into a fixed field of the lock control block. All subsequent lock operations directly read this field, without runtime strategy switching overhead. Within the same embedded real-time operating system, read-write lock instances with both read-first and write-first strategies can be created and run simultaneously. The different instance strategies are independent of each other and do not interfere with each other. S2. Atomic operations are achieved by disabling interrupts: multiple complex modifications to lock state count, wait queue, holder information, and priority parameters are all guaranteed to be atomic through the process of disabling interrupts → executing the modification → restoring interrupts. No LDREX / STREX hardware instructions or MMU process context support are required. In particular, the interrupt-disabling operation will shield PendSV, SysTick and external interrupts, ensuring that there is no task switching or interruption during the execution of the critical section, and is compatible with Cortex-M0 and Cortex-M0+ core chips without exclusive access instructions. S3. Actively eliminate writer starvation in write priority mode: When the lock is a write priority strategy and there are waiting tasks in the write waiting queue, regardless of whether the current lock is idle or held by a reader, new read lock requests are blocked and new readers are added to the read waiting queue; and the starvation elimination logic of the write priority strategy does not rely on the timeout mechanism or add any additional state fields, directly blocking the formation path of writer starvation from the read lock request entry point. S4. Priority inheritance is performed when a write lock is requested: When a high-priority task requests a write lock, if the lock is held by a low-priority task, the priority of the holder is automatically increased to the priority of the current task. When the write lock is released, the original priority of the holder is automatically restored to avoid priority inversion. Priority inheritance only applies to the write lock holder; the read lock holder does not trigger the priority increase operation. Priority increase and restoration are both completed automatically by the lock mechanism and are completely transparent to the upper-layer application tasks. S5. Adopt a dual waiting queue separation design: set up a reader waiting queue and a writer waiting queue independently. When the lock is released, the corresponding queue task is directly woken up according to the binding strategy. There is no need to traverse the queue. The time complexity of the wake-up operation is O(1). The wake-up rule for the write priority strategy is: after the lock is released, the first task in the write waiting queue is woken up first; when there are no write waiting tasks, all tasks in the read waiting queue are woken up in batches. The wake-up rule for the read priority strategy is: the first task in the write waiting queue is woken up only when the lock is completely idle; completely idle means the state of having no readers and no writers. S6. Employs a static memory pool with zero dynamic allocation: The lock control block is stored through a pre-allocated static array, and the POSIX interface is encapsulated by handle index mapping. No malloc dynamic memory allocation is performed throughout the process. It is a pure physical address operation with no MMU dependency. The lock control block size is 32 bytes in a 32-bit system and 48 bytes in a 64-bit system; the size of the static memory pool is determined at compile time and only allocation and deallocation are performed at runtime; the POSIX wrapper layer uses magic number verification, handle validity verification, and control block state verification to ensure the security of lock operations and prevent illegal pointer access. S7. Single-field three-state encoding is used to mark the lock state: a 32-bit signed number is used to represent the three states of the lock, greater than 0 means the reader holds the lock, equal to 0 means the lock is free, and equal to -1 means the writer holds the lock exclusively. This replaces the two-field storage scheme and reduces memory usage. Lock state judgment can be completed with only one numerical comparison, without the need for multi-field reading and logical combination, which shortens the execution time of the critical section and improves the real-time performance of the system. In the above steps, the lock supports recursive holding detection. When the same task repeatedly requests a write lock, a deadlock error is returned directly to avoid the task getting stuck.
[0018] Example 1: Definition of Read-Write Lock Control Block and Core Data Structure; This example is based on a 32-bit embedded processor and defines a 32-byte compact read-write lock control block LosRwlockCB. The field layout and functions are as follows: rwlockStat (1 byte, offset 0x00): Lock usage status, 0 = not created, 1 = created; policy (1 byte, offset 0x01): Scheduling policy, 0 = read priority, 1 = write priority; magic (2 bytes, offset 0x02): Check magic number, fixed at 0xEEDD, used for validity verification; rwCount (4 bytes, offset 0x04): Tri-state lock state count, >0 = reader holds, =0 = idle, =-1 = writer holds; rwlockID (4 bytes, offset 0x08): Static memory pool array index, used as the lock handle; owner (4 bytes, offset 0x0C): Pointer to the write lock holder's task control block; ownerPriority (2 bytes, offset 0x10): Writes the original priority of the owner; padding (2 bytes, offset 0x12): Memory alignment padding; readList (8 bytes, offset 0x14): Reader two-way wait queue (prev + next pointers); writeList (8 bytes, offset 0x1C): Writer's two-way wait queue (prev + next pointers).
[0019] Three-state encoding rule: The state marker is implemented using a single INT32 type variable rwCount, which replaces the traditional two-field scheme of "reader count" and "writer flag", saving 4 bytes of memory. The state judgment only requires one comparison operation. Example 2: Detailed process of read-write lock creation and policy binding; This example fully implements the entire process of read-write lock creation, policy fixation, and static memory allocation: Interface call and policy determination: The application layer calls the LOS_RwlockCreateWithPolicy interface, passing in the policy parameters (RWLOCK_POLICY_READ_PRIORITY / RWLOCK_POLICY_WRITE_PRIORITY); inter-process shared locks are set to write priority by default, and intra-process locks are set to read priority by default; Static memory pool allocation: Search for a free index item in the system's pre-allocated static array g_rwlockPool, allocate 32 bytes of control block space, without malloc operation; Control block initialization: (1) Set rwlockStat to 1 (already created) and magic to 0xEEDD; (2) Write the input policy value into the policy field to complete the policy solidification; (3) Set rwCount to 0 (lock is free), set owner to NULL, and set ownerPriority to 0; (4) Call the linked list initialization interface to initialize the readList and writeList queues; POSIX structure encapsulation: Fill with an 8-byte pthread_rwlock_t structure, write the magic number 0xABCD1234, and store the static pool index as a handle; Return lock handle: Returns the allocated index value as the lock handle. Once created, all subsequent operations directly read the policy field, with no runtime configuration overhead.
[0020] Example 3: Detailed implementation process of interrupt-disabled atomic operations; This example implements multivariable atomic operations without MMU and without hardware exclusive instructions, which is the foundation of all lock operations: Entering the critical section: Call the IntLock() function, execute the MRSR0, PRIMASK, and CPSIDI instructions, save the current interrupt state, and disable PendSV, SysTick, and all external interrupts; Modification of composite variables: Under interrupt protection disabled, any combination of rwCount, readList, writeList, owner, and ownerPriority variables can be modified synchronously, ensuring atomicity of the operation and no interference from task switching or interruption. Exit the critical section: Call the IntRestore() function, execute the MSR PRIMASK,R0 instruction to restore the original interrupt state, and enable task switching and interrupt response; Compatibility Notes: This process does not require LDREX / STREX instructions and is perfectly compatible with kernels such as Cortex-M0 / M0+ that do not have exclusive access capabilities.
[0021] Example 4: Detailed Process of Read Lock Acquisition and Write Starvation Elimination; This example fully implements read lock acquisition, focusing on the starvation elimination logic in write-priority mode: Pre-check: Check that the lock pointer is not null, magic=0xEEDD, and the current context is not interrupted; if the check is invalid, return an error directly. Disable interrupts before entering the critical section: Execute IntLock() to save the interrupt state; Strategy and queue judgment: (1) If policy=1 (write priority) and writeList is not empty (there are write tasks waiting), execute step S4; (2) If the above conditions are not met, proceed to step S5; Starvation elimination process: (1) Insert the current task's pendList node at the end of readList; (2) Set the current task status to blocked (OS_TASK_STATUS_PEND); (3) Exit the critical section, trigger task scheduling, the current task relinquishes the CPU and waits to be woken up; Normal read lock acquisition: Increment rwCount by 1 to mark it as held by the reader; Exiting the critical section: IntRestore() is executed to recover from the interrupt, and the read lock acquisition is successful; Example 5: Detailed process of read lock release; This example implements read lock release and wake-up scheduling triggering: Pre-check: Check that the lock pointer is valid and rwCount > 0 (indicating that a reader holds the lock); return an error if the check is invalid. Disable interrupts before entering the critical section: Execute IntLock() to save the interrupt state; Update lock state: Decrement rwCount by 1 to reduce the number of readers holding the lock. Wake-up determination: If rwCount=0 (the last reader released the lock), call the OsRwlockWake() function to wake up waiting tasks according to the strategy; Exiting the critical section: IntRestore() is executed to restore the interrupted read lock, and the read lock is released.
[0022] Example 6: Detailed Process of Write Lock Request and Priority Inheritance; This example implements the entire process of write lock request, recursive detection, and priority inheritance: Pre-check: Check that the lock pointer is valid, the magic code matches, and the context is not interrupted; return an error if the check is invalid. Disable interrupts before entering the critical section: Execute IntLock() to save the interrupt state; Lock status determination: (1) If rwCount=0 (lock is free): set rwCount=-1, owner=current task pointer, exit the critical section, and acquire the lock successfully; (2) If rwCount = -1 and owner = current task: return deadlock error and prohibit recursive lock holding; (3) If the lock is occupied by another task: execute step S4; Priority inheritance handling: (1) Obtain the priority of the current task and the owner task; (2) If the owner priority is greater than the current task priority: save the owner's original priority to ownerPriority, and call OsSchedModifyTaskSchedParam() to raise the owner's priority to the current task priority; Blocking wait: Insert the current task's pendList node at the end of writeList and set the task status to blocked; Exit the critical section: Execute IntRestore() to recover from the interrupt, trigger task scheduling, and wait for the write lock to be released and wake up.
[0023] Example 7: Detailed Process of Write Lock Release and Priority Recovery; This example implements write lock release, automatic priority recovery, and wake-up scheduling: Pre-check: Check that the lock pointer is valid, rwCount=-1, and owner=current task; only the holder can release the lock. Disable interrupts before entering the critical section: Execute IntLock() to save the interrupt state; Priority restoration: If the current priority of the owner is not equal to the ownerPriority, call OsSchedModifyTaskSchedParam() to restore the owner priority to its original value; Reset lock state: Set rwCount=0 (idle), owner=NULL, and clear the holder information; Wake-up scheduling: Call the OsRwlockWake() function to wake up read or write waiting queue tasks according to the binding strategy; Exiting the critical section: IntRestore() is executed to recover from the interrupt, and the write lock is released.
[0024] Example 8: Detailed process of dual-strategy wake-up scheduling; This example implements the wake-up logic for both write-first and read-first strategies, ensuring O(1) time complexity: Write-first strategy wake-up: (1) Check that writeList is not empty: take out the write task at the head of the queue, call OsSchedTaskWake() to wake up, and wake up only 1 writer; (2) When writeList is empty: Iterate through readList, wake up all reader tasks in batches, and increment rwCount after each reader is woken up; Read-first strategy wake-up: (1) Check that writeList is not empty only when rwCount = 0 (completely idle); (2) Wake up the first write task at the head of the writeList queue. Do not wake up the writer if a reader holds the lock.
[0025] Example 9: Detailed process of POSIX zero dynamic allocation encapsulation; This example implements POSIX standard interface adaptation without MMU and without dynamic memory: Application layer calls: The application calls the pthread_rwlock_rdlock / wrlock / unlock standard interface; Triple validity checks: (1) Verify that the pthread_rwlock_t pointer is not null and that magic=0xABCD1234; (2) Verify that the handle is within the static pool index range (0~RWLOCK_MAX_NUM); (3) Verify that g_rwlockPool[handle] has rwlockStat=1 and magic=0xEEDD; Control block mapping: Using handle as the index, directly access the g_rwlockPool static array to obtain the LosRwlockCB control block in O(1) time; Kernel operation execution: Based on the control block, read or write lock acquisition, release, and destruction are performed. There is no dynamic memory allocation or virtual address mapping throughout the process; it is purely physical address operation.
[0026] In summary, this method for implementing a configurable read / write priority strategy read / write lock in an MMU-less embedded real-time operating system achieves a lightweight, configurable read / write lock by employing techniques such as creation-time strategy binding, interrupt-disabling atomic operations, proactive write starvation elimination, writer priority inheritance, dual-queue separate wake-up, single-field tri-state encoding, and static memory zero allocation. It supports flexible configuration of read / write priority strategies with zero runtime switching overhead, requires no dedicated hardware instructions or MMU context support, and is perfectly compatible with low-end MCUs such as Cortex-M0 / M0+ that lack exclusive access capabilities. The write-first mode can block writer starvation from the source. Combined with the writer priority inheritance mechanism, it can effectively avoid priority inversion and reduce the waiting time of high-priority writers to the microsecond level, fully guaranteeing the hard real-time performance of the system. The independent read and write dual queues realize O(1) time complexity wake-up, with no queue traversal overhead and higher cache efficiency. The 32-byte compact control block and single-field tri-state encoding greatly reduce memory usage. The static pool + POSIX encapsulation realizes zero dynamic memory allocation and pure physical address operation throughout the process. The overall solution has the advantages of strong policy adaptability, high real-time performance, small memory footprint, good portability, and stable and reliable operation. It completely solves the technical defects of traditional read-write locks in embedded scenarios without MMU, such as inability to be ported, memory over-limit, writer starvation, priority inversion, and uncontrollable wake-up delay.
[0027] The embodiments of the present invention are given for illustrative and descriptive purposes only, and are not intended to be exhaustive or to limit the invention to the forms disclosed. Many modifications and variations will be apparent to those skilled in the art. The embodiments were chosen and described in order to better illustrate the principles and practical application of the invention, and to enable those skilled in the art to understand the invention and to design various embodiments with various modifications suitable for a particular purpose.
Claims
1. A method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system, characterized in that: Includes the following steps: S1. Read-write lock creation phase execution strategy binding: When creating the lock, select the read-first or write-first working strategy and solidify the strategy into a fixed field of the lock control block. All subsequent lock operations directly read this field, without runtime strategy switching overhead. S2. Atomic operations are achieved by disabling interrupts: multiple variable modifications to lock state count, waiting queue, holder information, and priority parameters are all guaranteed to be atomic by disabling interrupts → executing the modification → restoring interrupts, without the need for LDREX / STREX hardware instructions or MMU process context support. S3. Actively eliminate writer starvation in write priority mode: When the lock is a write priority strategy and there are waiting tasks in the write waiting queue, regardless of whether the current lock is idle or held by a reader, new read lock requests are blocked and new readers are added to the read waiting queue. S4. Priority inheritance is performed when a write lock is requested: When a high-priority task requests a write lock, if the lock is held by a low-priority task, the priority of the holder is automatically raised to the priority of the current task. When the write lock is released, the original priority of the holder is automatically restored to avoid priority inversion. S5. Adopt a dual waiting queue separation design: set up a reader waiting queue and a writer waiting queue independently. When the lock is released, the corresponding queue task is directly woken up according to the binding strategy. There is no need to traverse the queue. The time complexity of the wake-up operation is O(1). S6. Employs a static memory pool with zero dynamic allocation: The lock control block is stored through a pre-allocated static array, and the POSIX interface is encapsulated by handle index mapping. No malloc dynamic memory allocation is performed throughout the process. It is a pure physical address operation with no MMU dependency. S7. Use a single-field three-state encoding to mark the lock state: use a 32-bit signed number to represent the three states of the lock, greater than 0 means the reader holds the lock, equal to 0 means the lock is free, and equal to -1 means the writer holds the lock exclusively, replacing the two-field storage scheme and reducing memory usage.
2. The method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system according to claim 1, characterized in that: In step S1, read-write lock instances with read-first and write-first strategies can be created and run simultaneously within the same embedded real-time operating system. The different instance strategies are independent of each other and do not interfere with each other.
3. The method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system according to claim 1, characterized in that: In step S2, the interrupt disabling operation will shield PendSV, SysTick and external interrupts, ensuring that there is no task switching or interruption during the execution of the critical section, and adapting to core chips of Cortex-M0 and Cortex-M0+ without exclusive access instructions.
4. The method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system according to claim 1, characterized in that: In step S3, the hunger elimination logic of the write priority strategy does not rely on the timeout mechanism or add any additional state fields. It directly blocks the path of writer hunger formation from the read lock application entry.
5. The method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system according to claim 1, characterized in that: In step S4, priority inheritance only applies to write lock holders, and read lock holders do not trigger priority promotion operations; priority promotion and restoration are both completed automatically by the locking mechanism and are completely transparent to upper-layer application tasks.
6. The method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system according to claim 1, characterized in that: In step S5, the wake-up rule of the write priority strategy is: after the lock is released, the first task in the write waiting queue is woken up first, and when there are no write waiting tasks, all tasks in the read waiting queue are woken up in batches; the wake-up rule of the read priority strategy is: the first task in the write waiting queue is woken up only when the lock is completely idle, and completely idle means the state of no readers and no writers.
7. The method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system according to claim 1, characterized in that: In step S6, the lock control block size is 32 bytes in a 32-bit system and 48 bytes in a 64-bit system; the size of the static memory pool is determined during system compilation, and only allocation and reclamation are performed during runtime. The POSIX wrapper layer ensures the security of lock operations and prevents illegal pointer access through triple verification: magic number verification, handle validity verification, and control block state verification.
8. The method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system according to claim 1, characterized in that: In step S7, the lock state determination only requires a single numerical comparison, eliminating the need for multi-field reading and logical combination, thus shortening the critical section execution time and improving system real-time performance.
9. The method for implementing a configurable read-write priority strategy read-write lock in an MMU-less embedded real-time operating system according to claim 1, characterized in that: The lock supports recursive holding detection. If the same task repeatedly requests a write lock, a deadlock error will be returned directly to avoid the task getting stuck.