aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/stacks.c20
-rw-r--r--src/util.h3
2 files changed, 23 insertions, 0 deletions
diff --git a/src/stacks.c b/src/stacks.c
index a35ca3de..c783967c 100644
--- a/src/stacks.c
+++ b/src/stacks.c
@@ -248,6 +248,26 @@ wait_threads(void)
yield();
}
+void
+mutex_lock(struct mutex_s *mutex)
+{
+ ASSERT32FLAT();
+ if (! CONFIG_THREADS)
+ return;
+ while (mutex->isLocked)
+ yield();
+ mutex->isLocked = 1;
+}
+
+void
+mutex_unlock(struct mutex_s *mutex)
+{
+ ASSERT32FLAT();
+ if (! CONFIG_THREADS)
+ return;
+ mutex->isLocked = 0;
+}
+
/****************************************************************
* Thread preemption
diff --git a/src/util.h b/src/util.h
index 9f71d65a..9b4fd3ab 100644
--- a/src/util.h
+++ b/src/util.h
@@ -208,6 +208,9 @@ struct thread_info *getCurThread(void);
void yield(void);
void run_thread(void (*func)(void*), void *data);
void wait_threads(void);
+struct mutex_s { u32 isLocked; };
+void mutex_lock(struct mutex_s *mutex);
+void mutex_unlock(struct mutex_s *mutex);
void start_preempt(void);
void finish_preempt(void);
void check_preempt(void);