diff options
author | Damien George <damien.p.george@gmail.com> | 2016-05-26 10:42:53 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-06-28 11:28:50 +0100 |
commit | 4cec63a9dbed86c4332b9e7fcd56d092046193e4 (patch) | |
tree | 9e5e0636411f5de6647d4021c8069a39cb031f14 /py/mpthread.h | |
parent | 1f54ad2aed0dc8f2d868ccd89ccf639a475e8022 (diff) |
py: Implement a simple global interpreter lock.
This makes the VM/runtime thread safe, at the cost of not being able to
run code in parallel.
Diffstat (limited to 'py/mpthread.h')
-rw-r--r-- | py/mpthread.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/py/mpthread.h b/py/mpthread.h index d0164ea29..747de60fe 100644 --- a/py/mpthread.h +++ b/py/mpthread.h @@ -38,6 +38,14 @@ struct _mp_state_thread_t; +#if MICROPY_PY_THREAD_GIL +#define MP_THREAD_GIL_ENTER() mp_thread_mutex_lock(&MP_STATE_VM(gil_mutex), 1) +#define MP_THREAD_GIL_EXIT() mp_thread_mutex_unlock(&MP_STATE_VM(gil_mutex)) +#else +#define MP_THREAD_GIL_ENTER() +#define MP_THREAD_GIL_EXIT() +#endif + struct _mp_state_thread_t *mp_thread_get_state(void); void mp_thread_set_state(void *state); void mp_thread_create(void *(*entry)(void*), void *arg, size_t stack_size); |