mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-22 13:48:11 +08:00
make JS_NewClassID thread safe
This commit is contained in:
parent
5c120cd471
commit
8de4538ff3
11
quickjs.c
11
quickjs.c
@ -3384,16 +3384,25 @@ static inline BOOL JS_IsEmptyString(JSValueConst v)
|
|||||||
|
|
||||||
/* JSClass support */
|
/* 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 */
|
/* a new class ID is allocated if *pclass_id != 0 */
|
||||||
JSClassID JS_NewClassID(JSClassID *pclass_id)
|
JSClassID JS_NewClassID(JSClassID *pclass_id)
|
||||||
{
|
{
|
||||||
JSClassID class_id;
|
JSClassID class_id;
|
||||||
/* XXX: make it thread safe */
|
#ifdef CONFIG_ATOMICS
|
||||||
|
pthread_mutex_lock(&js_class_id_mutex);
|
||||||
|
#endif
|
||||||
class_id = *pclass_id;
|
class_id = *pclass_id;
|
||||||
if (class_id == 0) {
|
if (class_id == 0) {
|
||||||
class_id = js_class_id_alloc++;
|
class_id = js_class_id_alloc++;
|
||||||
*pclass_id = class_id;
|
*pclass_id = class_id;
|
||||||
}
|
}
|
||||||
|
#ifdef CONFIG_ATOMICS
|
||||||
|
pthread_mutex_unlock(&js_class_id_mutex);
|
||||||
|
#endif
|
||||||
return class_id;
|
return class_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user