py/modthread: Add with-context capabilities to lock object.

This commit is contained in:
Damien George 2016-04-25 11:33:53 +00:00
parent 801d1b3803
commit 34fc006f5e
1 changed files with 7 additions and 0 deletions

View File

@ -95,10 +95,17 @@ STATIC mp_obj_t thread_lock_locked(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_locked_obj, thread_lock_locked);
STATIC mp_obj_t thread_lock___exit__(size_t n_args, const mp_obj_t *args) {
return thread_lock_release(args[0]);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock___exit___obj, 4, 4, thread_lock___exit__);
STATIC const mp_rom_map_elem_t thread_lock_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_acquire), MP_ROM_PTR(&thread_lock_acquire_obj) },
{ MP_ROM_QSTR(MP_QSTR_release), MP_ROM_PTR(&thread_lock_release_obj) },
{ MP_ROM_QSTR(MP_QSTR_locked), MP_ROM_PTR(&thread_lock_locked_obj) },
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&thread_lock_acquire_obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&thread_lock___exit___obj) },
};
STATIC MP_DEFINE_CONST_DICT(thread_lock_locals_dict, thread_lock_locals_dict_table);