fixed mistakes around semaphores
This commit is contained in:
2
main.c
2
main.c
@@ -85,7 +85,7 @@ void task4(void) {
|
|||||||
static volatile int32_t t4;
|
static volatile int32_t t4;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
sem_post32(&t4, (int32_t)1);
|
atom_inc32(&t4, (int32_t)1);
|
||||||
printf("task 4 %d %lu\r\n", g_uptime, t4);
|
printf("task 4 %d %lu\r\n", g_uptime, t4);
|
||||||
delay(3300);
|
delay(3300);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ void sem_init(sem_t* sem, int32_t value) {
|
|||||||
int32_t sem_wait(sem_t* sem) {
|
int32_t sem_wait(sem_t* sem) {
|
||||||
//while(sem->value > 0);
|
//while(sem->value > 0);
|
||||||
//sem->value--;
|
//sem->value--;
|
||||||
return sem_wait32(&(sem->value), (int32_t)1);
|
while (atom_dec32(&(sem->value), (int32_t)0) > 0);
|
||||||
|
return atom_dec32(&(sem->value), (int32_t)1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sem_post(sem_t* sem) {
|
int32_t sem_post(sem_t* sem) {
|
||||||
//sem->value++;
|
//sem->value++;
|
||||||
return sem_post32(&(sem->value), (int32_t)1);
|
return atom_inc32(&(sem->value), (int32_t)1);
|
||||||
}
|
}
|
||||||
|
|||||||
12
semoper.S
12
semoper.S
@@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
.text
|
.text
|
||||||
|
|
||||||
.globl sem_post32
|
.globl atom_inc32
|
||||||
.type sem_post32, %function
|
.type atom_inc32, %function
|
||||||
|
|
||||||
sem_post32:
|
atom_inc32:
|
||||||
1:
|
1:
|
||||||
ldrex r2, [r0]
|
ldrex r2, [r0]
|
||||||
add r2, r2, r1
|
add r2, r2, r1
|
||||||
@@ -17,10 +17,10 @@ sem_post32:
|
|||||||
bx lr
|
bx lr
|
||||||
|
|
||||||
|
|
||||||
.globl sem_wait32
|
.globl atom_dec32
|
||||||
.type sem_wait32, %function
|
.type atom_dec32, %function
|
||||||
|
|
||||||
sem_wait32:
|
atom_dec32:
|
||||||
1:
|
1:
|
||||||
ldrex r2, [r0]
|
ldrex r2, [r0]
|
||||||
sub r2, r2, r1
|
sub r2, r2, r1
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
int32_t sem_post32(volatile int32_t *addr, int32_t value);
|
int32_t atom_inc32(volatile int32_t *addr, int32_t value);
|
||||||
int32_t sem_wait32(volatile int32_t *addr, int32_t value);
|
int32_t atom_dec32(volatile int32_t *addr, int32_t value);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user