Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
707f98f2
Commit
707f98f2
authored
9 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py/modthread: Add stack_size() function.
parent
3eb7a268
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
py/modthread.c
+15
-2
15 additions, 2 deletions
py/modthread.c
py/mpthread.h
+1
-1
1 addition, 1 deletion
py/mpthread.h
unix/mpthreadport.c
+27
-2
27 additions, 2 deletions
unix/mpthreadport.c
with
43 additions
and
5 deletions
py/modthread.c
+
15
−
2
View file @
707f98f2
...
...
@@ -45,11 +45,24 @@
/****************************************************************/
// _thread module
STATIC
size_t
thread_stack_size
=
0
;
STATIC
mp_obj_t
mod_thread_get_ident
(
void
)
{
return
mp_obj_new_int_from_uint
((
uintptr_t
)
mp_thread_get_state
());
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
mod_thread_get_ident_obj
,
mod_thread_get_ident
);
STATIC
mp_obj_t
mod_thread_stack_size
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_t
ret
=
mp_obj_new_int_from_uint
(
thread_stack_size
);
if
(
n_args
==
0
)
{
thread_stack_size
=
0
;
}
else
{
thread_stack_size
=
mp_obj_get_int
(
args
[
0
]);
}
return
ret
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mod_thread_stack_size_obj
,
0
,
1
,
mod_thread_stack_size
);
typedef
struct
_thread_entry_args_t
{
mp_obj_t
fun
;
size_t
n_args
;
...
...
@@ -126,8 +139,7 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args)
}
th_args
->
args
=
all_args
;
}
// TODO implement setting thread stack size
mp_thread_create
(
thread_entry
,
th_args
);
mp_thread_create
(
thread_entry
,
th_args
,
thread_stack_size
);
return
mp_const_none
;
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mod_thread_start_new_thread_obj
,
2
,
3
,
mod_thread_start_new_thread
);
...
...
@@ -135,6 +147,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3
STATIC
const
mp_rom_map_elem_t
mp_module_thread_globals_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR__thread
)
},
{
MP_ROM_QSTR
(
MP_QSTR_get_ident
),
MP_ROM_PTR
(
&
mod_thread_get_ident_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_stack_size
),
MP_ROM_PTR
(
&
mod_thread_stack_size_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_start_new_thread
),
MP_ROM_PTR
(
&
mod_thread_start_new_thread_obj
)
},
};
...
...
This diff is collapsed.
Click to expand it.
py/mpthread.h
+
1
−
1
View file @
707f98f2
...
...
@@ -38,7 +38,7 @@
mp_state_thread_t
*
mp_thread_get_state
(
void
);
void
mp_thread_set_state
(
void
*
state
);
void
mp_thread_create
(
void
*
(
*
entry
)(
void
*
),
void
*
arg
);
void
mp_thread_create
(
void
*
(
*
entry
)(
void
*
),
void
*
arg
,
size_t
stack_size
);
#endif // MICROPY_PY_THREAD
...
...
This diff is collapsed.
Click to expand it.
unix/mpthreadport.c
+
27
−
2
View file @
707f98f2
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment