Skip to content

Commit

Permalink
py/gc: Don't include or init gc_mutex when GIL is enabled.
Browse files Browse the repository at this point in the history
When threads and the GIL are enabled, then the GC mutex is not needed.  The
gc_mutex field is never used in this case because of:

    #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
    #define GC_ENTER() mp_thread_mutex_lock(&MP_STATE_MEM(gc_mutex), 1)
    #define GC_EXIT() mp_thread_mutex_unlock(&MP_STATE_MEM(gc_mutex))
    #else
    #define GC_ENTER()
    #define GC_EXIT()
    #endif

So, we can completely remove gc_mutex everywhere when MICROPY_PY_THREAD
&& !MICROPY_PY_THREAD_GIL.
  • Loading branch information
dlech authored and dpgeorge committed Jan 23, 2020
1 parent 6db5ced commit ccc18f0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion py/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void gc_init(void *start, void *end) {
MP_STATE_MEM(gc_alloc_amount) = 0;
#endif

#if MICROPY_PY_THREAD
#if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
mp_thread_mutex_init(&MP_STATE_MEM(gc_mutex));
#endif

Expand Down
2 changes: 1 addition & 1 deletion py/mpstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ typedef struct _mp_state_mem_t {
size_t gc_collected;
#endif

#if MICROPY_PY_THREAD
#if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
// This is a global mutex used to make the GC thread-safe.
mp_thread_mutex_t gc_mutex;
#endif
Expand Down

0 comments on commit ccc18f0

Please sign in to comment.