Subversion Repositories HelenOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2001-2004 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup genericadt
  30.  * @{
  31.  */
  32. /** @file listrcu.h
  33.  * @brief provides macro definitions for use with the RCU. Macros take care of memory barriers.
  34.  */
  35.  
  36. #ifndef KERN_LISTRCU_H_
  37. #define KERN_LISTRCU_H_
  38.  
  39. #include <arch/types.h>
  40. #include <adt/list.h>
  41. #include <synch/rcu.h>
  42.  
  43.  
  44. /** Add item to the beginning of doubly-linked circular list. Emits write barriers.
  45.  *
  46.  * Add item to the beginning of doubly-linked circular list.
  47.  *
  48.  * @param link Pointer to link_t structure to be added.
  49.  * @param head Pointer to link_t structure representing head of the list.
  50.  */
  51. static inline void list_prepend_rcu(link_t *link, link_t *head)
  52. {
  53.     rcu_assign_pointer(link->next,head->next);
  54.     link->prev = head;
  55.     head->next->prev = link;
  56.     rcu_assign_pointer(head->next,link);
  57. }
  58.  
  59. /** Add item to the end of doubly-linked circular list
  60.  *
  61.  * Add item to the end of doubly-linked circular list.
  62.  *
  63.  * @param link Pointer to link_t structure to be added.
  64.  * @param head Pointer to link_t structure representing head of the list.
  65.  */
  66. static inline void list_append_rcu(link_t *link, link_t *head)
  67. {
  68.     link->prev = head->prev;
  69.     rcu_assign_pointer(link->next,head);
  70.     rcu_assign_pointer(head->prev->next,link);
  71.     head->prev = link;
  72. }
  73.  
  74. /** Remove item from doubly-linked circular list
  75.  *
  76.  * Remove item from doubly-linked circular list.
  77.  *
  78.  * @param link  Pointer to link_t structure to be removed from the list it is
  79.  *      contained in.
  80.  */
  81. static inline void list_remove_rcu(link_t *link)
  82. {
  83.     link->next->prev = link->prev;
  84.     rcu_assign_pointer(link->prev->next,link->next);
  85.     link_initialize(link);
  86. }
  87.  
  88.  
  89.  
  90. /** Split or concatenate headless doubly-linked circular list
  91.  *
  92.  * Split or concatenate headless doubly-linked circular list.
  93.  *
  94.  * Note that the algorithm works both directions:
  95.  * concatenates splitted lists and splits concatenated lists.
  96.  *
  97.  * @param part1 Pointer to link_t structure leading the first (half of the
  98.  *      headless) list.
  99.  * @param part2 Pointer to link_t structure leading the second (half of the
  100.  *      headless) list.
  101.  */
  102. static inline void headless_list_split_or_concat_rcu(link_t *part1, link_t *part2)
  103. {
  104.     link_t *hlp;
  105.  
  106.     rcu_assign_pointer(part1->prev->next,part2);
  107.     rcu_assign_pointer(part2->prev->next,part1);   
  108.     hlp = part1->prev;
  109.     part1->prev = part2->prev;
  110.     part2->prev = hlp;
  111. }
  112.  
  113.  
  114. /** Split headless doubly-linked circular list
  115.  *
  116.  * Split headless doubly-linked circular list.
  117.  *
  118.  * @param part1 Pointer to link_t structure leading the first half of the
  119.  *      headless list.
  120.  * @param part2 Pointer to link_t structure leading the second half of the
  121.  *      headless list.
  122.  */
  123. static inline void headless_list_split_rcu(link_t *part1, link_t *part2)
  124. {
  125.     headless_list_split_or_concat_rcu(part1, part2);
  126. }
  127.  
  128. /** Concatenate two headless doubly-linked circular lists
  129.  *
  130.  * Concatenate two headless doubly-linked circular lists.
  131.  *
  132.  * @param part1 Pointer to link_t structure leading the first headless list.
  133.  * @param part2 Pointer to link_t structure leading the second headless list.
  134.  */
  135. static inline void headless_list_concat_rcu(link_t *part1, link_t *part2)
  136. {
  137.     headless_list_split_or_concat_rcu(part1, part2);
  138. }
  139.  
  140. /** Copy the link structure */
  141. void copy_link_rcu(link_t * src, link_t* dest);
  142.  
  143. #define list_get_instance(link,type,member) \
  144.     ((type *)(((uint8_t *)(link)) - ((uint8_t *)&(((type *)NULL)->member))))
  145.  
  146. extern bool list_member_rcu(const link_t *link, const link_t *head);
  147. extern void list_concat_rcu(link_t *head1, link_t *head2);
  148.  
  149. #endif
  150.  
  151. /** @}
  152.  */
  153.