summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-04-23 19:06:45 +0000
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-04-23 19:06:45 +0000
commitf93b4edd807be1c6102dad09f884828c27c4a58b (patch)
tree137d9c548c5e8c0dcbd6c3a76c121b5ce06ff663 /pp_ctl.c
parentb35b24033ff5a2171d5dc795e027358506aa01ff (diff)
downloadperl-f93b4edd807be1c6102dad09f884828c27c4a58b.tar.gz
Added programmer-level condition variables via "condpair" magic.
Added support for detached threads and tweaked a few things. p4raw-id: //depot/thrperl@8
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index fb64466883..ee463ea79b 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1220,9 +1220,54 @@ const void *b;
return 1;
}
+#ifdef USE_THREADS
+static void
+unlock_condpair(svv)
+void *svv;
+{
+ dTHR;
+ MAGIC *mg = mg_find((SV*)svv, 'm');
+
+ if (!mg)
+ croak("panic: unlock_condpair unlocking non-mutex");
+ MUTEX_LOCK(MgMUTEXP(mg));
+ if (MgOWNER(mg) != thr)
+ croak("panic: unlock_condpair unlocking mutex that we don't own");
+ MgOWNER(mg) = 0;
+ COND_SIGNAL(MgOWNERCONDP(mg));
+ MUTEX_UNLOCK(MgMUTEXP(mg));
+}
+#endif /* USE_THREADS */
+
PP(pp_reset)
{
dSP;
+#ifdef USE_THREADS
+ dTOPss;
+ MAGIC *mg;
+
+ if (MAXARG < 1)
+ croak("reset requires mutex argument with USE_THREADS");
+ if (SvROK(sv)) {
+ /*
+ * Kludge to allow lock of real objects without requiring
+ * to pass in every type of argument by explicit reference.
+ */
+ sv = SvRV(sv);
+ }
+ mg = condpair_magic(sv);
+ MUTEX_LOCK(MgMUTEXP(mg));
+ if (MgOWNER(mg) == thr)
+ MUTEX_UNLOCK(MgMUTEXP(mg));
+ else {
+ while (MgOWNER(mg))
+ COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
+ MgOWNER(mg) = thr;
+ MUTEX_UNLOCK(MgMUTEXP(mg));
+ save_destructor(unlock_condpair, sv);
+ }
+ RETURN;
+#else
char *tmps;
if (MAXARG < 1)
@@ -1232,6 +1277,7 @@ PP(pp_reset)
sv_reset(tmps, curcop->cop_stash);
PUSHs(&sv_yes);
RETURN;
+#endif /* USE_THREADS */
}
PP(pp_lineseq)