之前的互斥读写实现的信号量有问题,
压力测试不能通过
今天重新实现了一次,测试互斥操作正常。
另外,使用位带(bit band)实现互斥操作,
有没有同学有较好的思路的?
给我点指点~
- __asm I8 BenOSGetSemaphore1(SEMAPHORE_TYPE* pSem)
- {
- THUMB
- REQUIRE8
- PRESERVE8
-
- PUSH {R1,R2,LR}
-
- TryToRead_G
- LDREX R2, [R0]
- CMP R2,#0
- CBZ R2,GetFailed_G
-
- ReadSuccess_G ;Try to get sem
- SUB R2, #1
- STREX R1,R2,[R0]
- CMP R1, #0
- BNE TryToRead_G
-
- GetSuccess_G
- MOV R0, #1
- POP {R1,R2,PC}
-
- GetFailed_G
- ; STREX R1,R2,[R0]
- MOV R0, #0
- POP {R1,R2,PC}
- }
-
- __asm I8 BenOSReleaseSemaphore1(SEMAPHORE_TYPE* pSem)
- {
- PUSH {R1,R2,LR}
-
- TryToRead_R
- LDREX R2, [R0]
-
- ReadSuccess_R ;Try to get sem
- ADD R2, #1
- STREX R1,R2,[R0]
- CMP R1, #0
- BNE TryToRead_R
-
- GetSuccess_R
- MOV R0, #1
- POP {R1,R2,PC}
- }
-
- __asm I8 BenOSWaitSemaphore1(SEMAPHORE_TYPE* pSem,I32U timeout)
- {
- EXTERN BenOSTimeDly
-
- PUSH {R1,R2,R3,LR}
- ADD R1, #1
-
- Loop_W
- TryToRead_W
- LDREX R2, [R0]
- CBZ R2,Wait1Tick_W
-
- ReadSuccess_W ;Try to get sem
- SUB R2, #1
- STREX R3,R2,[R0]
- CMP R3, #0
- BNE TryToRead_W
- B GetSuccess_W
-
- Wait1Tick_W
- ; STREX R3,R2,[R0]
- SUB R1, #1
- CBZ R1,GetFailed_W
- PUSH {R0-R3}
- MOV R0,#1
- LDR R3,=BenOSTimeDly
- BLX R3
- POP {R0-R3}
- B Loop_W
-
-
- GetSuccess_W
- MOV R0, #1
- POP {R1,R2,R3,PC}
-
- GetFailed_W
- MOV R0, #0
- POP {R1,R2,R3,PC}
-
- }
复制代码 |