mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 20:50:14 +01:00
py/modmicropython: Add heap_locked function to test state of heap.
This commit adds micropython.heap_locked() which returns the current lock-depth of the heap, and can be used by Python code to check if the heap is locked or not. This new function is configured via MICROPY_PY_MICROPYTHON_HEAP_LOCKED and is disabled by default. This commit also changes the return value of micropython.heap_unlock() so it returns the current lock-depth as well.
This commit is contained in:
committed by
Damien George
parent
7eea0d8b6c
commit
86bfabec11
@@ -5,6 +5,7 @@ import micropython
|
||||
l = []
|
||||
l2 = list(range(100))
|
||||
|
||||
micropython.heap_lock()
|
||||
micropython.heap_lock()
|
||||
|
||||
# general allocation on the heap
|
||||
@@ -19,6 +20,14 @@ try:
|
||||
except MemoryError:
|
||||
print('MemoryError')
|
||||
|
||||
print(micropython.heap_unlock())
|
||||
|
||||
# Should still fail
|
||||
try:
|
||||
print([])
|
||||
except MemoryError:
|
||||
print('MemoryError')
|
||||
|
||||
micropython.heap_unlock()
|
||||
|
||||
# check that allocation works after an unlock
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
MemoryError
|
||||
MemoryError
|
||||
1
|
||||
MemoryError
|
||||
[]
|
||||
|
||||
12
tests/micropython/heap_locked.py
Normal file
12
tests/micropython/heap_locked.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# test micropython.heap_locked()
|
||||
|
||||
import micropython
|
||||
|
||||
if not hasattr(micropython, "heap_locked"):
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
micropython.heap_lock()
|
||||
print(micropython.heap_locked())
|
||||
micropython.heap_unlock()
|
||||
print(micropython.heap_locked())
|
||||
2
tests/micropython/heap_locked.py.exp
Normal file
2
tests/micropython/heap_locked.py.exp
Normal file
@@ -0,0 +1,2 @@
|
||||
1
|
||||
0
|
||||
Reference in New Issue
Block a user