STATIC ptable *lt_op_map = NULL;
+#ifdef USE_ITHREADS
+STATIC perl_mutex lt_op_map_mutex;
+#endif
+
typedef struct {
SV *orig_pkg;
SV *type_pkg;
} lt_op_info;
STATIC void lt_map_store(const OP *o, SV *orig_pkg, SV *type_pkg, SV *type_meth, OP *(*pp_padsv)(pTHX)) {
- lt_op_info *oi = ptable_fetch(lt_op_map, o);
+ lt_op_info *oi;
+
+#ifdef USE_ITHREADS
+ MUTEX_LOCK(<_op_map_mutex);
+#endif
- if (!oi) {
+ if (!(oi = ptable_fetch(lt_op_map, o))) {
oi = PerlMemShared_malloc(sizeof *oi);
ptable_store(lt_op_map, o, oi);
}
oi->type_pkg = type_pkg;
oi->type_meth = type_meth;
oi->pp_padsv = pp_padsv;
+
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(<_op_map_mutex);
+#endif
}
-STATIC const lt_op_info *lt_map_fetch(const OP *o) {
- const lt_op_info *oi;
+STATIC const lt_op_info *lt_map_fetch(const OP *o, lt_op_info *oi) {
+ const lt_op_info *val;
- oi = ptable_fetch(lt_op_map, o);
+#ifdef USE_ITHREADS
+ MUTEX_LOCK(<_op_map_mutex);
+#endif
+
+ val = ptable_fetch(lt_op_map, o);
+ if (val) {
+ *oi = *val;
+ val = oi;
+ }
- return oi;
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(<_op_map_mutex);
+#endif
+
+ return val;
}
/* --- Hooks --------------------------------------------------------------- */
/* ... Our pp_padsv ........................................................ */
STATIC OP *lt_pp_padsv(pTHX) {
- const lt_op_info *oi;
+ lt_op_info oi;
- if ((PL_op->op_private & OPpLVAL_INTRO) && (oi = lt_map_fetch(PL_op))) {
+ if ((PL_op->op_private & OPpLVAL_INTRO) && lt_map_fetch(PL_op, &oi)) {
PADOFFSET targ = PL_op->op_targ;
SV *sv = PAD_SVl(targ);
PUSHMARK(SP);
EXTEND(SP, 3);
- PUSHs(oi->type_pkg);
+ PUSHs(oi.type_pkg);
PUSHs(sv);
- PUSHs(oi->orig_pkg);
+ PUSHs(oi.orig_pkg);
PUTBACK;
- items = call_sv(oi->type_meth, G_ARRAY | G_METHOD);
+ items = call_sv(oi.type_meth, G_ARRAY | G_METHOD);
SPAGAIN;
switch (items) {
LEAVE;
}
- return CALL_FPTR(oi->pp_padsv)(aTHX);
+ return CALL_FPTR(oi.pp_padsv)(aTHX);
}
return CALL_FPTR(PL_ppaddr[OP_PADSV])(aTHX);
{
if (!lt_initialized++) {
lt_op_map = ptable_new();
+#ifdef USE_ITHREADS
+ MUTEX_INIT(<_op_map_mutex);
+#endif
lt_default_meth = newSVpvn("TYPEDSCALAR", 11);
SvREADONLY_on(lt_default_meth);