You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by do...@apache.org on 2002/06/13 04:59:05 UTC

cvs commit: modperl-2.0/xs/APR/Pool APR__Pool.h

dougm       2002/06/12 19:59:05

  Modified:    .        Changes
               src/modules/perl modperl_interp.c modperl_interp.h
                        modperl_types.h
               xs/APR/Pool APR__Pool.h
  Log:
  add a reference count mechanism to interpreters for use in threaded MPMs,
  so if APR::Pool cleanups have been registered the interpreter is not
  putback into the interpreter pool until all cleanups have run.
  
  Revision  Changes    Path
  1.22      +4 -0      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- Changes	12 Jun 2002 23:37:55 -0000	1.21
  +++ Changes	13 Jun 2002 02:59:05 -0000	1.22
  @@ -10,6 +10,10 @@
   
   =item 1.99_03-dev
   
  +add a reference count mechanism to interpreters for use in threaded MPMs,
  +so if APR::Pool cleanups have been registered the interpreter is not
  +putback into the interpreter pool until all cleanups have run.
  +
   unbuffer STDERR (by turning on autoflush by default)
   
   add support for Perl*Handler +Apache::Foo
  
  
  
  1.43      +16 -0     modperl-2.0/src/modules/perl/modperl_interp.c
  
  Index: modperl_interp.c
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_interp.c,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- modperl_interp.c	30 May 2002 23:35:02 -0000	1.42
  +++ modperl_interp.c	13 Jun 2002 02:59:05 -0000	1.43
  @@ -44,6 +44,7 @@
           (modperl_interp_t *)apr_pcalloc(p, sizeof(*interp));
       
       interp->mip = mip;
  +    interp->refcnt = 0; /* for use by APR::Pool->cleanup_register */
   
       if (perl) {
   #ifdef MP_USE_GTOP
  @@ -232,6 +233,13 @@
       modperl_interp_t *interp = (modperl_interp_t *)data;
       modperl_interp_pool_t *mip = interp->mip;
   
  +    if (interp->refcnt != 0) {
  +        --interp->refcnt;
  +        MP_TRACE_i(MP_FUNC, "interp=0x%lx, refcnt=%d\n",
  +                   (unsigned long)interp, interp->refcnt);
  +        return APR_SUCCESS;
  +    }
  +
       if (interp->request) {
           /* ithreads + a threaded mpm + PerlInterpScope handler */
           request_rec *r = interp->request;
  @@ -243,6 +251,8 @@
       MpInterpIN_USE_Off(interp);
       MpInterpPUTBACK_Off(interp);
   
  +    MP_THX_INTERP_SET(interp->perl, NULL);
  +
       modperl_tipool_putback_data(mip->tipool, data, interp->num_requests);
   
       return APR_SUCCESS;
  @@ -393,6 +403,12 @@
   
       /* set context (THX) for this thread */
       PERL_SET_CONTEXT(interp->perl);
  +
  +#ifdef USE_ITHREADS
  +    if (scfg->threaded_mpm) {
  +        MP_THX_INTERP_SET(interp->perl, interp);
  +    }
  +#endif
   
       return interp;
   }
  
  
  
  1.15      +11 -0     modperl-2.0/src/modules/perl/modperl_interp.h
  
  Index: modperl_interp.h
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_interp.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- modperl_interp.h	21 Oct 2001 06:48:39 -0000	1.14
  +++ modperl_interp.h	13 Jun 2002 02:59:05 -0000	1.15
  @@ -8,6 +8,17 @@
   
   #ifdef USE_ITHREADS
   
  +/*
  + * HvPMROOT will never be used by Perl with PL_modglobal.
  + * so we have stolen it as a quick way to stash the interp
  + * pointer.
  + */
  +#define MP_THX_INTERP_GET(thx) \
  +    (modperl_interp_t *)HvPMROOT(*Perl_Imodglobal_ptr(thx))
  +
  +#define MP_THX_INTERP_SET(thx, interp) \
  +    HvPMROOT(*Perl_Imodglobal_ptr(thx)) = (PMOP*)interp
  +
   const char *modperl_interp_scope_desc(modperl_interp_scope_e scope);
   
   void modperl_interp_clone_init(modperl_interp_t *interp);
  
  
  
  1.58      +1 -0      modperl-2.0/src/modules/perl/modperl_types.h
  
  Index: modperl_types.h
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_types.h,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- modperl_types.h	19 May 2002 02:10:13 -0000	1.57
  +++ modperl_types.h	13 Jun 2002 02:59:05 -0000	1.58
  @@ -43,6 +43,7 @@
       int num_requests;
       U8 flags;
       request_rec *request;
  +    int refcnt;
   #ifdef MP_TRACE
       unsigned long tid;
   #endif
  
  
  
  1.5       +19 -2     modperl-2.0/xs/APR/Pool/APR__Pool.h
  
  Index: APR__Pool.h
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/xs/APR/Pool/APR__Pool.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- APR__Pool.h	8 May 2001 04:20:17 -0000	1.4
  +++ APR__Pool.h	13 Jun 2002 02:59:05 -0000	1.5
  @@ -8,13 +8,14 @@
       return retval;
   }
   
  -/* XXX: need to properly deal with PerlInterpScope */
  -
   typedef struct {
       SV *cv;
       SV *arg;
       apr_pool_t *p;
       PerlInterpreter *perl;
  +#ifdef USE_ITHREADS
  +    modperl_interp_t *interp;
  +#endif
   } mpxs_cleanup_t;
   
   static apr_status_t mpxs_cleanup_run(void *data)
  @@ -52,6 +53,16 @@
           SvREFCNT_dec(cdata->arg);
       }
   
  +#ifdef USE_ITHREADS
  +    if (cdata->interp) {
  +        /* this will decrement the interp refcnt until
  +         * there are no more references, in which case
  +         * the interpreter will be putback into the mip
  +         */
  +        (void)modperl_interp_unselect(cdata->interp);
  +    }
  +#endif
  +
       return status;
   }
   
  @@ -66,6 +77,12 @@
       data->p = p;
   #ifdef USE_ITHREADS
       data->perl = aTHX;
  +    /* make sure interpreter is not putback into the mip
  +     * until this cleanup has run.
  +     */
  +    if ((data->interp = MP_THX_INTERP_GET(data->perl))) {
  +        data->interp->refcnt++;
  +    }
   #endif
   
       apr_pool_cleanup_register(p, data,