striker 2003/10/30 03:29:17
Modified: memory/unix apr_pools.c
Log:
Submitted by: Joe Orton
Reviewed by: Greg Stein, Cliff Woolley, Sander Striker
* memory/unix/apr_pools.c
(list_insert, list_remove): new macros to do manipulation of lists
throughout the pools code.
Revision Changes Path
1.201 +26 -37 apr/memory/unix/apr_pools.c
Index: apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.200
retrieving revision 1.201
diff -u -r1.200 -r1.201
--- apr_pools.c 28 Sep 2003 16:43:44 -0000 1.200
+++ apr_pools.c 30 Oct 2003 11:29:17 -0000 1.201
@@ -615,6 +615,21 @@
}
#endif /* defined(NETWARE) */
+/* Node list management helper macros; list_insert() inserts 'node'
+ * before 'point'. */
+#define list_insert(node, point) do { \
+ node->ref = point->ref; \
+ *node->ref = node; \
+ node->next = point; \
+ point->ref = &node->next; \
+} while (0)
+
+/* list_remove() removes 'node' from its list. */
+#define list_remove(node) do { \
+ *node->ref = node->next; \
+ node->next->ref = node->ref; \
+} while (0)
+
/*
* Memory allocation
*/
@@ -638,8 +653,7 @@
node = active->next;
if (size < (apr_size_t)(node->endp - node->first_avail)) {
- *node->ref = node->next;
- node->next->ref = node->ref;
+ list_remove(node);
}
else {
if ((node = allocator_alloc(pool->allocator, size)) == NULL) {
@@ -655,10 +669,7 @@
mem = node->first_avail;
node->first_avail += size;
- node->ref = active->ref;
- *node->ref = node;
- node->next = active;
- active->ref = &node->next;
+ list_insert(node, active);
pool->active = node;
@@ -675,13 +686,8 @@
}
while (free_index < node->free_index);
- *active->ref = active->next;
- active->next->ref = active->ref;
-
- active->ref = node->ref;
- *active->ref = active;
- active->next = node;
- node->ref = &active->next;
+ list_remove(active);
+ list_insert(active, node);
return mem;
}
@@ -944,13 +950,9 @@
node = active->next;
if (!ps->got_a_new_node
&& size < (apr_size_t)(node->endp - node->first_avail)) {
- *node->ref = node->next;
- node->next->ref = node->ref;
- node->ref = active->ref;
- *node->ref = node;
- node->next = active;
- active->ref = &node->next;
+ list_remove(node);
+ list_insert(node, active);
node->free_index = 0;
@@ -967,13 +969,8 @@
}
while (free_index < node->free_index);
- *active->ref = active->next;
- active->next->ref = active->ref;
-
- active->ref = node->ref;
- *active->ref = active;
- active->next = node;
- node->ref = &active->next;
+ list_remove(active);
+ list_insert(active, node);
}
node = pool->active;
@@ -1058,10 +1055,7 @@
node->free_index = 0;
- node->ref = active->ref;
- *node->ref = node;
- node->next = active;
- active->ref = &node->next;
+ list_insert(node, active);
pool->active = node;
@@ -1079,13 +1073,8 @@
}
while (free_index < node->free_index);
- *active->ref = active->next;
- active->next->ref = active->ref;
-
- active->ref = node->ref;
- *active->ref = active;
- active->next = node;
- node->ref = &active->next;
+ list_remove(active);
+ list_insert(active, node);
return strp;
}