Author: stevehay
Date: Thu Oct 31 22:38:03 2013
New Revision: 1537745

URL: http://svn.apache.org/r1537745
Log:
Merged revision(s) 594612-607681 from perl/modperl/branches/threading:
This one makes PerlInterpScope more advisory. Using pnotes increment the 
refcnt of the interp thus binding it to the lifetime of the pnotes. So, using 
$c->pnotes binds the interp to the lifetime of the connection, $r->pnotes to 
the request lifetime.

$[rc]->pnotes_kill() can be used to prematurely drop pnotes and thus remove 
the binding.

Reviewed-By: gozer
Submittted-By: Torsten Foertsch <torsten.foert...@gmx.net>
Message-Id: <200710241945.25803.torsten.foert...@gmx.net>


........
Forgot to add the test case for a previous fix.

Reviewed-By: gozer
Submitted-By: Torsten Foertsch <torsten.foert...@gmx.net>
Message-Id: <200705101104.48324.torsten.foert...@gmx.net>


........

Added:
    perl/modperl/branches/httpd24threading/t/perl/ithreads3.t
      - copied unchanged from r607681, 
perl/modperl/branches/threading/t/perl/ithreads3.t
    perl/modperl/branches/httpd24threading/t/response/TestPerl/ithreads3.pm
      - copied unchanged from r607681, 
perl/modperl/branches/threading/t/response/TestPerl/ithreads3.pm
Modified:
    perl/modperl/branches/httpd24threading/   (props changed)
    perl/modperl/branches/httpd24threading/Changes
    perl/modperl/branches/httpd24threading/src/modules/perl/modperl_types.h
    perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.c
    perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.h
    
perl/modperl/branches/httpd24threading/xs/Apache2/ConnectionUtil/Apache2__ConnectionUtil.h
    
perl/modperl/branches/httpd24threading/xs/Apache2/RequestUtil/Apache2__RequestUtil.h
    perl/modperl/branches/httpd24threading/xs/maps/modperl_functions.map
    
perl/modperl/branches/httpd24threading/xs/tables/current/ModPerl/FunctionTable.pm

Propchange: perl/modperl/branches/httpd24threading/
------------------------------------------------------------------------------
  Merged /perl/modperl/branches/threading:r594612-607681

Modified: perl/modperl/branches/httpd24threading/Changes
URL: 
http://svn.apache.org/viewvc/perl/modperl/branches/httpd24threading/Changes?rev=1537745&r1=1537744&r2=1537745&view=diff
==============================================================================
--- perl/modperl/branches/httpd24threading/Changes (original)
+++ perl/modperl/branches/httpd24threading/Changes Thu Oct 31 22:38:03 2013
@@ -12,6 +12,11 @@ Also refer to the Apache::Test changes l
 
 =item 2.0.9-dev
 
+PerlInterpScope is now more advisory. Using $(c|r)->pnotes will bind
+the current interpreter to that object for it's lifetime.
+$(c|r)->pnotes_kill() can be used to prematurely drop pnotes and
+remove this binding. [Torsten Foertsch]
+
 Now correctly invokes PerlCleanupHandlers, even if they are the only
 handler type configured for that request [Torsten Foertsch]
 

Modified: 
perl/modperl/branches/httpd24threading/src/modules/perl/modperl_types.h
URL: 
http://svn.apache.org/viewvc/perl/modperl/branches/httpd24threading/src/modules/perl/modperl_types.h?rev=1537745&r1=1537744&r2=1537745&view=diff
==============================================================================
--- perl/modperl/branches/httpd24threading/src/modules/perl/modperl_types.h 
(original)
+++ perl/modperl/branches/httpd24threading/src/modules/perl/modperl_types.h Thu 
Oct 31 22:38:03 2013
@@ -246,6 +246,14 @@ typedef struct {
 
 typedef struct {
     HV *pnotes;
+    apr_pool_t *pool;
+#ifdef USE_ITHREADS
+    modperl_interp_t *interp;
+#endif
+} modperl_pnotes_t;
+
+typedef struct {
+    modperl_pnotes_t pnotes;
     SV *global_request_obj;
     U8 flags;
     int status;
@@ -253,13 +261,10 @@ typedef struct {
     MpAV *handlers_per_dir[MP_HANDLER_NUM_PER_DIR];
     MpAV *handlers_per_srv[MP_HANDLER_NUM_PER_SRV];
     modperl_perl_globals_t perl_globals;
-#ifdef USE_ITHREADS
-    modperl_interp_t *interp;
-#endif
 } modperl_config_req_t;
 
 struct modperl_config_con_t {
-    HV *pnotes;
+    modperl_pnotes_t pnotes;
 #ifdef USE_ITHREADS
     modperl_interp_t *interp;
 #endif

Modified: perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.c
URL: 
http://svn.apache.org/viewvc/perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.c?rev=1537745&r1=1537744&r2=1537745&view=diff
==============================================================================
--- perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.c 
(original)
+++ perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.c Thu 
Oct 31 22:38:03 2013
@@ -855,30 +855,29 @@ apr_status_t modperl_cleanup_pnotes(void
     return APR_SUCCESS;
 }
 
-MP_INLINE
-static void *modperl_pnotes_cleanup_data(pTHX_ HV **pnotes, apr_pool_t *p) {
-#ifdef USE_ITHREADS
-    modperl_cleanup_pnotes_data_t *cleanup_data = apr_palloc(p, 
sizeof(*cleanup_data));
-    cleanup_data->pnotes = pnotes;
-    cleanup_data->perl = aTHX;
-    return cleanup_data;
-#else
-    return pnotes;
-#endif
-}
+void modperl_pnotes_kill(void *data) {
+    modperl_pnotes_t *pnotes = data;
 
-SV *modperl_pnotes(pTHX_ HV **pnotes, SV *key, SV *val,
-                   request_rec *r, conn_rec *c) {
-    SV *retval = (SV *)NULL;
+    if( !pnotes->pnotes ) return;
 
-    if (!*pnotes) {
-        apr_pool_t *pool = r ? r->pool : c->pool;
-        void *cleanup_data;
-        *pnotes = newHV();
+    apr_pool_cleanup_kill(pnotes->pool, pnotes, modperl_cleanup_pnotes);
+    modperl_cleanup_pnotes(pnotes);
+}
 
-        cleanup_data = modperl_pnotes_cleanup_data(aTHX_ pnotes, pool);
+SV *modperl_pnotes(pTHX_ modperl_pnotes_t *pnotes, SV *key, SV *val,
+                   apr_pool_t *pool) {
+    SV *retval = (SV *)NULL;
 
-        apr_pool_cleanup_register(pool, cleanup_data,
+    if (!pnotes->pnotes) {
+        pnotes->pool = pool;
+#ifdef USE_ITHREADS
+        pnotes->interp = MP_THX_INTERP_GET(aTHX);
+        pnotes->interp->refcnt++;
+        MP_TRACE_i(MP_FUNC, "TO: (0x%lx)->refcnt incremented to %ld",
+                   pnotes->interp, pnotes->interp->refcnt);
+#endif
+        pnotes->pnotes = newHV();
+        apr_pool_cleanup_register(pool, pnotes,
                                   modperl_cleanup_pnotes,
                                   apr_pool_cleanup_null);
     }
@@ -888,15 +887,15 @@ SV *modperl_pnotes(pTHX_ HV **pnotes, SV
         char *k = SvPV(key, len);
 
         if (val) {
-            retval = *hv_store(*pnotes, k, len, SvREFCNT_inc(val), 0);
+            retval = *hv_store(pnotes->pnotes, k, len, SvREFCNT_inc(val), 0);
         }
-        else if (hv_exists(*pnotes, k, len)) {
-            retval = *hv_fetch(*pnotes, k, len, FALSE);
+        else if (hv_exists(pnotes->pnotes, k, len)) {
+            retval = *hv_fetch(pnotes->pnotes, k, len, FALSE);
         }
 
         return retval ? SvREFCNT_inc(retval) : &PL_sv_undef;
     }
-    return newRV_inc((SV *)*pnotes);
+    return newRV_inc((SV *)pnotes->pnotes);
 }
 
 U16 *modperl_code_attrs(pTHX_ CV *cv) {

Modified: perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.h
URL: 
http://svn.apache.org/viewvc/perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.h?rev=1537745&r1=1537744&r2=1537745&view=diff
==============================================================================
--- perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.h 
(original)
+++ perl/modperl/branches/httpd24threading/src/modules/perl/modperl_util.h Thu 
Oct 31 22:38:03 2013
@@ -134,8 +134,10 @@ void modperl_package_unload(pTHX_ const 
 void modperl_restart_count_inc(server_rec *base_server);
 int  modperl_restart_count(void);
 
-SV *modperl_pnotes(pTHX_ HV **pnotes, SV *key, SV *val,
-                   request_rec *r, conn_rec *c);
+void modperl_pnotes_kill(void *data);
+
+SV *modperl_pnotes(pTHX_ modperl_pnotes_t *pnotes, SV *key, SV *val,
+                  apr_pool_t *pool );
 
 U16 *modperl_code_attrs(pTHX_ CV *cv);
 

Modified: 
perl/modperl/branches/httpd24threading/xs/Apache2/ConnectionUtil/Apache2__ConnectionUtil.h
URL: 
http://svn.apache.org/viewvc/perl/modperl/branches/httpd24threading/xs/Apache2/ConnectionUtil/Apache2__ConnectionUtil.h?rev=1537745&r1=1537744&r2=1537745&view=diff
==============================================================================
--- 
perl/modperl/branches/httpd24threading/xs/Apache2/ConnectionUtil/Apache2__ConnectionUtil.h
 (original)
+++ 
perl/modperl/branches/httpd24threading/xs/Apache2/ConnectionUtil/Apache2__ConnectionUtil.h
 Thu Oct 31 22:38:03 2013
@@ -25,5 +25,19 @@ SV *mpxs_Apache2__Connection_pnotes(pTHX
         return &PL_sv_undef;
     }
     
-    return modperl_pnotes(aTHX_ &ccfg->pnotes, key, val, NULL, c);
+    return modperl_pnotes(aTHX_ &ccfg->pnotes, key, val, c->pool);
+}
+
+static MP_INLINE
+void mpxs_Apache2__Connection_pnotes_kill(pTHX_ conn_rec *c)
+{
+    MP_dCCFG;
+
+    modperl_config_con_init(c, ccfg);
+
+    if (!ccfg) {
+        return;
+    }
+
+    modperl_pnotes_kill(&ccfg->pnotes);
 }

Modified: 
perl/modperl/branches/httpd24threading/xs/Apache2/RequestUtil/Apache2__RequestUtil.h
URL: 
http://svn.apache.org/viewvc/perl/modperl/branches/httpd24threading/xs/Apache2/RequestUtil/Apache2__RequestUtil.h?rev=1537745&r1=1537744&r2=1537745&view=diff
==============================================================================
--- 
perl/modperl/branches/httpd24threading/xs/Apache2/RequestUtil/Apache2__RequestUtil.h
 (original)
+++ 
perl/modperl/branches/httpd24threading/xs/Apache2/RequestUtil/Apache2__RequestUtil.h
 Thu Oct 31 22:38:03 2013
@@ -212,7 +212,19 @@ SV *mpxs_Apache2__RequestRec_pnotes(pTHX
         return &PL_sv_undef;
     }
 
-    return modperl_pnotes(aTHX_ &rcfg->pnotes, key, val, r, NULL);
+    return modperl_pnotes(aTHX_ &rcfg->pnotes, key, val, r->pool);
+}
+
+static MP_INLINE
+void mpxs_Apache2__RequestRec_pnotes_kill(pTHX_ request_rec *r)
+{
+    MP_dRCFG;
+
+    if (!rcfg) {
+        return;
+    }
+
+    modperl_pnotes_kill(&rcfg->pnotes);
 }
 
 #define mpxs_Apache2__RequestRec_dir_config(r, key, sv_val) \

Modified: perl/modperl/branches/httpd24threading/xs/maps/modperl_functions.map
URL: 
http://svn.apache.org/viewvc/perl/modperl/branches/httpd24threading/xs/maps/modperl_functions.map?rev=1537745&r1=1537744&r2=1537745&view=diff
==============================================================================
--- perl/modperl/branches/httpd24threading/xs/maps/modperl_functions.map 
(original)
+++ perl/modperl/branches/httpd24threading/xs/maps/modperl_functions.map Thu 
Oct 31 22:38:03 2013
@@ -40,6 +40,7 @@ MODULE=Apache2::RequestUtil   PACKAGE=gu
  mpxs_Apache2__RequestRec_location
  mpxs_Apache2__RequestRec_as_string
  mpxs_Apache2__RequestRec_pnotes | | r, key=(SV *)NULL, val=(SV *)NULL
+ mpxs_Apache2__RequestRec_pnotes_kill | | r
  mpxs_Apache2__RequestRec_add_config | | r, lines, 
override=MP_HTTPD_OVERRIDE_HTACCESS, path=NULL, 
override_options=MP_HTTPD_OVERRIDE_OPTS_UNSET
  mpxs_Apache2__RequestRec_document_root | | r, new_root=(SV *)NULL
  mpxs_Apache2__RequestRec_child_terminate
@@ -105,6 +106,7 @@ MODULE=Apache2::Connection
 
 MODULE=Apache2::ConnectionUtil   PACKAGE=guess
  mpxs_Apache2__Connection_pnotes | | c, key=(SV *)NULL, val=(SV *)NULL
+ mpxs_Apache2__Connection_pnotes_kill | | c
 
 MODULE=Apache2::Filter
  modperl_filter_attributes | MPXS_ | ... | MODIFY_CODE_ATTRIBUTES

Modified: 
perl/modperl/branches/httpd24threading/xs/tables/current/ModPerl/FunctionTable.pm
URL: 
http://svn.apache.org/viewvc/perl/modperl/branches/httpd24threading/xs/tables/current/ModPerl/FunctionTable.pm?rev=1537745&r1=1537744&r2=1537745&view=diff
==============================================================================
--- 
perl/modperl/branches/httpd24threading/xs/tables/current/ModPerl/FunctionTable.pm
 (original)
+++ 
perl/modperl/branches/httpd24threading/xs/tables/current/ModPerl/FunctionTable.pm
 Thu Oct 31 22:38:03 2013
@@ -4460,7 +4460,17 @@ $ModPerl::FunctionTable = [
         'type' => 'request_rec *',
         'name' => 'r'
       }
-    ]    
+    ]
+  },
+  {
+    'return_type' => 'void',
+    'name' => 'modperl_pnotes_kill',
+    'args' => [
+      {
+        'type' => 'void *',
+        'name' => 'cl_data'
+      }
+    ]
   },
   {
     'return_type' => 'int',
@@ -6321,6 +6331,20 @@ $ModPerl::FunctionTable = [
     ]
   },
   {
+    'return_type' => 'void',
+    'name' => 'mpxs_Apache2__Connection_pnotes_kill',
+    'args' => [
+      {
+        'type' => 'PerlInterpreter *',
+        'name' => 'my_perl'
+      },
+      {
+        'type' => 'conn_rec *',
+        'name' => 'c'
+      }
+    ]
+  },
+  {
     'return_type' => 'SV *',
     'name' => 'mpxs_Apache2__Directive_as_hash',
     'attr' => [
@@ -7128,6 +7152,20 @@ $ModPerl::FunctionTable = [
     ]
   },
   {
+    'return_type' => 'void',
+    'name' => 'mpxs_Apache2__RequestRec_pnotes_kill',
+    'args' => [
+      {
+        'type' => 'PerlInterpreter *',
+        'name' => 'my_perl'
+      },
+      {
+        'type' => 'request_rec *',
+        'name' => 'r'
+      }
+    ]
+  },
+  {
     'return_type' => 'SV *',
     'name' => 'mpxs_Apache2__RequestRec_print',
     'args' => [


Reply via email to