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.
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
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);