micropython/py
Damien George b6b39bff47 py/gc: Make gc_lock_depth have a count per thread.
This commit makes gc_lock_depth have one counter per thread, instead of one
global counter.  This makes threads properly independent with respect to
the GC, in particular threads can now independently lock the GC for
themselves without locking it for other threads.  It also means a given
thread can run a hard IRQ without temporarily locking the GC for all other
threads and potentially making them have MemoryError exceptions at random
locations (this really only occurs on MCUs with multiple cores and no GIL,
eg on the rp2 port).

The commit also removes protection of the GC lock/unlock functions, which
is no longer needed when the counter is per thread (and this also fixes the
cas where a hard IRQ calling gc_lock() may stall waiting for the mutex).

It also puts the check for `gc_lock_depth > 0` outside the GC mutex in
gc_alloc, gc_realloc and gc_free, to potentially prevent a hard IRQ from
waiting on a mutex if it does attempt to allocate heap memory (and putting
the check outside the GC mutex is now safe now that there is a
gc_lock_depth per thread).

Signed-off-by: Damien George <damien@micropython.org>
2021-05-10 13:07:16 +10:00
..
argcheck.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
asmarm.c py/asm: Add funcs/macros to emit machine code for logical-shift-right. 2020-06-27 00:24:04 +10:00
asmarm.h py/asm: Add funcs/macros to emit machine code for logical-shift-right. 2020-06-27 00:24:04 +10:00
asmbase.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmbase.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmthumb.c py/emitnative: Support binary ops on ARMv6M without use of ite instr. 2021-01-29 23:57:10 +11:00
asmthumb.h py/emitnative: Support binary ops on ARMv6M without use of ite instr. 2021-01-29 23:57:10 +11:00
asmx64.c py/asm: Add funcs/macros to emit machine code for logical-shift-right. 2020-06-27 00:24:04 +10:00
asmx64.h py/asm: Add condition codes for signed comparisons. 2020-06-27 00:24:04 +10:00
asmx86.c py/asm: Add funcs/macros to emit machine code for logical-shift-right. 2020-06-27 00:24:04 +10:00
asmx86.h py/asm: Add condition codes for signed comparisons. 2020-06-27 00:24:04 +10:00
asmxtensa.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmxtensa.h py/asm: Add funcs/macros to emit machine code for logical-shift-right. 2020-06-27 00:24:04 +10:00
bc.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
bc.h py/showbc: Pass in an mp_print_t struct to all bytecode-print functions. 2020-09-11 17:22:28 +10:00
bc0.h py/bc0.h: Shift comment to start of line to improve format consistency. 2020-02-28 10:29:32 +11:00
binary.c all: Rename BYTES_PER_WORD to MP_BYTES_PER_OBJ_WORD. 2021-02-04 22:46:42 +11:00
binary.h py/binary: Change mp_uint_t to size_t for index, size, align args. 2019-09-02 13:14:27 +10:00
builtin.h extmod/uasyncio: Add optional implementation of core uasyncio in C. 2020-03-26 01:25:45 +11:00
builtinevex.c all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
builtinhelp.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
builtinimport.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
compile.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
compile.h py: Add global default_emit_opt variable to make emit kind persistent. 2019-08-28 12:47:58 +10:00
dynruntime.h py/dynruntime.h: Add mp_obj_get_array() function. 2021-04-28 00:06:46 +10:00
dynruntime.mk py/dynruntime.mk: Set MICROPY_ENABLE_DYNRUNTIME instead of per module. 2020-04-05 14:13:02 +10:00
emit.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
emitbc.c all: Rename BYTES_PER_WORD to MP_BYTES_PER_OBJ_WORD. 2021-02-04 22:46:42 +11:00
emitcommon.c py/scope: Optimise scope_find_or_add_id to not need "added" arg. 2018-10-28 00:38:18 +11:00
emitglue.c py/showbc: Pass in an mp_print_t struct to all bytecode-print functions. 2020-09-11 17:22:28 +10:00
emitglue.h py: Integrate sys.settrace feature into the VM and runtime. 2019-08-30 16:44:12 +10:00
emitinlinethumb.c py/emitinlinethumb: Exclude code using #if when ARMV7M disabled. 2021-01-29 23:57:10 +11:00
emitinlinextensa.c py: Use unsigned comparison of chars. 2020-10-22 11:47:36 +02:00
emitnarm.c py/emitnative: Add support for return/break/continue in try and with. 2018-09-04 14:31:28 +10:00
emitnative.c py/emitnative: Support binary ops on ARMv6M without use of ite instr. 2021-01-29 23:57:10 +11:00
emitnthumb.c py/emitnative: Add support for return/break/continue in try and with. 2018-09-04 14:31:28 +10:00
emitnx64.c py/emitnative: Add support for return/break/continue in try and with. 2018-09-04 14:31:28 +10:00
emitnx86.c py/nativeglue: Add new header file with native function table typedef. 2019-12-12 20:15:28 +11:00
emitnxtensa.c py/emitnative: Add support for return/break/continue in try and with. 2018-09-04 14:31:28 +10:00
emitnxtensawin.c py: Add new Xtensa-Windowed arch for native emitter. 2019-10-05 13:44:53 +10:00
formatfloat.c all: Fix implicit conversion from double to float. 2020-04-18 22:42:24 +10:00
formatfloat.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
frozenmod.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
frozenmod.h various: Update early copyright years to match actual edit history. 2019-05-17 18:06:11 +10:00
gc.c py/gc: Make gc_lock_depth have a count per thread. 2021-05-10 13:07:16 +10:00
gc.h py/gc: Change include of stdint.h to stddef.h. 2021-02-05 15:46:56 +11:00
grammar.h py/compile: Implement PEP 526, syntax for variable annotations. 2020-06-16 23:18:01 +10:00
lexer.c py, extmod: Introduce and use MP_FALLTHROUGH macro. 2020-10-22 11:53:16 +02:00
lexer.h py/compile: Implement PEP 572, assignment expressions with := operator. 2020-06-16 22:02:24 +10:00
makecompresseddata.py py/makecompresseddata.py: Make compression deterministic. 2020-04-20 10:32:49 +10:00
makemoduledefs.py all: Update Python code to conform to latest black formatting. 2020-08-29 15:18:01 +10:00
makeqstrdata.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
makeqstrdefs.py tools/makeqstrdefs.py: Run qstr preprocessing in parallel. 2020-11-12 15:04:53 +11:00
makeversionhdr.py py/makeversionhdr: Honor SOURCE_DATE_EPOCH if present. 2021-01-31 17:48:59 +01:00
malloc.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
map.c py/objdict: Add mp_const_empty_dict_obj, use it for mp_const_empty_map. 2020-10-10 00:16:26 +11:00
misc.h py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
mkenv.mk py/mkenv.mk: Move usage of 32-bit flags to py.mk. 2020-01-12 10:34:10 +11:00
mkrules.cmake rp2: Add support for USER_C_MODULES to CMake build system. 2021-03-31 00:26:01 +11:00
mkrules.mk py/mkrules.mk: Remove stray vpath and unused -Itmp, add $(Q) for $(AR). 2020-12-14 13:57:15 +11:00
modarray.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modbuiltins.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
modcmath.c all: Format code to add space after C++-style comment start. 2020-04-23 11:24:25 +10:00
modcollections.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modgc.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modio.c py: Rename remaining object types to be of the form mp_type_xxx. 2021-03-26 13:48:34 +11:00
modmath.c py/modmath: Simplify handling of positional args to reduce code size. 2020-12-14 13:30:56 +11:00
modmicropython.c py/gc: Make gc_lock_depth have a count per thread. 2021-05-10 13:07:16 +10:00
modstruct.c all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
modsys.c py/modsys: Use consistent naming pattern for module-level const objects. 2020-05-28 10:02:14 +10:00
modthread.c py/gc: Make gc_lock_depth have a count per thread. 2021-05-10 13:07:16 +10:00
moduerrno.c all: Format code to add space after C++-style comment start. 2020-04-23 11:24:25 +10:00
mpconfig.h py/scheduler: Add optional port hook for when something is scheduled. 2021-04-30 15:32:16 +10:00
mperrno.h py/mperrno: Define MP_EWOULDBLOCK as EWOULDBLOCK, not EAGAIN. 2018-05-01 15:53:25 +10:00
mphal.h all: Rename absolute time-based functions to include "epoch". 2020-09-18 17:20:34 +10:00
mpprint.c py/mpprint: Fix length calculation for strings with precision-modifier. 2020-12-07 23:32:06 +11:00
mpprint.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpstate.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
mpstate.h py/gc: Make gc_lock_depth have a count per thread. 2021-05-10 13:07:16 +10:00
mpthread.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpz.c py/mpz: Fix overflow of borrow in mpn_div. 2021-02-08 11:50:05 +11:00
mpz.h tools/codeformat.py: Eliminate need for sizeof fixup. 2020-03-11 14:34:40 +11:00
nativeglue.c all: Fix implicit floating point promotion. 2020-04-18 22:36:14 +10:00
nativeglue.h py/nativeglue.h: Rename "setjmp" entry to "setjmp_" to avoid any clash. 2020-05-14 21:48:05 +10:00
nlr.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlr.h py/nlr: Implement NLR for AArch64. 2021-03-11 12:51:10 +11:00
nlraarch64.c py/nlr: Implement NLR for AArch64. 2021-03-11 12:51:10 +11:00
nlrpowerpc.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlrsetjmp.c py/nlr: Factor out common NLR code to macro and generic funcs in nlr.c. 2017-12-28 16:46:30 +11:00
nlrthumb.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlrx64.c py/nlrx64: Fix typo in comment. 2021-03-11 12:51:10 +11:00
nlrx86.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlrxtensa.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
obj.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
obj.h py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
objarray.c py: Rename remaining object types to be of the form mp_type_xxx. 2021-03-26 13:48:34 +11:00
objarray.h py/objarray.h: Add mp_obj_memoryview_init() helper function. 2020-09-25 12:23:11 +10:00
objattrtuple.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objbool.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objboundmeth.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objcell.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objclosure.c py: Rename remaining object types to be of the form mp_type_xxx. 2021-03-26 13:48:34 +11:00
objcomplex.c py/objcomplex: Add mp_obj_get_complex_maybe for use in complex bin-op. 2020-06-27 01:03:10 +10:00
objdeque.c all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
objdict.c py: Rename remaining object types to be of the form mp_type_xxx. 2021-03-26 13:48:34 +11:00
objenumerate.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objexcept.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
objexcept.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objfilter.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
objfloat.c py: Rename BITS_PER_BYTE to MP_BITS_PER_BYTE. 2021-02-04 22:46:42 +11:00
objfun.c py/objfun: Support fun.__globals__ attribute. 2021-01-29 23:57:10 +11:00
objfun.h py: Integrate sys.settrace feature into the VM and runtime. 2019-08-30 16:44:12 +10:00
objgenerator.c py: Rework mp_convert_member_lookup to properly handle built-ins. 2020-06-30 23:55:32 +10:00
objgenerator.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objgetitemiter.c py: Rename remaining object types to be of the form mp_type_xxx. 2021-03-26 13:48:34 +11:00
objint.c py: Rename BITS_PER_BYTE to MP_BITS_PER_BYTE. 2021-02-04 22:46:42 +11:00
objint.h py/modsys: Use consistent naming pattern for module-level const objects. 2020-05-28 10:02:14 +10:00
objint_longlong.c py/modsys: Use consistent naming pattern for module-level const objects. 2020-05-28 10:02:14 +10:00
objint_mpz.c py/mpz: Do sign extension in mpz_as_bytes for negative values. 2020-11-11 22:18:24 +11:00
objlist.c all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
objlist.h py/obj.h: Move declaration of mp_obj_list_init to objlist.h. 2018-03-13 14:03:15 +11:00
objmap.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
objmodule.c all: Rename "sys" module to "usys". 2020-09-04 00:10:24 +10:00
objmodule.h py/objmodule.h: Remove obsolete mp_builtin_module_weak_links_map decl. 2020-02-11 15:43:13 +11:00
objnamedtuple.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
objnamedtuple.h py/objnamedtuple: Allow to reuse namedtuple basic functionality. 2017-11-20 09:30:06 +02:00
objnone.c py/obj: Add MICROPY_OBJ_IMMEDIATE_OBJS option to reduce code size. 2020-01-13 01:01:45 +11:00
objobject.c all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
objpolyiter.c all: Remove inclusion of internal py header files. 2017-10-04 12:37:50 +11:00
objproperty.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objrange.c py: Rename remaining object types to be of the form mp_type_xxx. 2021-03-26 13:48:34 +11:00
objreversed.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
objset.c py, extmod: Introduce and use MP_FALLTHROUGH macro. 2020-10-22 11:53:16 +02:00
objsingleton.c py/objsingleton: Use mp_generic_unary_op for singleton objects. 2019-12-27 12:53:36 +11:00
objslice.c all: Clean up error strings to use lowercase and change cannot to can't. 2020-04-13 22:19:37 +10:00
objstr.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
objstr.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objstringio.c all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
objstringio.h py/objstringio: If created from immutable object, follow copy on write policy. 2017-06-09 17:33:01 +03:00
objstrunicode.c py/mpprint: Fix length calculation for strings with precision-modifier. 2020-12-07 23:32:06 +11:00
objtuple.c all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
objtuple.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objtype.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
objtype.h py/runtime: Don't allocate iter buf for user-defined types. 2019-12-27 12:34:22 +11:00
objzip.c py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. 2019-02-12 14:54:51 +11:00
opmethods.c py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t. 2020-01-09 11:25:26 +11:00
pairheap.c py/pairheap: Properly unlink node on pop and delete. 2020-03-26 01:21:04 +11:00
pairheap.h py/pairheap: Add helper function to initialise a new node. 2020-03-26 01:21:04 +11:00
parse.c py/parse: Expose rule-name printing as MICROPY_DEBUG_PARSE_RULE_NAME. 2020-10-01 15:26:43 +10:00
parse.h py/parse: Pass in an mp_print_t to mp_parse_node_print. 2020-09-11 23:00:03 +10:00
parsenum.c py: Add option to compile without any error messages at all. 2021-04-27 23:51:52 +10:00
parsenum.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
parsenumbase.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
parsenumbase.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
persistentcode.c all: Rename BYTES_PER_WORD to MP_BYTES_PER_OBJ_WORD. 2021-02-04 22:46:42 +11:00
persistentcode.h py/persistentcode: Make ARM Thumb archs support multiple sub-archs. 2019-12-12 20:15:28 +11:00
profile.c py/profile: Use mp_handle_pending() to raise pending exception. 2021-04-30 15:13:43 +10:00
profile.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
py.cmake py/py.cmake: Introduce MICROPY_INC_CORE as a list with core includes. 2021-04-09 13:08:35 +10:00
py.mk py/nlr: Implement NLR for AArch64. 2021-03-11 12:51:10 +11:00
pystack.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
pystack.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
qstr.c all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
qstr.h py/qstr.h: Remove QSTR_FROM_STR_STATIC macro. 2021-01-30 13:40:48 +11:00
qstrdefs.h all: Add *FORMAT-OFF* in various places. 2020-02-28 10:31:07 +11:00
reader.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
reader.h py: Allow lexer to raise exceptions during construction. 2017-03-14 11:52:05 +11:00
repl.c py/repl: Autocomplete builtin modules. 2021-05-02 23:11:14 +10:00
repl.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
ringbuf.c py/ringbuf: Add peek16 method. 2019-11-21 12:04:53 +11:00
ringbuf.h extmod/modbluetooth: Make modbluetooth event not a bitfield. 2020-06-05 14:04:20 +10:00
runtime.c py/runtime: Remove commented-out code from mp_deinit(). 2021-04-30 16:35:14 +10:00
runtime.h all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt. 2021-04-30 15:13:43 +10:00
runtime0.h py/nativeglue: Add new header file with native function table typedef. 2019-12-12 20:15:28 +11:00
runtime_utils.c py: mp_call_function_*_protected(): Pass-thru return value if possible. 2017-12-05 00:38:41 +02:00
scheduler.c py/scheduler: Add missing MICROPY_WRAP_MP_SCHED_EXCEPTION usage. 2021-05-01 23:10:26 +10:00
scope.c py/scope: Name and use id_kind_type_t. 2020-10-22 11:40:56 +02:00
scope.h py/scope: Name and use id_kind_type_t. 2020-10-22 11:40:56 +02:00
sequence.c all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
showbc.c py/showbc: Pass in an mp_print_t struct to all bytecode-print functions. 2020-09-11 17:22:28 +10:00
smallint.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
smallint.h py: Rename WORD_MSBIT_HIGH to MP_OBJ_WORD_MSBIT_HIGH. 2021-02-04 22:46:42 +11:00
stackctrl.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
stackctrl.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
stream.c py/stream: Remove mp_stream_errno and use system errno instead. 2020-04-27 23:58:46 +10:00
stream.h py/stream.h: Include sys/types.h to get size_t and off_t for POSIX API. 2020-03-25 01:00:52 +11:00
unicode.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
unicode.h py/objstr: Add check for valid UTF-8 when making a str from bytes. 2017-09-06 16:43:09 +10:00
usermod.cmake rp2: Add support for USER_C_MODULES to CMake build system. 2021-03-31 00:26:01 +11:00
vm.c py/vm: For tracing use mp_printf, and print state when thread enabled. 2021-03-17 12:13:53 +11:00
vmentrytable.h py/vmentrytable: Ignore GCC -Woverride-init. 2020-10-22 11:47:36 +02:00
vstr.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
warning.c py: Update my copyright info on some files. 2019-02-06 00:19:00 +11:00