diff options
author | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-04-23 19:06:45 +0000 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-04-23 19:06:45 +0000 |
commit | f93b4edd807be1c6102dad09f884828c27c4a58b (patch) | |
tree | 137d9c548c5e8c0dcbd6c3a76c121b5ce06ff663 /pp_ctl.c | |
parent | b35b24033ff5a2171d5dc795e027358506aa01ff (diff) | |
download | perl-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.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -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) |