#endif /* SO_THREADSAFE */
+#define PTABLE_NAME ptable
+#define PTABLE_VAL_FREE(V) PerlMemShared_free(V)
+
+#include "ptable.h"
+
+/* PerlMemShared_free() needs the [ap]PTBLMS_? default values */
+#define ptable_store(T, K, V) ptable_store(aPTBLMS_ (T), (K), (V))
+
+STATIC ptable *sub_op_name = NULL;
+
+#ifdef USE_ITHREADS
+STATIC perl_mutex sub_op_name_mutex;
+#endif
+
+typedef struct {
+ STRLEN len;
+ char buf;
+} sub_op_name_t;
+
/* --- Public API ---------------------------------------------------------- */
#include "sub_op.h"
}
sub_op_linklist(o);
+
+ {
+ sub_op_name_t *on = PerlMemShared_malloc(sizeof(*on) + len);
+ Copy(name, &on->buf, len, char);
+ (&on->buf)[len] = '\0';
+ on->len = len;
+#ifdef USE_ITHREADS
+ MUTEX_LOCK(&sub_op_name_mutex);
+#endif /* USE_ITHREADS */
+ ptable_store(sub_op_name, o, on);
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(&sub_op_name_mutex);
+#endif /* USE_ITHREADS */
+ }
}
}
BOOT:
{
+ sub_op_name = ptable_new();
+#ifdef USE_ITHREADS
+ MUTEX_INIT(&sub_op_name_mutex);
+#endif
+
MY_CXT_INIT;
MY_CXT.map = newHV();
MY_CXT.next_pkg = newAV();
PROTOTYPE: $
PREINIT:
OP *o;
- SV *key;
- HE *he;
+ sub_op_name_t *on;
PPCODE:
if (!SvROK(op))
XSRETURN_UNDEF;
o = INT2PTR(OP *, SvIV(SvRV(op)));
if (!o || o->op_type != OP_CUSTOM)
XSRETURN_UNDEF;
- key = newSViv(PTR2IV(o->op_ppaddr));
- he = hv_fetch_ent(PL_custom_op_names, key, 0, 0);
- SvREFCNT_dec(key);
- if (!he)
+#ifdef USE_ITHREADS
+ MUTEX_LOCK(&sub_op_name_mutex);
+#endif /* USE_ITHREADS */
+ on = ptable_fetch(sub_op_name, o);
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(&sub_op_name_mutex);
+#endif /* USE_ITHREADS */
+ if (!on)
XSRETURN_UNDEF;
- ST(0) = sv_mortalcopy(HeVAL(he));
+ ST(0) = sv_2mortal(newSVpvn(&on->buf, on->len));
XSRETURN(1);