develooper Front page | perl.perl5.porters | Postings from November 1999

[PATCH 5.005_62]Allow XS code to lock arbitrary scalars

From:
Dan Sugalski
Date:
November 16, 1999 06:31
Subject:
[PATCH 5.005_62]Allow XS code to lock arbitrary scalars
Message ID:
3.0.6.32.19991116093354.00bfd340@tuatha.sidhe.org
The following patch provides a new macro, SvLOCK, which lets XS code snag a
perl-level lock on an arbitrary SV *.

(FWIW, I can't get inbound mail for a while, so replies'll be a bit tardy)

--- sv.h;1      Sat Sep 25 06:25:28 1999
+++ sv.h        Mon Nov 15 12:27:56 1999
@@ -696,3 +696,19 @@

 #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
 #define Sv_Grow sv_grow
+
+#ifdef USE_THREADS
+#  define SvLOCK(sv) STMT_START {                      \
+        dSP;                                           \
+        SAVETMPS;                                      \
+        PUSHMARK(SP);                                  \
+        XPUSHs(sv);                                    \
+        PUTBACK;                                       \
+        Perl_pp_lock(ARGS);                            \
+        SPAGAIN;                                       \
+        PUTBACK;                                       \
+        FREETMPS;                                      \
+    } STMT_END
+#else
+#  define SvLOCK(sv)
+#endif


--- pod/perlguts.pod;1  Sun Oct 10 19:37:53 1999
+++ pod/perlguts.pod    Tue Nov 16 09:25:48 1999
@@ -3159,6 +3159,14 @@

	STRLEN  sv_len (SV* sv)

+=item SvLOCK
+
+Take out a perl lock on the SV. (Note that this is B<not> the same as
+aquiring a mutex on the SV *) Equivalent to doing a C<lock $foo;>
+from perl.
+
+        void SvLOCK(SV* sv)
+
 =item sv_magic

 Adds magic to an SV.


## End of Patch ##

					Dan

----------------------------------------"it's like this"-------------------
Dan Sugalski                            even samurai
dan@sidhe.org                           have teddy bears and even
                                        teddy bears get drunk



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About