apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject cvs commit: apr/memory/unix apr_sms_tracking.c
Date Sun, 10 Jun 2001 21:33:45 GMT
dreid       01/06/10 14:33:45

  Modified:    memory/unix apr_sms_tracking.c
  Log:
  Remove the header I forgot to remove from Sanders last patch.
  
  Also, it's bugged me for a while now that we have identical code in
  a few places, so move the duplicate code to a macro and use that to
  simplify the code. Should make the file easier to maintain.
  
  Revision  Changes    Path
  1.11      +33 -54    apr/memory/unix/apr_sms_tracking.c
  
  Index: apr_sms_tracking.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms_tracking.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- apr_sms_tracking.c	2001/06/10 21:21:49	1.10
  +++ apr_sms_tracking.c	2001/06/10 21:33:45	1.11
  @@ -66,7 +66,6 @@
   #include "apr_sms.h"
   #include "apr_sms_tracking.h"
   #include "apr_lock.h"
  -#include <stdlib.h>
   
   static const char *module_identity = "TRACKING";
   
  @@ -88,6 +87,30 @@
       apr_lock_t          *lock;
   } apr_sms_tracking_t;
   
  +#define INSERT_NODE(node, tms) \
  +    if (tms->lock) \
  +        apr_lock_acquire(tms->lock); \
  +    \
  +    node->next = tms->nodes; \
  +    tms->nodes = node; \
  +    node->ref = &tms->nodes; \
  +    if (node->next) \
  +        node->next->ref = &node->next; \
  +    \
  +    if (tms->lock) \
  +        apr_lock_release(tms->lock);
  +    
  +#define REMOVE_NODE(node, tms) \
  +        if (tms->lock) \
  +            apr_lock_acquire(tms->lock); \
  +        \
  +        *(node->ref) = node->next; \
  +        if (node->next) \
  +            node->next->ref = node->ref; \
  +        \
  +        if (tms->lock) \
  +            apr_lock_release(tms->lock);
  +    
   static void *apr_sms_tracking_malloc(apr_sms_t *sms,
                                        apr_size_t size)
   {
  @@ -100,18 +123,9 @@
           return NULL;
   
       tms = (apr_sms_tracking_t *)sms;
  -    if (tms->lock)
  -        apr_lock_acquire(tms->lock);
  -
  -    node->next = tms->nodes;
  -    tms->nodes = node;
  -    node->ref = &tms->nodes;
  -    if (node->next)
  -        node->next->ref = &node->next;
   
  -    if (tms->lock)
  -        apr_lock_release(tms->lock);
  -
  +    INSERT_NODE(node, tms)
  +    
       node++;
   
       return (void *)node;
  @@ -129,17 +143,8 @@
           return NULL;
   
       tms = (apr_sms_tracking_t *)sms;
  -    if (tms->lock)
  -        apr_lock_acquire(tms->lock);
   
  -    node->next = tms->nodes;
  -    tms->nodes = node;
  -    node->ref = &tms->nodes;
  -    if (node->next)
  -        node->next->ref = &node->next;
  -
  -    if (tms->lock)
  -        apr_lock_release(tms->lock);
  +    INSERT_NODE(node, tms)
   
       node++;
   
  @@ -158,15 +163,7 @@
       if (node) {
           node--;
   
  -        if (tms->lock)
  -            apr_lock_acquire(tms->lock);
  -        
  -        *(node->ref) = node->next;
  -        if (node->next)
  -            node->next->ref = node->ref;
  -
  -        if (tms->lock)
  -            apr_lock_release(tms->lock);
  +        REMOVE_NODE(node, tms)
       }
   
       node = apr_sms_realloc(sms->parent,
  @@ -174,18 +171,8 @@
       if (!node)
           return NULL;
   
  -    if (tms->lock)
  -        apr_lock_acquire(tms->lock);
  -    
  -    node->next = tms->nodes;
  -    tms->nodes = node;
  -    node->ref = &tms->nodes;
  -    if (node->next)
  -        node->next->ref = &node->next;
  +    INSERT_NODE(node, tms)
   
  -    if (tms->lock)
  -        apr_lock_release(tms->lock);
  -    
       node++;
   
       return (void *)node;
  @@ -198,20 +185,12 @@
       apr_sms_tracking_t *tms;
      
       node = (apr_track_node_t *)mem;
  +    tms = (apr_sms_tracking_t *)sms;
  +
       node--;
   
  -    tms = (apr_sms_tracking_t *)sms;
  - 
  -    if (tms->lock)
  -        apr_lock_acquire(tms->lock);
  -
  -    *(node->ref) = node->next;
  -    if (node->next)
  -        node->next->ref = node->ref;
  - 
  -    if (tms->lock)
  -        apr_lock_release(tms->lock);
  -         
  +    REMOVE_NODE(node, tms);
  +
       return apr_sms_free(sms->parent, node);
   }
   
  
  
  

Mime
View raw message