commit c9f9ef0a9c443dcd1e3d471c8b3fb1635f0960b4 parent fc877fb13b554e551fa3063bda6c5dad42e4ba38 Author: Fabrice Bellard <fabrice@bellard.org> Date: Tue, 2 Jan 2024 16:08:48 +0100 make JS_NewClassID thread safe Diffstat:
| M | quickjs/quickjs.c | | | 11 | ++++++++++- |
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/quickjs/quickjs.c b/quickjs/quickjs.c @@ -3388,16 +3388,25 @@ static inline BOOL JS_IsEmptyString(JSValueConst v) /* JSClass support */ +#ifdef CONFIG_ATOMICS +static pthread_mutex_t js_class_id_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif + /* a new class ID is allocated if *pclass_id != 0 */ JSClassID JS_NewClassID(JSClassID *pclass_id) { JSClassID class_id; - /* XXX: make it thread safe */ +#ifdef CONFIG_ATOMICS + pthread_mutex_lock(&js_class_id_mutex); +#endif class_id = *pclass_id; if (class_id == 0) { class_id = js_class_id_alloc++; *pclass_id = class_id; } +#ifdef CONFIG_ATOMICS + pthread_mutex_unlock(&js_class_id_mutex); +#endif return class_id; }