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 /util.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 'util.c')
-rw-r--r-- | util.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -1829,4 +1829,41 @@ getTHR _((void)) return (struct thread *) t; } #endif /* OLD_PTHREADS_API */ + +MAGIC * +condpair_magic(sv) +SV *sv; +{ + MAGIC *mg; + + SvUPGRADE(sv, SVt_PVMG); + mg = mg_find(sv, 'm'); + if (!mg) { + condpair_t *cp; + + New(53, cp, 1, condpair_t); + MUTEX_INIT(&cp->mutex); + COND_INIT(&cp->owner_cond); + COND_INIT(&cp->cond); + cp->owner = 0; + MUTEX_LOCK(&sv_mutex); + mg = mg_find(sv, 'm'); + if (mg) { + /* someone else beat us to initialising it */ + MUTEX_UNLOCK(&sv_mutex); + MUTEX_DESTROY(&cp->mutex); + COND_DESTROY(&cp->owner_cond); + COND_DESTROY(&cp->cond); + Safefree(cp); + } + else { + sv_magic(sv, Nullsv, 'm', 0, 0); + mg = SvMAGIC(sv); + mg->mg_ptr = (char *)cp; + mg->mg_len = sizeof(cp); + MUTEX_UNLOCK(&sv_mutex); + } + } + return mg; +} #endif /* USE_THREADS */ |