aboutsummaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-03-24 19:21:12 -0700
committerChristian Cunningham <cc@localhost>2022-03-24 19:21:12 -0700
commitc5b6f1611ea1f4685ef02f65fc0362f9c22c344f (patch)
treeae00afc0d01a6aa1f14ccd894ebe42e239d7e30a /usr
parentab0252db26ff425b26ab6a2e0a2b359d2da2adea (diff)
Semaphore example in toy
Diffstat (limited to 'usr')
-rw-r--r--usr/main.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/usr/main.c b/usr/main.c
index 835cedf..0cc25d8 100644
--- a/usr/main.c
+++ b/usr/main.c
@@ -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);
}