You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by "Philippe M. Chiasson" <go...@cpan.org> on 2002/03/11 17:31:14 UTC

TiPool: chicken and egg callback problem/question

I am almost done with my tipool implementation, and I just ran into this
little thing I had left for later.

How can I do this?

I am inside an XS function, and I must call a perl-land sub, no problem.
But as an argument to that perl fuction I must pass a reference to the
object in question. i.e.

$tipool->foo() translates in:

MPXS_tipool_foo(modperl_tipool_t *tp)

and in there I am trying to do:

PUSHMARK(sp)
rv = sv_setref_pv(sv_newmortal(), "ModPerl::TiPool", (void*)tp)
XPUSHs(rv);
PUTBACK;
retval = call_sv(...);

And it works fine, creating a temporary blessed reference back to
the tipool object for the perl ubroutine to play with.

PROBLEM: This creates another object being referenced to, with refcnt
of 1 and that object will eventually have to be destroyed, triggering
more then one call to DESTROY, and leading to annoying "attempt to free
unreferences scalar"

Am I just to tired, or did I just miss the way to create a temporary
reference to something, then throw that reference away (not leaking)
without affecting the referred-to object ?

I am stumped and I hope my problem makes sense ;-)

tired Gozer ;-)

--------------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'

Re: TiPool: chicken and egg callback problem/question

Posted by Doug MacEachern <do...@covalent.net>.
before you go any further, i meant to ask, have you looked at 
threads::shared yet?  i don't really understand the problem you're having, 
but i fear there's going to be far worse.  for example:

what PerlInterpreter is associated with the item in the tipool?  

how can an item created in one interpreter be used in another?

what happens when PerlInterpreter associated with item in tipool is 
removed (e.g. max requests)?

some of the reasons i hadn't gone forward with the interface.
i think threads::shared already solves these problems, but i haven't spent 
any time with it.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TiPool: chicken and egg callback problem/question

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Mon, Mar 11, 2002 at 01:46:57PM -0800, Doug MacEachern wrote:
> On Tue, 12 Mar 2002, Philippe M. Chiasson wrote:
> 
> > MPXS_tipool_foo(modperl_tipool_t *tp)
> 
> might be better to make that SV *tp, then you can just do:
>  
>  PUSHMARK(sp)
>  XPUSHs(tp);
>  PUTBACK;
>  retval = call_sv(...);
> 

Actually, this won't work ;-(

There is one aspect of the problem I forgot to mention.

This perl callback is itself called from the tipool grow/shring
callbacks, and once in there, I already lost the original RV *
to the tipool object.  Once again, chicken and egg problem.

Only think I can think of is at object creation, in the initial
new, to stash the tipool object about to be returned somewhere
in the callback data to be used later, but that would be messy.

I'd have to write the new as a pure XS() function and so on.

I have all tests working now, except for that annoying little
problem. Any more suggestions?

--------------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'

Re: TiPool: chicken and egg callback problem/question

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 12 Mar 2002, Philippe M. Chiasson wrote:

> MPXS_tipool_foo(modperl_tipool_t *tp)

might be better to make that SV *tp, then you can just do:
 
 PUSHMARK(sp)
 XPUSHs(tp);
 PUTBACK;
 retval = call_sv(...);


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org