File tree 4 files changed +18
-6
lines changed
4 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 113
113
#endif
114
114
115
115
#if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
116
- #define GC_ENTER () mp_thread_mutex_lock(&MP_STATE_MEM(gc_mutex), 1)
117
- #define GC_EXIT () mp_thread_mutex_unlock(&MP_STATE_MEM(gc_mutex))
116
+ #define GC_MUTEX_INIT () mp_thread_recursive_mutex_init(&MP_STATE_MEM(gc_mutex))
117
+ #define GC_ENTER () mp_thread_recursive_mutex_lock(&MP_STATE_MEM(gc_mutex), 1)
118
+ #define GC_EXIT () mp_thread_recursive_mutex_unlock(&MP_STATE_MEM(gc_mutex))
118
119
#else
120
+ // Either no threading, or assume callers to gc_collect() hold the GIL
121
+ #define GC_MUTEX_INIT ()
119
122
#define GC_ENTER ()
120
123
#define GC_EXIT ()
121
124
#endif
@@ -210,9 +213,7 @@ void gc_init(void *start, void *end) {
210
213
MP_STATE_MEM (gc_alloc_amount ) = 0 ;
211
214
#endif
212
215
213
- #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
214
- mp_thread_mutex_init (& MP_STATE_MEM (gc_mutex ));
215
- #endif
216
+ GC_MUTEX_INIT ();
216
217
}
217
218
218
219
#if MICROPY_GC_SPLIT_HEAP
Original file line number Diff line number Diff line change @@ -1629,6 +1629,11 @@ typedef double mp_float_t;
1629
1629
#define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
1630
1630
#endif
1631
1631
1632
+ // Is a recursive mutex type in use?
1633
+ #ifndef MICROPY_PY_THREAD_RECURSIVE_MUTEX
1634
+ #define MICROPY_PY_THREAD_RECURSIVE_MUTEX (MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL)
1635
+ #endif
1636
+
1632
1637
// Extended modules
1633
1638
1634
1639
#ifndef MICROPY_PY_ASYNCIO
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ typedef struct _mp_state_mem_t {
145
145
146
146
#if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
147
147
// This is a global mutex used to make the GC thread-safe.
148
- mp_thread_mutex_t gc_mutex ;
148
+ mp_thread_recursive_mutex_t gc_mutex ;
149
149
#endif
150
150
} mp_state_mem_t ;
151
151
Original file line number Diff line number Diff line change @@ -48,6 +48,12 @@ void mp_thread_mutex_init(mp_thread_mutex_t *mutex);
48
48
int mp_thread_mutex_lock (mp_thread_mutex_t * mutex , int wait );
49
49
void mp_thread_mutex_unlock (mp_thread_mutex_t * mutex );
50
50
51
+ #if MICROPY_PY_THREAD_RECURSIVE_MUTEX
52
+ void mp_thread_recursive_mutex_init (mp_thread_recursive_mutex_t * mutex );
53
+ int mp_thread_recursive_mutex_lock (mp_thread_recursive_mutex_t * mutex , int wait );
54
+ void mp_thread_recursive_mutex_unlock (mp_thread_recursive_mutex_t * mutex );
55
+ #endif
56
+
51
57
#endif // MICROPY_PY_THREAD
52
58
53
59
#if MICROPY_PY_THREAD && MICROPY_PY_THREAD_GIL
You can’t perform that action at this time.
0 commit comments