Hi all!
I work with perl version 5.14.2-6ubuntu2.4.
Recently I had a problem writing a new XS module.

In my unsafe sighandler I want check, if PL_malloc_mutex is free, so I can work in my perl part of sighandler code. So, I try to compile this code:

1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5 #include "ppport.h"
6
7 MODULE = Timeout PACKAGE = Timeout
8
9 void
10 try_get_mutex()
11 CODE:
12 if (pthread_mutex_trylock(PL_malloc_mutex) == EBUSY) {
13 printf("Busy!\n");
14 } else {
15 printf("Free!\n");
16 }

But I have an error:
cc -c -I. -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" -fPIC "-I/usr/lib/perl/5.14/CORE" Timeout.c
Timeout.xs: In function ‘XS_Timeout_try_get_mutex’:
Timeout.xs:12:29: error: ‘PL_malloc_mutex’ undeclared (first use in this function)
Timeout.xs:12:29: note: each undeclared identifier is reported only once for each function it appears in
Makefile:334: recipe for target 'Timeout.o' failed
make: *** Timeout.o Error 1

shell returned 2

Including perlapi.h didn't help me.
Plase, help me, how can I get this var in my XS code?

In reply to PL_malloc_mutex in XS by finisterra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.