summaryrefslogtreecommitdiff
path: root/util.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 /util.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 'util.c')
-rw-r--r--util.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/util.c b/util.c
index ef5c8460a9..65fa31b3a2 100644
--- a/util.c
+++ b/util.c
@@ -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 */