Damien George
53562213c8
cc3200: Enable the GIL.
2016-06-28 11:28:52 +01:00
Damien George
fa2ac93c3a
cc3200/mpthreadport: Move mem alloc outside the thread_mutex lock.
...
Otherwise there could be a deadlock, with the GC's mutex and
thread_mutex.
2016-06-28 11:28:52 +01:00
Damien George
757146efe3
cc3200/mpthreadport: Scan more root pointers from thread data.
2016-06-28 11:28:52 +01:00
Damien George
17886828c8
cc3200/gccollect: Use MP_STATE_THREAD(stack_top) to get top of stack.
2016-06-28 11:28:52 +01:00
Damien George
3b0fbfe4e5
cc3200/mpthreadport: Properly initialise the main thread's data.
2016-06-28 11:28:52 +01:00
Damien George
27241293c4
cc3200/mpthreadport: Make mutex statically allocated.
...
Reduced the need for the FreeRTOS heap to allocate the mutex.
2016-06-28 11:28:52 +01:00
Damien George
0455755296
cc3200: Use xTaskCreateStatic instead of osi_TaskCreate.
...
This allows to statically allocate the TCB (thread control block) and
thread stack in the BSS segment, reducing the need for dynamic memory
allocation.
2016-06-28 11:28:52 +01:00
Damien George
77e37ff98b
py/mpthread: Include mpstate.h when defining GIL macros.
2016-06-28 11:28:52 +01:00
Damien George
15e68277c1
tests/thread: Make sure that thread tests don't rely on floating point.
2016-06-28 11:28:52 +01:00
Damien George
5b7789d519
tests/thread: Make stack-size test run correctly and reliable on uPy.
2016-06-28 11:28:52 +01:00
Damien George
94238d4ae5
py/nlrsetjmp: Update to take into account new location of nlr_top.
...
It's now accessed via the MP_STATE_THREAD macro.
2016-06-28 11:28:52 +01:00
Damien George
1df4168c33
py/nlrthumb: Convert NLR thumb funcs from asm to C with inline-asm.
...
Now only the bits that really need to be written in assembler are written
in it, otherwise C is used. This means that the assembler code no longer
needs to know about the global state structure which makes it much easier
to maintain.
2016-06-28 11:28:52 +01:00
Damien George
c9520c591b
cc3200: Fix call to new exception to be _msg instead of _arg1.
2016-06-28 11:28:51 +01:00
Damien George
df95f52583
py/modthread: Allow to properly set the stack limit of a thread.
...
We rely on the port setting and adjusting the stack size so there is
enough room to recover from hitting the stack limit.
2016-06-28 11:28:51 +01:00
Damien George
eef4f13a33
cc3200: Add basic threading capabilities.
...
Can create a new thread and run it. Does not use the GIL at this point.
2016-06-28 11:28:51 +01:00
Damien George
9b1c1262dc
cc3200: Define our own FreeRTOS heap so it can go in a special segment.
2016-06-28 11:28:50 +01:00
Damien George
5c0fc73f33
cc3200: Update FreeRTOS to v9.0.0.
...
This is a pristine copy (actually a subset of files) of upstream FreeRTOS
v9.0.0.
Modifications to the previous version of FreeRTOS (v8.1.2) included
addition of __attribute__ ((section (".boot"))) to the following
functions:
pxPortInitialiseStack
prvTaskExitError
prvPortStartFirstTask
xPortStartScheduler
vPortSetupTimerInterrupt
xTaskGenericCreate
vTaskStartScheduler
prvInitialiseTCBVariables
prvInitialiseTaskLists
prvAllocateTCBAndStack
This attribute will need to be reinstated on a case-by-case basis
because some of the above functions are now removed/changed.
2016-06-28 11:28:50 +01:00
Damien George
e90b6ce0b5
py/mpthread.h: Move GIL macros outside MICROPY_PY_THREAD block.
...
The GIL macros are needed even if threading is not enabled.
2016-06-28 11:28:50 +01:00
Damien George
94d2919b77
unix/modtime: Release the GIL when sleeping.
2016-06-28 11:28:50 +01:00
Damien George
c567afc5fa
py/modthread: Make Lock objects work when GIL is enabled.
2016-06-28 11:28:50 +01:00
Damien George
a1c93a62b1
py: Don't use gc or qstr mutex when the GIL is enabled.
...
There is no need since the GIL already makes gc and qstr operations
atomic.
2016-06-28 11:28:50 +01:00
Damien George
4cec63a9db
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.
2016-06-28 11:28:50 +01:00
Damien George
1f54ad2aed
py: Make interning of qstrs thread safe.
2016-06-28 11:28:50 +01:00
Damien George
b7274e91bc
tests/thread: Add test for concurrent mutating of user instance.
2016-06-28 11:28:50 +01:00
Damien George
2e4cdae4fd
tests/thread: Add test for concurrent interning of strings.
...
Qstr code accesses global state and needs to be made thread safe.
2016-06-28 11:28:50 +01:00
Damien George
094a0dd11a
tests/thread: Add tests that mutate shared objects.
...
Tests concurrent mutating access to: list, dict, set, bytearray.
2016-06-28 11:28:50 +01:00
Damien George
c73cf9d931
tests/thread: Rename thread_stress_XXX.py to stress_XXX.py.
2016-06-28 11:28:50 +01:00
Damien George
f443504f86
unix/mpthreadport: Suppress compiler warning about unused arguments.
2016-06-28 11:28:50 +01:00
Damien George
f1dbd2909e
unix/gccollect: Provide declaration of exported function.
2016-06-28 11:28:50 +01:00
Damien George
c2508ac8bd
unix/mpthreadport: Use SA_SIGINFO for GC signal handler.
...
SA_SIGINFO allows the signal handler to access more information about
the signal, especially useful in a threaded environment. The extra
information is not currently used but it may prove useful in the future.
2016-06-28 11:28:49 +01:00
Damien George
3653f5144a
py/gc: Fix GC+thread bug where ptr gets lost because it's not computed.
...
GC_EXIT() can cause a pending thread (waiting on the mutex) to be
scheduled right away. This other thread may trigger a garbage
collection. If the pointer to the newly-allocated block (allocated by
the original thread) is not computed before the switch (so it's just left
as a block number) then the block will be wrongly reclaimed.
This patch makes sure the pointer is computed before allowing any thread
switch to occur.
2016-06-28 11:28:49 +01:00
Damien George
dbd54e0b5b
unix: Implement garbage collection with threading.
...
This patch allows any given thread to do a proper garbage collection and
scan all the pointers of all active threads.
2016-06-28 11:28:49 +01:00
Damien George
9172c0cb25
py/modthread: Call mp_thread_start/mp_thread_finish around threads.
...
So the underlying thread implementation can do any necessary bookkeeping.
2016-06-28 11:28:49 +01:00
Damien George
722cff5fd0
py/modthread: Be more careful with root pointers when creating a thread.
2016-06-28 11:28:49 +01:00
Damien George
f1b6db2218
unix/file: If write syscall returns because of EINTR then try again.
...
As per PEP-475.
2016-06-28 11:28:49 +01:00
Damien George
e33806aaff
py/gc: Fix 2 cases of concurrent access to ATB and FTB.
2016-06-28 11:28:49 +01:00
Damien George
7f4658a7ee
py/modthread: Satisfy unused-args warning.
2016-06-28 11:28:49 +01:00
Damien George
dcc7c5bd89
tests/thread: Add tests for running GC within a thread, and heap stress.
2016-06-28 11:28:49 +01:00
Damien George
c93d9caa8b
py/gc: Make memory manager and garbage collector thread safe.
...
By using a single, global mutex, all memory-related functions (alloc,
free, realloc, collect, etc) are made thread safe. This means that only
one thread can be in such a function at any one time.
2016-06-28 11:28:49 +01:00
Damien George
34fc006f5e
py/modthread: Add with-context capabilities to lock object.
2016-06-28 11:28:49 +01:00
Damien George
801d1b3803
py/modthread: Implement lock object, for creating a mutex.
2016-06-28 11:28:49 +01:00
Damien George
2dacd604c5
py/modthread: Add exit() function.
...
Simply raises the SystemExit exception.
2016-06-28 11:28:48 +01:00
Damien George
707f98f207
py/modthread: Add stack_size() function.
2016-06-28 11:28:48 +01:00
Damien George
3eb7a26809
py/modthread: Properly cast concrete exception pointer to an object.
2016-06-28 11:28:48 +01:00
Damien George
a791be936a
unix: Add basic thread support using pthreads.
...
Has the ability to create new threads.
2016-06-28 11:28:48 +01:00
Damien George
27cc07721b
py: Add basic _thread module, with ability to start a new thread.
2016-06-28 11:28:48 +01:00
Damien George
330165a2cc
py: Add MP_STATE_THREAD to hold state specific to a given thread.
2016-06-28 11:09:31 +01:00
Damien George
3545ef8bb4
tests/thread: Remove need to sleep to wait for completion in some tests.
...
Use a lock and a counter instead, and busy wait for all threads to
complete. This makes test run faster and they no longer rely on the time
module.
2016-06-28 11:09:31 +01:00
Damien George
2d5ea38b49
tests: Add 3 more tests for _thread module.
2016-06-28 11:09:31 +01:00
Damien George
ed36632c6c
tests: Add tests for _thread module.
...
Includes functionality and stress tests.
2016-06-28 11:09:31 +01:00