They happen very late in the destruction process but that's not an issue
there. The MGWIZ structure and the SVs they contain are destroyed and
removed from the global pointer table when the wizard object is destroyed.
At the time the atexit callback fires, the pointer table is then empty and
the only thing left to do is to free its own (shared) memory.
ptable_store(ud->wizards, ent->key, w);
}
ptable_store(ud->wizards, ent->key, w);
}
-STATIC void vmg_thread_cleanup(pTHX_ void *);
-
-STATIC void vmg_thread_cleanup(pTHX_ void *ud) {
- int *level = ud;
-
- if (*level) {
- --*level;
- LEAVE;
- SAVEDESTRUCTOR_X(vmg_thread_cleanup, level);
- ENTER;
- } else {
- dMY_CXT;
- PerlMemShared_free(level);
- ptable_free(MY_CXT.wizards);
- }
-}
#endif /* VMG_THREADSAFE */
/* --- Wizard objects ------------------------------------------------------ */
#endif /* VMG_THREADSAFE */
/* --- Wizard objects ------------------------------------------------------ */
+#if VMG_THREADSAFE
+
+STATIC void vmg_cleanup(pTHX_ void *ud) {
+ dMY_CXT;
+
+ ptable_free(MY_CXT.wizards);
+ MY_CXT.wizards = NULL;
+}
+
+#endif /* VMG_THREADSAFE */
+
/* --- XS ------------------------------------------------------------------ */
MODULE = Variable::Magic PACKAGE = Variable::Magic
/* --- XS ------------------------------------------------------------------ */
MODULE = Variable::Magic PACKAGE = Variable::Magic
MY_CXT.b__op_stashes[0] = NULL;
#if VMG_THREADSAFE
MUTEX_INIT(&vmg_op_name_init_mutex);
MY_CXT.b__op_stashes[0] = NULL;
#if VMG_THREADSAFE
MUTEX_INIT(&vmg_op_name_init_mutex);
+ call_atexit(vmg_cleanup, NULL);
#endif
stash = gv_stashpv(__PACKAGE__, 1);
#endif
stash = gv_stashpv(__PACKAGE__, 1);
? gv_stashpv(vmg_opclassnames[c], 1) : NULL;
}
}
? gv_stashpv(vmg_opclassnames[c], 1) : NULL;
}
}
- {
- int *level;
- level = PerlMemShared_malloc(sizeof *level);
- *level = 1;
- LEAVE;
- SAVEDESTRUCTOR_X(vmg_thread_cleanup, level);
- ENTER;
- }
XSRETURN(0);
#endif /* VMG_THREADSAFE */
XSRETURN(0);
#endif /* VMG_THREADSAFE */