diff options
| author | Damien George | 2017-02-06 15:13:30 +1100 |
|---|---|---|
| committer | Damien George | 2017-02-15 13:28:48 +1100 |
| commit | 05a4859585c4e0a55fca2e7467ba70da6453fdcb (patch) | |
| tree | 70d87f5ac3437b2e46e5b4d2d7b29b9ecced3776 /stmhal/mpthreadport.h | |
| parent | f6c22a06797735e4a65a91491d8373ba951a798b (diff) | |
stmhal: Implement a proper thread scheduler.
This patch changes the threading implementation from simple round-robin
with busy waits on mutexs, to proper scheduling whereby threads that are
waiting on a mutex are only scheduled when the mutex becomes available.
Diffstat (limited to 'stmhal/mpthreadport.h')
| -rw-r--r-- | stmhal/mpthreadport.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/stmhal/mpthreadport.h b/stmhal/mpthreadport.h index 4fef323eb..3d8b4ef01 100644 --- a/stmhal/mpthreadport.h +++ b/stmhal/mpthreadport.h @@ -29,7 +29,7 @@ #include "py/mpthread.h" #include "pybthread.h" -typedef uint32_t mp_thread_mutex_t; +typedef pyb_mutex_t mp_thread_mutex_t; void mp_thread_init(void); void mp_thread_gc_others(void); @@ -42,4 +42,16 @@ static inline struct _mp_state_thread_t *mp_thread_get_state(void) { return pyb_thread_get_local(); } +static inline void mp_thread_mutex_init(mp_thread_mutex_t *m) { + pyb_mutex_init(m); +} + +static inline int mp_thread_mutex_lock(mp_thread_mutex_t *m, int wait) { + return pyb_mutex_lock(m, wait); +} + +static inline void mp_thread_mutex_unlock(mp_thread_mutex_t *m) { + pyb_mutex_unlock(m); +} + #endif // __MICROPY_INCLUDED_STMHAL_MPTHREADPORT_H__ |
