summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneal <neal>2008-02-15 10:57:01 +0000
committerneal <neal>2008-02-15 10:57:01 +0000
commitf92ba6e4c187946af90fd683b960edb11eed1417 (patch)
tree828cd774b6071cc23b8b0726cfef19f3a2b4241b
parent24e886a83566fc8f608f63aed1c1edcd1f269f37 (diff)
2008-02-15 Neal H. Walfield <neal@gnu.org>
* list.h (list_unlink): New function. (LIST_CLASS): Add above function to template. (LIST_CLASS_TYPE): New macro. (LIST_CLASS): Take additional argument need_type. If false, don't generate a type declaration. Update users.
-rw-r--r--viengoos/ChangeLog9
-rw-r--r--viengoos/list.h59
-rw-r--r--viengoos/object.h8
-rw-r--r--viengoos/t-link.c2
4 files changed, 70 insertions, 8 deletions
diff --git a/viengoos/ChangeLog b/viengoos/ChangeLog
index 4e1b415..950ea77 100644
--- a/viengoos/ChangeLog
+++ b/viengoos/ChangeLog
@@ -1,3 +1,12 @@
+2008-02-15 Neal H. Walfield <neal@gnu.org>
+
+ * list.h (list_unlink): New function.
+ (LIST_CLASS): Add above function to template.
+
+ (LIST_CLASS_TYPE): New macro.
+ (LIST_CLASS): Take additional argument need_type. If false, don't
+ generate a type declaration. Update users.
+
2008-02-13 Neal H. Walfield <neal@gnu.org>
* ia32-crt0.S (STACK_SIZE): Increase to 64 pages.
diff --git a/viengoos/list.h b/viengoos/list.h
index 3a64142..2ab9ea6 100644
--- a/viengoos/list.h
+++ b/viengoos/list.h
@@ -207,6 +207,40 @@ list_queue (struct list *list, struct list_node *item)
list->count ++;
}
+/* Insert ITEM after node NODE. If NODE is NULL, insert at the head
+ of the list. */
+static inline void
+list_insert_after (struct list *list, struct list_node *item,
+ struct list_node *node)
+{
+ /* We require that when an item is added to a list that its next and
+ previous pointers be NULL. This helps to catch when an item is
+ already on a list. */
+ assert (! item->next);
+ assert (! item->prev);
+
+ if (! node)
+ return list_push (list, item);
+
+ item->next = node->next;
+ node->next = item;
+ item->prev = node;
+
+ if (LIST_SENTINEL_P (item->next))
+ /* Item is the new last item on the list. Update the head of the
+ list's previous pointer to point to it. */
+ {
+ assert (LIST_SENTINEL_P (list->head->prev));
+ assert (LIST_PTR (list->head->prev) == node);
+
+ list->head->prev = LIST_SENTINEL (item);
+ }
+ else
+ item->next->prev = item;
+
+ list->count ++;
+}
+
static inline void
list_unlink (struct list *list, struct list_node *item)
{
@@ -323,7 +357,7 @@ list_join (struct list *target, struct list *source)
struct list_node *node;
}
- LIST_CLASS(foo, struct foo, node)
+ LIST_CLASS(foo, struct foo, node, true)
code corresponding to the following declaration is made available:
@@ -345,12 +379,21 @@ list_join (struct list *target, struct list *source)
void foo_list_move (struct foo_list *target, struct foo_list *source);
void foo_list_join (struct foo_list *target, struct foo_list *source);
*/
-#define LIST_CLASS(name, object_type, node_field) \
+/* Generates just the list type, not the methods. */
+#define LIST_CLASS_TYPE(name) \
struct name##_list \
{ \
struct list list; \
}; \
- typedef struct name##_list name##_list_t; \
+ typedef struct name##_list name##_list_t;
+
+#define LIST_CLASS_TYPE_need_type_true(name) LIST_CLASS_TYPE(name)
+#define LIST_CLASS_TYPE_need_type_false(name)
+
+/* If LIST_CLASS_TYPE(name) was used in scope, then pass false as the
+ value of need_type, otherwise true. */
+#define LIST_CLASS(name, object_type, node_field, need_type) \
+ LIST_CLASS_TYPE_need_type_##need_type(name) \
\
static inline void \
name##_list_init (struct name##_list *list) \
@@ -415,6 +458,16 @@ list_join (struct list *target, struct list *source)
} \
\
static inline void \
+ name##_list_insert_after (struct name##_list *list, \
+ object_type *item, \
+ object_type *after) \
+ { \
+ list_insert_after (&list->list, \
+ &item->node_field, \
+ after ? &after->node_field : NULL); \
+ } \
+ \
+ static inline void \
name##_list_unlink (struct name##_list *list, object_type *object) \
{ \
list_unlink (&list->list, &object->node_field); \
diff --git a/viengoos/object.h b/viengoos/object.h
index fc8ba1d..e68e805 100644
--- a/viengoos/object.h
+++ b/viengoos/object.h
@@ -194,11 +194,11 @@ struct object_desc
memory map. */
extern struct object_desc *object_descs;
-LIST_CLASS(activity_lru, struct object_desc, activity_node)
-LIST_CLASS(eviction, struct object_desc, activity_node)
+LIST_CLASS(activity_lru, struct object_desc, activity_node, true)
+LIST_CLASS(eviction, struct object_desc, activity_node, true)
-LIST_CLASS(available, struct object_desc, available_node)
-LIST_CLASS(laundry, struct object_desc, laundry_node)
+LIST_CLASS(available, struct object_desc, available_node, true)
+LIST_CLASS(laundry, struct object_desc, laundry_node, true)
/* Lock protecting the following lists as well as an activity's
lists. */
diff --git a/viengoos/t-link.c b/viengoos/t-link.c
index 6dcf7fc..dac3302 100644
--- a/viengoos/t-link.c
+++ b/viengoos/t-link.c
@@ -12,7 +12,7 @@ struct object_desc
struct list_node activity_lru;
};
-LIST_CLASS(object_activity_lru, struct object_desc, activity_lru)
+LIST_CLASS(object_activity_lru, struct object_desc, activity_lru, true)
int output_debug = 0;