lkml.org 
[lkml]   [2006]   [Jul]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC/PATCH] Introduce list_get() and list_get_tail()
    Date
    From: Dmitry Torokhov <dtor@mail.ru>

    Add primitives to access first and last elements of a list instead
    of accessng pointers directly.

    Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
    ---

    We have primitives to iterate over lists and to add/delete elements,
    why not for accessing head/tail?

    include/linux/list.h | 18 ++++++++++++++++++
    1 files changed, 18 insertions(+)

    Index: work/include/linux/list.h
    ===================================================================
    --- work.orig/include/linux/list.h
    +++ work/include/linux/list.h
    @@ -571,6 +571,24 @@ static inline void list_splice_init(stru
    prefetch(rcu_dereference((pos))->next), (pos) != (head); \
    (pos) = (pos)->next)

    +/**
    + * list_get - get first element in a list
    + * @head: the head of your list
    + */
    +static inline struct list_head *list_get(struct list_head *head)
    +{
    + return head->next;
    +}
    +
    +/**
    + * list_get_tail - get last element in a list
    + * @head: the head of your list
    + */
    +static inline struct list_head *list_get_tail(struct list_head *head)
    +{
    + return head->prev;
    +}
    +
    /*
    * Double linked lists with a single pointer list head.
    * Mostly useful for hash tables where the two pointer list head is
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/
    \
     
     \ /
      Last update: 2006-07-08 07:29    [W:0.022 / U:60.240 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site