Damien George
77e37ff98b
py/mpthread: Include mpstate.h when defining GIL macros.
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
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
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
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
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
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
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
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
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
Paul Sokolovsky
c7fba524cb
py/objtype: Inherit protocol vtable from base class only if it exists.
2016-06-19 00:56:06 +03:00
Paul Sokolovsky
41167554e4
py/mphal.h: If virtpin API is used, automagically include its header.
2016-06-19 00:12:37 +03:00
Paul Sokolovsky
413c3e10b4
py/objtype: instance: Inherit protocol vtable from a base class.
...
This allows to define an abstract base class which would translate
C-level protocol to Python method calls, and any subclass inheriting
from it will support this feature. This in particular actually enables
recently introduced machine.PinBase class.
2016-06-19 00:01:59 +03:00