MUTEX_DESTROY(&vmg_op_name_init_mutex);
MUTEX_DESTROY(&vmg_vtable_refcount_mutex);
- vmg_loaded = 0;
-
return;
}
static int vmg_global_teardown_free(pTHX_ SV *sv, MAGIC *mg) {
- vmg_global_teardown_late_locked();
+ VMG_LOADED_LOCK;
+
+ if (vmg_loaded == 0)
+ vmg_global_teardown_late_locked();
+
VMG_LOADED_UNLOCK;
return 0;
#if VMG_THREADSAFE
VMG_LOADED_LOCK;
- if (vmg_loaded <= 1) {
- assert(vmg_loaded == 1);
+ if (vmg_loaded == 1) {
+ vmg_loaded = 0;
if (vmg_destruct_level() == 0) {
vmg_global_teardown_late_locked();
- VMG_LOADED_UNLOCK;
} else {
if (!PL_strtab)
PL_strtab = newHV();
vmg_sv_magicext((SV *) PL_strtab, NULL, &vmg_global_teardown_vtbl, NULL, 0);
- /* Lock until vmg_global_teardown_free() is called */
}
} else {
+ assert(vmg_loaded > 1);
--vmg_loaded;
- VMG_LOADED_UNLOCK;
}
+
+ VMG_LOADED_UNLOCK;
#endif
if (MY_CXT.depth == 0 && MY_CXT.freed_tokens) {