You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by st...@apache.org on 2001/07/03 13:07:47 UTC

cvs commit: apr/memory/unix sms_private.h apr_sms.c apr_sms_trivial.c

striker     01/07/03 04:07:45

  Modified:    include  apr_sms.h
               memory/unix sms_private.h apr_sms.c apr_sms_trivial.c
  Log:
  First step in adding dynamic locking to sms. The framework now starts
  off without locking.
  
  Revision  Changes    Path
  1.27      +27 -0     apr/include/apr_sms.h
  
  Index: apr_sms.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_sms.h,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- apr_sms.h	2001/07/02 22:22:52	1.26
  +++ apr_sms.h	2001/07/03 11:07:01	1.27
  @@ -68,6 +68,10 @@
   #include "apr_pools.h"
   #include "apr_lock.h"
   
  +#if APR_HAS_THREADS
  +#include "apr_portable.h"
  +#endif /* APR_HAS_THREADS */
  +
   #ifdef __cplusplus
   extern "C" {
   #endif
  @@ -346,6 +350,29 @@
    */
   APR_DECLARE(apr_status_t) apr_sms_cleanup_run_type(apr_sms_t *sms, 
                                                      apr_int32_t type);
  +
  +#if APR_HAS_THREADS
  +/**
  + * Register the specified thread with the sms
  + * @param sms The memory system the thread is to be registered with
  + * @param thread The thread to register
  + * @deffunc apr_status_t apr_sms_thread_register(apr_sms_t *sms, 
  + *                                               apr_os_thread_t thread);
  + */
  +APR_DECLARE(apr_status_t) apr_sms_thread_register(apr_sms_t *sms, 
  +                                                  apr_os_thread_t thread);
  +
  +/**
  + * Unregister a previously registered thread from the sms
  + * @param sms The memory system the thread is to be unregistered from
  + * @param thread The thread to unregister
  + * @deffunc apr_status_t apr_sms_thread_unregister(apr_sms_t *sms, 
  + *                                                 apr_os_thread_t thread);
  + */
  +APR_DECLARE(apr_status_t) apr_sms_thread_unregister(apr_sms_t *sms, 
  +                                                    apr_os_thread_t thread);
  +
  +#endif /* APR_HAS_THREADS */
   
   /**********************************************************************
    ** Standard SMS module
  
  
  
  1.4       +9 -0      apr/memory/unix/sms_private.h
  
  Index: sms_private.h
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/sms_private.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- sms_private.h	2001/07/02 09:01:38	1.3
  +++ sms_private.h	2001/07/03 11:07:17	1.4
  @@ -59,6 +59,7 @@
   #include "apr_errno.h"
   #include "apr_pools.h"
   #include "apr_lock.h"
  +#include "apr_portable.h"
   
   #ifdef __cplusplus
   extern "C" {
  @@ -91,6 +92,14 @@
       apr_status_t (*destroy_fn)     (apr_sms_t *sms);
       apr_status_t (*lock_fn)        (apr_sms_t *sms);
       apr_status_t (*unlock_fn)      (apr_sms_t *sms);
  +
  +#if APR_HAS_THREADS    
  +    apr_status_t (*thread_register_fn)   (apr_sms_t *sms, 
  +                                          apr_os_thread_t thread);
  +    apr_status_t (*thread_unregister_fn) (apr_sms_t *sms, 
  +                                          apr_os_thread_t thread);
  +    apr_uint16_t threads;
  +#endif /* APR_HAS_THREADS */
   
   #if APR_DEBUG_TAG_SMS
       const char *tag;
  
  
  
  1.35      +58 -4     apr/memory/unix/apr_sms.c
  
  Index: apr_sms.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- apr_sms.c	2001/07/02 22:22:50	1.34
  +++ apr_sms.c	2001/07/03 11:07:24	1.35
  @@ -287,6 +287,10 @@
        */
       sms->calloc_fn = apr_sms_default_calloc;
       
  +#if APR_HAS_THREADS
  +    sms->threads = 1;
  +#endif /* APR_HAS_THREADS */
  +    
       /* XXX - This should eventually be removed */
       apr_pool_create(&sms->pool, pms ? pms->pool : NULL);
   
  @@ -303,11 +307,14 @@
       apr_status_t rv;
   
       apr_sms_assert(sms);
  -
  -    /* Create the sms framework lock we'll use. */
  -    rv = apr_lock_create(&sms->sms_lock, APR_MUTEX, APR_LOCKALL,
  -                         NULL, sms->pool);
   
  +    rv = APR_SUCCESS;
  +    
  +#if APR_HAS_THREADS
  +    if (sms->thread_register_fn)
  +        rv = sms->thread_register_fn(sms, apr_os_thread_current());
  +#endif /* APR_HAS_THREADS */
  +    
   #if APR_DEBUG_SHOW_FUNCTIONS
       fprintf(dbg_file, "CREATE - sms %p [%s] has been created\n", 
               sms, sms->identity);
  @@ -830,6 +837,53 @@
       /* The cleanup function should have been registered previously */
       return rv;
   }
  +
  +#if APR_HAS_THREADS
  +APR_DECLARE(apr_status_t) apr_sms_thread_register(apr_sms_t *sms,
  +                                                  apr_os_thread_t thread)
  +{
  +    do {
  +        if (!sms->sms_lock) {
  +            /* Create the sms framework lock we'll use. */
  +            apr_lock_create(&sms->sms_lock, APR_MUTEX, APR_LOCKALL,
  +                            NULL, sms->pool);
  +        }
  +
  +        apr_lock_acquire(sms->sms_lock);
  +
  +        sms->threads++;
  +
  +        /* let the sms know about the thread if it is
  +         * interested (so it can protect its private
  +         * data with its own lock)
  +         */
  +        if (sms->thread_register_fn)
  +            sms->thread_register_fn(sms, thread);
  +
  +        apr_lock_release(sms->sms_lock);
  +
  +        sms = sms->parent;
  +    } while (sms);
  +
  +    return APR_SUCCESS;    
  +}
  +
  +APR_DECLARE(apr_status_t) apr_sms_thread_unregister(apr_sms_t *sms,
  +                                                    apr_os_thread_t thread)
  +{
  +    if (sms->sms_lock)
  +        apr_lock_acquire(sms->sms_lock);
  +    
  +    sms->threads--;
  +
  +    /* Even if the thread count hits one, we don't destroy the
  +     * lock for now
  +     */
  +
  +    if (sms->sms_lock)
  +        apr_lock_release(sms->sms_lock);
  +}
  +#endif /* APR_HAS_THREADS */
   
   APR_DECLARE(const char*) apr_sms_identity(apr_sms_t *sms)
   {
  
  
  
  1.7       +30 -6     apr/memory/unix/apr_sms_trivial.c
  
  Index: apr_sms_trivial.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms_trivial.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- apr_sms_trivial.c	2001/07/02 08:29:45	1.6
  +++ apr_sms_trivial.c	2001/07/03 11:07:28	1.7
  @@ -387,6 +387,26 @@
       return APR_SUCCESS;
   }
   
  +#if APR_HAS_THREADS
  +APR_DECLARE(apr_status_t) apr_sms_trivial_thread_register(
  +                                                      apr_sms_t *sms,
  +                                                      apr_os_thread_t thread)
  +{
  +    if (!SMS_TRIVIAL_T(sms)->lock && sms->threads > 1)
  +        return apr_lock_create(&SMS_TRIVIAL_T(sms)->lock,
  +                               APR_MUTEX, APR_LOCKALL,
  +                               NULL, sms->pool);
  +
  +    return APR_SUCCESS;
  +}
  +
  +APR_DECLARE(apr_status_t) apr_sms_trivial_thread_unregister(
  +                                                      apr_sms_t *sms,
  +                                                      apr_os_thread_t thread)
  +{
  +    return APR_SUCCESS;
  +}
  +#endif /* APR_HAS_THREADS */
   
   APR_DECLARE(apr_status_t) apr_sms_trivial_create(apr_sms_t **sms, 
                                                     apr_sms_t *pms)
  @@ -422,12 +442,16 @@
       if ((rv = apr_sms_init(new_sms, pms)) != APR_SUCCESS)
           return rv;
   
  -    new_sms->malloc_fn      = apr_sms_trivial_malloc;
  -    new_sms->free_fn        = apr_sms_trivial_free;
  -    new_sms->reset_fn       = apr_sms_trivial_reset;
  -    new_sms->pre_destroy_fn = apr_sms_trivial_pre_destroy;
  -    new_sms->destroy_fn     = apr_sms_trivial_destroy;
  -    new_sms->identity       = module_identity;
  +    new_sms->malloc_fn            = apr_sms_trivial_malloc;
  +    new_sms->free_fn              = apr_sms_trivial_free;
  +    new_sms->reset_fn             = apr_sms_trivial_reset;
  +    new_sms->pre_destroy_fn       = apr_sms_trivial_pre_destroy;
  +    new_sms->destroy_fn           = apr_sms_trivial_destroy;
  +#if APR_HAS_THREADS
  +    new_sms->thread_register_fn   = apr_sms_trivial_thread_register;
  +    new_sms->thread_unregister_fn = apr_sms_trivial_thread_unregister;
  +#endif /* APR_HAS_THREADS */
  +    new_sms->identity             = module_identity;
   
       node = NODE_T((char *)new_sms + SIZEOF_SMS_TRIVIAL_T);
       node->first_avail = (char *)node + SIZEOF_NODE_T;