Changeset 40a468a in mainline


Ignore:
Timestamp:
2005-09-29T20:15:43Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
941d1e9
Parents:
2a9543d
Message:

Implement splitting and concatenation for headless doubly-linked circular lists.
This is going to be needed during implementation of buddy system operations for zones.
Add doxygen-style comments to all functions in list.h.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • include/list.h

    r2a9543d r40a468a  
    3838};
    3939
     40/** Initialize doubly-linked circular list link
     41 *
     42 * Initialize doubly-linked list link.
     43 *
     44 * @param link Pointer to link_t structure to be initialized.
     45 */
    4046static inline void link_initialize(link_t *link)
    4147{
     
    4450}
    4551
     52/** Initialize doubly-linked circular list
     53 *
     54 * Initialize doubly-linked circular list.
     55 *
     56 * @param head Pointer to link_t structure representing head of the list.
     57 */
    4658static inline void list_initialize(link_t *head)
    4759{
     
    5062}
    5163
     64/** Add item to the beginning of doubly-linked circular list
     65 *
     66 * Add item to the beginning of doubly-linked circular list.
     67 *
     68 * @param link Pointer to link_t structure to be added.
     69 * @param head Pointer to link_t structure representing head of the list.
     70 */
    5271static inline void list_prepend(link_t *link, link_t *head)
    5372{
     
    5877}
    5978
     79/** Add item to the end of doubly-linked circular list
     80 *
     81 * Add item to the end of doubly-linked circular list.
     82 *
     83 * @param link Pointer to link_t structure to be added.
     84 * @param head Pointer to link_t structure representing head of the list.
     85 */
    6086static inline void list_append(link_t *link, link_t *head)
    6187{
     
    6692}
    6793
     94/** Remove item from doubly-linked circular list
     95 *
     96 * Remove item from doubly-linked circular list.
     97 *
     98 * @param link Pointer to link_t structure to be removed from the list it is contained in.
     99 */
    68100static inline void list_remove(link_t *link)
    69101{
     
    73105}
    74106
    75 static inline bool list_empty(link_t *head) { return head->next == head ? true : false; }
     107/** Query emptiness of doubly-linked circular list
     108 *
     109 * Query emptiness of doubly-linked circular list.
     110 *
     111 * @param head Pointer to link_t structure representing head of the list.
     112 */
     113static inline bool list_empty(link_t *head)
     114{
     115        return head->next == head ? true : false;
     116}
     117
     118
     119/** Split or concatenate headless doubly-linked circular list
     120 *
     121 * Split or concatenate headless doubly-linked circular list.
     122 *
     123 * Note that the algorithm works both directions:
     124 * concatenates splitted lists and splits concatenated lists.
     125 *
     126 * @param part1 Pointer to link_t structure leading the first (half of the headless) list.
     127 * @param part2 Pointer to link_t structure leading the second (half of the headless) list.
     128 */
     129static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
     130{
     131        link_t *hlp;
     132
     133        part1->prev->next = part2;
     134        part2->prev->next = part1;     
     135        hlp = part1->prev;
     136        part1->prev = part2->prev;
     137        part2->prev = hlp;
     138}
     139
     140
     141/** Split headless doubly-linked circular list
     142 *
     143 * Split headless doubly-linked circular list.
     144 *
     145 * @param part1 Pointer to link_t structure leading the first half of the headless list.
     146 * @param part2 Pointer to link_t structure leading the second half of the headless list.
     147 */
     148static inline void headless_list_split(link_t *part1, link_t *part2)
     149{
     150        headless_list_split_or_concat(part1, part2);
     151}
     152
     153/** Concatenate two headless doubly-linked circular lists
     154 *
     155 * Concatenate two headless doubly-linked circular lists.
     156 *
     157 * @param part1 Pointer to link_t structure leading the first headless list.
     158 * @param part2 Pointer to link_t structure leading the second headless list.
     159 */
     160static inline void headless_list_concat(link_t *part1, link_t *part2)
     161{
     162        headless_list_split_or_concat(part1, part2);
     163}
    76164
    77165#define list_get_instance(link,type,member) (type *)(((__u8*)(link))-((__u8*)&(((type *)NULL)->member)))
Note: See TracChangeset for help on using the changeset viewer.