# define SvPV_const(S, L) SvPV(S, L)
#endif
+#ifdef USE_ITHREADS
+# define REH_LOCK(M) MUTEX_LOCK(M)
+# define REH_UNLOCK(M) MUTEX_UNLOCK(M)
+#else
+# define REH_LOCK(M) NOOP
+# define REH_UNLOCK(M) NOOP
+#endif
+
/* --- Lexical hints ------------------------------------------------------- */
STATIC U32 reh_hash = 0;
STATIC reh_action *reh_action_list = 0;
+#ifdef USE_ITHREADS
+
+STATIC perl_mutex reh_action_list_mutex;
+
+#endif /* USE_ITHREADS */
+
#undef reh_register
void reh_register(pTHX_ const char *key, reh_comp_hook comp, reh_exec_hook exec) {
reh_action *a;
key_dup[len] = '\0';
a = PerlMemShared_malloc(sizeof *a);
- a->next = reh_action_list;
a->comp = comp;
a->exec = exec;
a->key = key_dup;
a->klen = len;
+ REH_LOCK(&reh_action_list_mutex);
+ a->next = reh_action_list;
reh_action_list = a;
+ REH_UNLOCK(&reh_action_list_mutex);
return;
}
const char *keys = SvPV_const(hint, len);
reh_action *a;
- for (a = reh_action_list; a; a = a->next) {
+ REH_LOCK(&reh_action_list_mutex);
+ a = reh_action_list;
+ REH_UNLOCK(&reh_action_list_mutex);
+
+ for (; a; a = a->next) {
if (a->comp) {
char *p = strstr(keys, a->key);
const char *keys = SvPV_const(hint, len);
reh_action *a;
- for (a = reh_action_list; a; a = a->next) {
+ REH_LOCK(&reh_action_list_mutex);
+ a = reh_action_list;
+ REH_UNLOCK(&reh_action_list_mutex);
+
+ for (; a; a = a->next) {
if (a->exec) {
char *p = strstr(keys, a->key);
PROTOTYPES: ENABLE
+BOOT:
+{
+#ifdef USE_ITHREADS
+ MUTEX_INIT(&reh_action_list_mutex);
+#endif
+}
+
void
_ENGINE()
PROTOTYPE:
PROTOTYPE: $
PREINIT:
SV *ret = NULL;
- reh_action *a = reh_action_list;
+ reh_action *a;
STRLEN len;
const char *s;
PPCODE:
+ REH_LOCK(&reh_action_list_mutex);
+ a = reh_action_list;
+ REH_UNLOCK(&reh_action_list_mutex);
s = SvPV_const(key, len);
while (a && !ret) {
if (a->klen == len && memcmp(a->key, s, len) == 0)