summaryrefslogtreecommitdiff
path: root/pp.c
diff options
context:
space:
mode:
authorMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-07-05 11:55:18 +0000
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-07-05 11:55:18 +0000
commitc03294656c9980c235cc5951a63088fd96d33704 (patch)
tree6e8191a8d83c36b157d11c7868c3d9c0e8ddcc8d /pp.c
parent462e5cf694f345fbf34a1f95e9a82957e59dcc2b (diff)
downloadperl-c03294656c9980c235cc5951a63088fd96d33704.tar.gz
Introduce pp_lock.
p4raw-id: //depot/perl@35
Diffstat (limited to 'pp.c')
-rw-r--r--pp.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/pp.c b/pp.c
index 391133b72a..735b884134 100644
--- a/pp.c
+++ b/pp.c
@@ -89,6 +89,9 @@ typedef unsigned UBW;
static void doencodes _((SV* sv, char* s, I32 len));
static SV* refto _((SV* sv));
static U32 seed _((void));
+#ifdef USE_THREADS
+static void unlock_condpair _((void*));
+#endif /* USE_THREADS */
static bool srand_called = FALSE;
@@ -4109,3 +4112,47 @@ PP(pp_split)
RETPUSHUNDEF;
}
+#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_lock)
+{
+ dSP;
+#ifdef USE_THREADS
+ dTOPss;
+ MAGIC *mg;
+
+ if (SvROK(sv))
+ 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);
+ }
+#endif /* USE_THREADS */
+ PUSHs(&sv_yes);
+ RETURN;
+}