Skip to content
Snippets Groups Projects
Commit e374cfff authored by Damien George's avatar Damien George
Browse files

py/modthread: Raise RuntimeError in release() if lock is not acquired.

parent a47b8711
No related branches found
No related tags found
No related merge requests found
...@@ -84,7 +84,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread ...@@ -84,7 +84,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread
STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) { STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) {
mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in);
// TODO check if already unlocked if (!self->locked) {
mp_raise_msg(&mp_type_RuntimeError, NULL);
}
self->locked = false; self->locked = false;
MP_THREAD_GIL_EXIT(); MP_THREAD_GIL_EXIT();
mp_thread_mutex_unlock(&self->mutex); mp_thread_mutex_unlock(&self->mutex);
......
...@@ -38,3 +38,9 @@ try: ...@@ -38,3 +38,9 @@ try:
except KeyError: except KeyError:
print('KeyError') print('KeyError')
print(lock.locked()) print(lock.locked())
# test that we can't release an unlocked lock
try:
lock.release()
except RuntimeError:
print('RuntimeError')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment