diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2010-02-27 13:49:47 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2010-02-28 17:26:25 -0500 |
commit | e9086652b3901df4ff29bdd5eb095d0e3b8c349a (patch) | |
tree | 1d66452bc616a228c211e2d84fafb8143b332c07 | |
parent | 3b79f8b97f2abff364b9ca9f1e761ed4827a6deb (diff) | |
download | seabios-e9086652b3901df4ff29bdd5eb095d0e3b8c349a.tar.gz |
Introduce simple "mutex" locking code.
Locks are not normally necessary because SeaBIOS uses a cooperative
multitasking system. However, occasionally it is necessary to be able
to lock a resource across yield calls. This patch introduces a simple
mechanism for doing that.
-rw-r--r-- | src/stacks.c | 20 | ||||
-rw-r--r-- | src/util.h | 3 |
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 @@ -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); |