summaryrefslogtreecommitdiffstatshomepage
path: root/unix/mpthreadport.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-04-25 09:02:47 +0000
committerDamien George <damien.p.george@gmail.com>2016-06-28 11:28:48 +0100
commit707f98f207d85b1de9814e90254d52a78ac19739 (patch)
treec1f4546ff29c5117c7a13aa3caf18e604c76e21d /unix/mpthreadport.c
parent3eb7a268091ef68248d58ddb3ad11465f1cb2199 (diff)
downloadmicropython-707f98f207d85b1de9814e90254d52a78ac19739.tar.gz
micropython-707f98f207d85b1de9814e90254d52a78ac19739.zip
py/modthread: Add stack_size() function.
Diffstat (limited to 'unix/mpthreadport.c')
-rw-r--r--unix/mpthreadport.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/unix/mpthreadport.c b/unix/mpthreadport.c
index af75be1aa1..73e08dcb86 100644
--- a/unix/mpthreadport.c
+++ b/unix/mpthreadport.c
@@ -46,9 +46,34 @@ void mp_thread_set_state(void *state) {
pthread_setspecific(tls_key, state);
}
-void mp_thread_create(void *(*entry)(void*), void *arg) {
+void mp_thread_create(void *(*entry)(void*), void *arg, size_t stack_size) {
+ // default stack size is 8k machine-words
+ if (stack_size == 0) {
+ stack_size = 8192 * BYTES_PER_WORD;
+ }
+
+ // set thread attributes
+ pthread_attr_t attr;
+ int ret = pthread_attr_init(&attr);
+ if (ret != 0) {
+ goto er;
+ }
+ ret = pthread_attr_setstacksize(&attr, stack_size);
+ if (ret != 0) {
+ goto er;
+ }
+
+ // create thread
pthread_t id;
- pthread_create(&id, NULL, entry, arg);
+ ret = pthread_create(&id, &attr, entry, arg);
+ if (ret != 0) {
+ goto er;
+ }
+
+ return;
+
+er:
+ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(ret)));
}
#endif // MICROPY_PY_THREAD