[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apreq-cvs
Subject:    svn commit: r164987 - in /httpd/apreq/trunk: CHANGES include/apreq.h
From:       joes () apache ! org
Date:       2005-04-27 14:56:39
Message-ID: 20050427145640.19233.qmail () minotaur ! apache ! org
[Download RAW message or body]

Author: joes
Date: Wed Apr 27 07:56:38 2005
New Revision: 164987

URL: http://svn.apache.org/viewcvs?rev=164987&view=rev
Log:
Replace rwthread locks with apreq_pre_initialize()
and apreq_post_initialize() functions.

Modified:
    httpd/apreq/trunk/CHANGES
    httpd/apreq/trunk/include/apreq.h
    httpd/apreq/trunk/library/parser.c
    httpd/apreq/trunk/module/apache2/filter.c
    httpd/apreq/trunk/module/apache2/handle.c

Modified: httpd/apreq/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/CHANGES?rev=164987&r1=164986&r2=164987&view=diff
 ==============================================================================
--- httpd/apreq/trunk/CHANGES (original)
+++ httpd/apreq/trunk/CHANGES Wed Apr 27 07:56:38 2005
@@ -5,6 +5,12 @@
 @section v2_05_dev Changes with libapreq2-2.05-dev
 
 
+- C API [joes, Max Kellermann]
+  Add apreq_initialize, apreq_pre_initialize and apreq_post_initialize.
+  These are not thread-safe operations, so applications need to ensure
+  they are invoked (in the correct sequence) prior to using any apreq2
+  modules.
+
 - C, Perl API [joes]
   Add pool, bucket_alloc to apreq_handle_t.
 
@@ -74,7 +80,6 @@
   - Convert apreq_cookie_name and apreq_cookie_value macros to inline.
   - Convert apreq_param_name, apreq_param_value, apreq_param_info, and
     apreq_param_brigade to inline.
-  - Add apreq_initialize to allow thread-safe parser registration.
 
 - C API [joes]
   Widespread API refactorization to remove apreq_jar_t and apreq_request_t:

Modified: httpd/apreq/trunk/include/apreq.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/include/apreq.h?rev=164987&r1=164986&r2=164987&view=diff
 ==============================================================================
--- httpd/apreq/trunk/include/apreq.h (original)
+++ httpd/apreq/trunk/include/apreq.h Wed Apr 27 07:56:38 2005
@@ -120,14 +120,40 @@
 
 /**
  * Initialize libapreq2. Applications (except apache modules using
- * mod_apreq) have to call this exactly once before they use
- * libapreq2.
+ * mod_apreq) should call this exactly once before they use any
+ * libapreq2 modules.  If you want to modify the list of default parsers
+ * with apreq_register_parser(), please use apreq_pre_initialize()
+ * and apreq_post_initialize() instead.
  *
  * @param pool a base pool persisting while libapreq2 is used
- * @remarks after you detroyed the pool, you have to call this function again
+ * @remarks after you detroy the pool, you have to call this function again
  *    with a new pool if you still plan to use libapreq2
  */
 APREQ_DECLARE(apr_status_t) apreq_initialize(apr_pool_t *pool);
+
+
+/**
+ * Pre-initialize libapreq2. Applications (except apache modules using
+ * mod_apreq2) should call this exactly once before they register custom
+ * parsers with libapreq2. mod_apreq2 does this automatically during the
+ * post-config phase, so modules that need call apreq_register_parser should
+ * create a post-config hook using APR_HOOK_MIDDLE.
+ *
+ * @param pool a base pool persisting while libapreq2 is used
+ * @remarks after you detroyed the pool, you have to call this function again
+ *    with a new pool if you still plan to use libapreq2
+ */
+APREQ_DECLARE(apr_status_t) apreq_pre_initialize(apr_pool_t *pool);
+
+/**
+ * Post-initialize libapreq2. Applications (except apache modules using
+ * mod_apreq2) should this exactly once before they use any
+ * libapreq2 modules for parsing.
+ *
+ * @param pool the same pool that was used in apreq_pre_initialize().
+ */
+APREQ_DECLARE(apr_status_t) apreq_post_initialize(apr_pool_t *pool);
+
 
 #ifdef __cplusplus
  }

Modified: httpd/apreq/trunk/library/parser.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/library/parser.c?rev=164987&r1=164986&r2=164987&view=diff
 ==============================================================================
--- httpd/apreq/trunk/library/parser.c (original)
+++ httpd/apreq/trunk/library/parser.c Wed Apr 27 07:56:38 2005
@@ -20,7 +20,6 @@
 #include "apr_strings.h"
 #include "apr_xml.h"
 #include "apr_hash.h"
-#include "apr_thread_rwlock.h"
 
 #define PARSER_STATUS_CHECK(PREFIX)   do {         \
     if (ctx->status == PREFIX##_ERROR)             \
@@ -81,23 +80,27 @@
     return APR_SUCCESS;
 }
 
-static apr_thread_rwlock_t *default_parsers_lock = NULL;
+static int default_parsers_lock = 0;
 static apr_hash_t *default_parsers = NULL;
 static apr_pool_t *default_parser_pool = NULL;
 
-static apr_status_t apreq_parsers_cleanup(void *data) {
-    default_parsers_lock = NULL;
+static apr_status_t apreq_parsers_cleanup(void *data)
+{
+    default_parsers_lock = 0;
     default_parsers = NULL;
     default_parser_pool = NULL;
 
     return APR_SUCCESS;
 }
 
-static apr_status_t apreq_parser_initialize(apr_pool_t *pool)
+APREQ_DECLARE(apr_status_t) apreq_pre_initialize(apr_pool_t *pool)
 {
     apr_status_t status;
 
     if (default_parser_pool != NULL)
+        return APR_SUCCESS;
+
+    if (default_parsers_lock)
         return APREQ_ERROR_GENERAL;
 
     status = apr_pool_create(&default_parser_pool, pool);
@@ -108,11 +111,6 @@
                               apreq_parsers_cleanup,
                               apr_pool_cleanup_null);
 
-    status = apr_thread_rwlock_create(&default_parsers_lock,
-                                      default_parser_pool);
-    if (status != APR_SUCCESS)
-        return status;
-
     default_parsers = apr_hash_make(default_parser_pool);
 
     apreq_register_parser("application/x-www-form-urlencoded",
@@ -123,14 +121,31 @@
     return APR_SUCCESS;
 }
 
-APREQ_DECLARE(apr_status_t) apreq_initialize(apr_pool_t *pool) {
-    return apreq_parser_initialize(pool);
+APREQ_DECLARE(apr_status_t) apreq_post_initialize(apr_pool_t *pool)
+{
+    (void)pool;
+
+    if (default_parser_pool == NULL)
+        return APREQ_ERROR_GENERAL;
+
+    default_parsers_lock = 1;
+    return APR_SUCCESS;
+}
+
+APREQ_DECLARE(apr_status_t) apreq_initialize(apr_pool_t *pool)
+{
+    apr_status_t s = apreq_pre_initialize(pool);
+
+    if (s != APR_SUCCESS)
+        return s;
+
+    return apreq_post_initialize(pool);
 }
 
+
 APREQ_DECLARE(apr_status_t) apreq_register_parser(const char *enctype,
                                                   apreq_parser_function_t pfn)
 {
-    apr_status_t status;
     apreq_parser_function_t *f = NULL;
 
     if (default_parsers == NULL)
@@ -139,9 +154,8 @@
     if (enctype == NULL)
         return APR_EINVAL;
 
-    status = apr_thread_rwlock_wrlock(default_parsers_lock);
-    if (status != APR_SUCCESS)
-        return status;
+    if (default_parsers_lock)
+        return APREQ_ERROR_GENERAL;
 
     if (pfn != NULL) {
         f = apr_palloc(default_parser_pool, sizeof *f);
@@ -150,30 +164,21 @@
     apr_hash_set(default_parsers, apr_pstrdup(default_parser_pool, enctype),
                  APR_HASH_KEY_STRING, f);
 
-    apr_thread_rwlock_unlock(default_parsers_lock);
-
     return APR_SUCCESS;
 }
 
 APREQ_DECLARE(apreq_parser_function_t)apreq_parser(const char *enctype)
 {
-    apr_status_t status;
     apreq_parser_function_t *f;
     apr_size_t tlen = 0;
 
-    if (enctype == NULL || default_parsers == NULL)
-        return NULL;
-
-    status = apr_thread_rwlock_rdlock(default_parsers_lock);
-    if (status != APR_SUCCESS)
+    if (enctype == NULL || default_parsers_lock == 0)
         return NULL;
 
     while(enctype[tlen] && enctype[tlen] != ';')
         ++tlen;
 
     f = apr_hash_get(default_parsers, enctype, tlen);
-
-    apr_thread_rwlock_unlock(default_parsers_lock);
 
     if (f != NULL)
         return *f;

Modified: httpd/apreq/trunk/module/apache2/filter.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/module/apache2/filter.c?rev=164987&r1=164986&r2=164987&view=diff
 ==============================================================================
--- httpd/apreq/trunk/module/apache2/filter.c (original)
+++ httpd/apreq/trunk/module/apache2/filter.c Wed Apr 27 07:56:38 2005
@@ -404,25 +404,45 @@
 }
 
 
-static int apreq_post_config(apr_pool_t *p, apr_pool_t *plog,
-                             apr_pool_t *ptemp, server_rec *base_server) {
+static int apreq_pre_init(apr_pool_t *p, apr_pool_t *plog,
+                          apr_pool_t *ptemp, server_rec *base_server)
+{
     apr_status_t status;
 
-    status = apreq_initialize(p);
+    status = apreq_pre_initialize(p);
     if (status != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_ERR, status, base_server,
-                     "Failed to initialize libapreq2");
+                     "Failed to pre-initialize libapreq2");
         return HTTP_INTERNAL_SERVER_ERROR;
     }
+    return OK;
+}
+
+static int apreq_post_init(apr_pool_t *p, apr_pool_t *plog,
+                           apr_pool_t *ptemp, server_rec *base_server)
+{
+    apr_status_t status;
 
+    status = apreq_post_initialize(p);
+    if (status != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_ERR, status, base_server,
+                     "Failed to post-initialize libapreq2");
+        return HTTP_INTERNAL_SERVER_ERROR;
+    }
     return OK;
 }
 
 static void register_hooks (apr_pool_t *p)
 {
     /* APR_HOOK_FIRST because we want other modules to be able to
-       register parsers in their post_config hook */
-    ap_hook_post_config(apreq_post_config, NULL, NULL, APR_HOOK_FIRST);
+     * register parsers in their post_config hook via APR_HOOK_MIDDLE.
+     */
+    ap_hook_post_config(apreq_pre_init, NULL, NULL, APR_HOOK_FIRST);
+
+    /* APR_HOOK_LAST because we need to lock the default_parsers hash
+     * (to prevent further modifications) before the server forks.
+     */
+    ap_hook_post_config(apreq_post_init, NULL, NULL, APR_HOOK_LAST);
 
     ap_register_input_filter(APREQ_FILTER_NAME, apreq_filter, apreq_filter_init,
                              AP_FTYPE_PROTOCOL-1);

Modified: httpd/apreq/trunk/module/apache2/handle.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/trunk/module/apache2/handle.c?rev=164987&r1=164986&r2=164987&view=diff
 ==============================================================================
--- httpd/apreq/trunk/module/apache2/handle.c (original)
+++ httpd/apreq/trunk/module/apache2/handle.c Wed Apr 27 07:56:38 2005
@@ -407,7 +407,7 @@
     return APR_SUCCESS;
 }
 
-static APREQ_MODULE(apache2, 20050425);
+static APREQ_MODULE(apache2, 20050427);
 
 APREQ_DECLARE(apreq_handle_t *) apreq_handle_apache2(request_rec *r)
 {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic