summaryrefslogtreecommitdiff
path: root/py/modthread.c
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2024-02-27 15:32:29 +1100
committerDamien George <damien@micropython.org>2024-03-07 14:20:42 +1100
commitdecf8e6a8bb940d5829ca3296790631fcece7b21 (patch)
tree55b7cd31de14b73e4b72d49344e9084f402767a9 /py/modthread.c
parentb3f2f18f927fa2fad10daf63d8c391331f5edf58 (diff)
all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. The original reason for this was to have the option to define it to nothing so that all static functions become global functions and therefore visible to certain debug tools, so one could do function size comparison and other things. This STATIC feature is rarely (if ever) used. And with the use of LTO and heavy inline optimisation, analysing the size of individual functions when they are not static is not a good representation of the size of code when fully optimised. So the macro does not have much use and it's simpler to just remove it. Then you know exactly what it's doing. For example, newcomers don't have to learn what the STATIC macro is and why it exists. Reading the code is also less "loud" with a lowercase static. One other minor point in favour of removing it, is that it stops bugs with `STATIC inline`, which should always be `static inline`. Methodology for this commit was: 1) git ls-files | egrep '\.[ch]$' | \ xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/" 2) Do some manual cleanup in the diff by searching for the word STATIC in comments and changing those back. 3) "git-grep STATIC docs/", manually fixed those cases. 4) "rg -t python STATIC", manually fixed codegen lines that used STATIC. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'py/modthread.c')
-rw-r--r--py/modthread.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/py/modthread.c b/py/modthread.c
index 9fc20570b..2826fadea 100644
--- a/py/modthread.c
+++ b/py/modthread.c
@@ -45,7 +45,7 @@
/****************************************************************/
// Lock object
-STATIC const mp_obj_type_t mp_type_thread_lock;
+static const mp_obj_type_t mp_type_thread_lock;
typedef struct _mp_obj_thread_lock_t {
mp_obj_base_t base;
@@ -53,14 +53,14 @@ typedef struct _mp_obj_thread_lock_t {
volatile bool locked;
} mp_obj_thread_lock_t;
-STATIC mp_obj_thread_lock_t *mp_obj_new_thread_lock(void) {
+static mp_obj_thread_lock_t *mp_obj_new_thread_lock(void) {
mp_obj_thread_lock_t *self = mp_obj_malloc(mp_obj_thread_lock_t, &mp_type_thread_lock);
mp_thread_mutex_init(&self->mutex);
self->locked = false;
return self;
}
-STATIC mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *args) {
+static mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *args) {
mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(args[0]);
bool wait = true;
if (n_args > 1) {
@@ -79,9 +79,9 @@ STATIC mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *args) {
mp_raise_OSError(-ret);
}
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread_lock_acquire);
+static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread_lock_acquire);
-STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) {
+static mp_obj_t thread_lock_release(mp_obj_t self_in) {
mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in);
if (!self->locked) {
mp_raise_msg(&mp_type_RuntimeError, NULL);
@@ -92,21 +92,21 @@ STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) {
MP_THREAD_GIL_ENTER();
return mp_const_none;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_release_obj, thread_lock_release);
+static MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_release_obj, thread_lock_release);
-STATIC mp_obj_t thread_lock_locked(mp_obj_t self_in) {
+static mp_obj_t thread_lock_locked(mp_obj_t self_in) {
mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_bool(self->locked);
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_locked_obj, thread_lock_locked);
+static MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_locked_obj, thread_lock_locked);
-STATIC mp_obj_t thread_lock___exit__(size_t n_args, const mp_obj_t *args) {
+static mp_obj_t thread_lock___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args; // unused
return thread_lock_release(args[0]);
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock___exit___obj, 4, 4, thread_lock___exit__);
+static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock___exit___obj, 4, 4, thread_lock___exit__);
-STATIC const mp_rom_map_elem_t thread_lock_locals_dict_table[] = {
+static const mp_rom_map_elem_t thread_lock_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_acquire), MP_ROM_PTR(&thread_lock_acquire_obj) },
{ MP_ROM_QSTR(MP_QSTR_release), MP_ROM_PTR(&thread_lock_release_obj) },
{ MP_ROM_QSTR(MP_QSTR_locked), MP_ROM_PTR(&thread_lock_locked_obj) },
@@ -114,9 +114,9 @@ STATIC const mp_rom_map_elem_t thread_lock_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&thread_lock___exit___obj) },
};
-STATIC MP_DEFINE_CONST_DICT(thread_lock_locals_dict, thread_lock_locals_dict_table);
+static MP_DEFINE_CONST_DICT(thread_lock_locals_dict, thread_lock_locals_dict_table);
-STATIC MP_DEFINE_CONST_OBJ_TYPE(
+static MP_DEFINE_CONST_OBJ_TYPE(
mp_type_thread_lock,
MP_QSTR_lock,
MP_TYPE_FLAG_NONE,
@@ -126,14 +126,14 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
/****************************************************************/
// _thread module
-STATIC size_t thread_stack_size = 0;
+static size_t thread_stack_size = 0;
-STATIC mp_obj_t mod_thread_get_ident(void) {
+static mp_obj_t mod_thread_get_ident(void) {
return mp_obj_new_int_from_uint(mp_thread_get_id());
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_get_ident_obj, mod_thread_get_ident);
+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) {
+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;
@@ -142,7 +142,7 @@ STATIC mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) {
}
return ret;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_stack_size_obj, 0, 1, mod_thread_stack_size);
+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_dict_t *dict_locals;
@@ -154,7 +154,7 @@ typedef struct _thread_entry_args_t {
mp_obj_t args[];
} thread_entry_args_t;
-STATIC void *thread_entry(void *args_in) {
+static void *thread_entry(void *args_in) {
// Execution begins here for a new thread. We do not have the GIL.
thread_entry_args_t *args = (thread_entry_args_t *)args_in;
@@ -207,7 +207,7 @@ STATIC void *thread_entry(void *args_in) {
return NULL;
}
-STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) {
+static mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) {
// This structure holds the Python function and arguments for thread entry.
// We copy all arguments into this structure to keep ownership of them.
// We must be very careful about root pointers because this pointer may
@@ -258,19 +258,19 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args)
// spawn the thread!
return mp_obj_new_int_from_uint(mp_thread_create(thread_entry, th_args, &th_args->stack_size));
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3, mod_thread_start_new_thread);
+static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3, mod_thread_start_new_thread);
-STATIC mp_obj_t mod_thread_exit(void) {
+static mp_obj_t mod_thread_exit(void) {
mp_raise_type(&mp_type_SystemExit);
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_exit_obj, mod_thread_exit);
+static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_exit_obj, mod_thread_exit);
-STATIC mp_obj_t mod_thread_allocate_lock(void) {
+static mp_obj_t mod_thread_allocate_lock(void) {
return MP_OBJ_FROM_PTR(mp_obj_new_thread_lock());
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_allocate_lock_obj, mod_thread_allocate_lock);
+static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_allocate_lock_obj, mod_thread_allocate_lock);
-STATIC const mp_rom_map_elem_t mp_module_thread_globals_table[] = {
+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_LockType), MP_ROM_PTR(&mp_type_thread_lock) },
{ MP_ROM_QSTR(MP_QSTR_get_ident), MP_ROM_PTR(&mod_thread_get_ident_obj) },
@@ -280,7 +280,7 @@ STATIC const mp_rom_map_elem_t mp_module_thread_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_allocate_lock), MP_ROM_PTR(&mod_thread_allocate_lock_obj) },
};
-STATIC MP_DEFINE_CONST_DICT(mp_module_thread_globals, mp_module_thread_globals_table);
+static MP_DEFINE_CONST_DICT(mp_module_thread_globals, mp_module_thread_globals_table);
const mp_obj_module_t mp_module_thread = {
.base = { &mp_type_module },