[rrd-developers] Re: status of threaded RRDTool and Perl

Ole Bjørn Hessen obh at telenor.net
Sat Nov 26 00:05:16 MET 2005


Eric ZYLBERSTEJN <ezylby at yahoo.fr> writes:
> Implementing the thread safe API is of course possible
> in XS. It requires a little bit more coding because
> the API is not as generic as before.
> Since some parameters are now required and in a
> specific order, it could break a lot of the present
> Perl code. One way to circumvent that could be to keep
> the low level MT implementation in XS and offer a
> compatible higher layer in Perl which decodes the
> variable arguments list and calls the lower layer.

Yes, I came to the same conclusion. But there's a but here. Only a few
of these functions are thread-safe yet. 

Perhaps the best way is to start on a new XS perl-binding exposing the
low level function in a new module with different names so it can be
extended one by one function until it is finished.

I startet on a RRDts.pm and perl-shared-thread/RRDts.xs binding below
defining rrd_error_r, rrd_update_r and rrd_create_r, but I'm not sure
if I want to do more than this.

Ole Bjørn.


rocs3(obh) perl-shared-thread 1199$ cat RRDts.xs
#ifdef __cplusplus
extern "C" {
#endif

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#ifdef __cplusplus
}
#endif

#include "../../src/rrd_tool.h"
#include "../../src/rrd_is_thread_safe.h"

#define MALLOC_COPY_STRING(sv,var) \
        { \
                STRLEN len;\
                char *handle= SvPV(sv,len); \
                var = savepvn(handle, len); \
                if (! (var)) \
                        XSRETURN_UNDEF; \
        }

#define INITIALIZE_COPY(n) \
        int i;\
        char **argv;\
        struct rrd_context *context = rrd_get_context(); \
        int start = (n)

#define COPY_ARGS(start) \
        New(0, argv, items+1, char *); \
        if (!argv) \
                XSRETURN_UNDEF; \
        for (i = start; i < items; i++) { \
                MALLOC_COPY_STRING(ST(i), argv[i-start]); \
        } \
        argv[items] = NULL

#define FREE_ARGS(start) \
        for (i=start; i < items; i++) {\
                Safefree(argv[i-start]); \
        } \
        Safefree(argv)



/*
 * should not be needed if libc is linked (see ntmake.pl)
#ifdef WIN32
 #define free free
 #define malloc malloc
 #define realloc realloc
#endif
*/


MODULE = RRDts  PACKAGE = RRDts PREFIX = rrd_
PROTOTYPES: ENABLE


BOOT:
#ifdef MUST_DISABLE_SIGFPE
        signal(SIGFPE,SIG_IGN);
#endif
#ifdef MUST_DISABLE_FPMASK
        fpsetmask(0);
#endif 


SV*
rrd_error_r()
        PREINIT:

        CODE:
                if (! rrd_test_error()) XSRETURN_UNDEF;
                RETVAL = newSVpv(rrd_get_error(),0);
        OUTPUT:
                RETVAL


int
rrd_create_r(filename, pdp_step, last_up, ...)
        char *filename;
        unsigned long pdp_step;
        time_t last_up;
        PREINIT:
        INITIALIZE_COPY(3);
        CODE:
                COPY_ARGS(3);
                rrd_clear_error();
                RETVAL=rrd_create_r(filename, pdp_step, last_up, items-3,argv);
                FREE_ARGS(3);
                if (rrd_test_error()) 
                        XSRETURN_UNDEF;
                RETVAL = 1;
        OUTPUT:
                RETVAL

int
rrd_update_r(filename, _template, ...)
        char *filename;
        SV *_template;
        PREINIT:
        char *template;
        char *filex;
        INITIALIZE_COPY(2);
        CODE:
                if (SvOK(_template))
                {
                        MALLOC_COPY_STRING(_template, template);
                } else {
                        template = NULL;
                }
                filex = savepvn(filename, strlen(filename));
                COPY_ARGS(2);
                rrd_clear_error();
                RETVAL=rrd_update_r(filex, template, items-2, argv);
                if (template)
                        Safefree(template);
                Safefree(filex);
                FREE_ARGS(2);
                if (rrd_test_error()) 
                        XSRETURN_UNDEF;
                RETVAL = 1;
        OUTPUT:
                RETVAL

--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://lists.ee.ethz.ch/rrd-developers
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi



More information about the rrd-developers mailing list