diff options
author | Christian Cunningham <cc@localhost> | 2022-03-24 19:21:12 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-03-24 19:21:12 -0700 |
commit | c5b6f1611ea1f4685ef02f65fc0362f9c22c344f (patch) | |
tree | ae00afc0d01a6aa1f14ccd894ebe42e239d7e30a | |
parent | ab0252db26ff425b26ab6a2e0a2b359d2da2adea (diff) |
Semaphore example in toy
-rw-r--r-- | usr/main.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -1,4 +1,6 @@ +#include <cpu.h> #include <globals.h> +#include <graphics/lfb.h> #include <symbols.h> #include <sys/schedule.h> #include <usr/string.h> @@ -33,6 +35,25 @@ static struct UartInfo UART_INFO = { .priority = 2, }; +static unsigned long simulated = 0; + +void producer(void) +{ + draw_string(0, 15, "Producing..."); + sys1(SYS_SEMAPHORE_V, &simulated); + draw_string(0, 15, "Produced! "); +} + +void consumer(void) +{ + add_thread(producer, 0, 4); + while (1) { + draw_string(0, 16, "Consuming..."); + sys1(SYS_SEMAPHORE_P, &simulated); + draw_string(0, 16, "Consumed! "); + } +} + void main(void) { subscribe_irq(UART_IRQ, handle_data, &UART_INFO); @@ -40,5 +61,6 @@ void main(void) subscribe_irq(SYS_TIMER_1_IRQ, loopt, &stime_1); subscribe_irq(SYS_TIMER_2_IRQ, loopt, &stime_2); subscribe_irq(SYS_TIMER_3_IRQ, loopt, &stime_3); - add_thread(loop, 0, 0); + add_thread(loop, 0, 8); + add_thread(consumer, 0, 3); } |