Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2456 | hudecek | 1 | /* |
| 2 | * Copyright (c) 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 | |||
| 33 | /** |
||
| 34 | * @file listrcu.c |
||
| 35 | * @brief Functions completing doubly linked circular list protected by RCU implementation. |
||
| 36 | * |
||
| 37 | * This file contains some of the functions implementing doubly linked circular lists. |
||
| 38 | * Note that the implementation doesn't differ much as when traversing the list we use only next pointers. So changes can be considered atomic. |
||
| 39 | * However, this ADT is mostly implemented in @ref list.h and @ref listrcu.h. |
||
| 40 | */ |
||
| 41 | |||
| 42 | #include <adt/list.h> |
||
| 43 | #include <adt/listrcu.h> |
||
| 44 | #include <synch/rcu.h> |
||
| 45 | |||
| 46 | /** Check for membership |
||
| 47 | * |
||
| 48 | * Check whether link is contained in the list head. |
||
| 49 | * The membership is defined as pointer equivalence. |
||
| 50 | * |
||
| 51 | * @param link Item to look for. |
||
| 52 | * @param head List to look in. |
||
| 53 | * |
||
| 54 | * @return true if link is contained in head, false otherwise. |
||
| 55 | * |
||
| 56 | */ |
||
| 57 | bool list_member_rcu(const link_t *link, const link_t *head) |
||
| 58 | { |
||
| 59 | bool found = false; |
||
| 60 | rcu_read_lock(); |
||
| 61 | link_t *hlp = rcu_dereference_pointer(head).next; |
||
| 62 | |||
| 63 | while (hlp != head) { |
||
| 64 | if (hlp == link) { |
||
| 65 | found = true; |
||
| 66 | break; |
||
| 67 | } |
||
| 68 | hlp = rcu_dereference_pointer(hlp).next; |
||
| 69 | } |
||
| 70 | rcu_read_lock(); |
||
| 71 | |||
| 72 | return found; |
||
| 73 | } |
||
| 74 | |||
| 75 | |||
| 76 | /** Concatenate two lists |
||
| 77 | * |
||
| 78 | * Concatenate lists head1 and head2, producing a single |
||
| 79 | * list head1 containing items from both (in head1, head2 |
||
| 80 | * order) and empty list head2. |
||
| 81 | * |
||
| 82 | * @param head1 First list and concatenated output |
||
| 83 | * @param head2 Second list and empty output. |
||
| 84 | * |
||
| 85 | */ |
||
| 86 | void list_concat_rcu(link_t *head1, link_t *head2) |
||
| 87 | { |
||
| 88 | if (list_empty(head2)) |
||
| 89 | return; |
||
| 90 | |||
| 91 | head2->next->prev = head1->prev; |
||
| 92 | rcu_assign_pointer(head2->prev->next, head1); |
||
| 93 | rcu_assign_pointer(head1->prev->next, head2->next); |
||
| 94 | head1->prev = head2->prev; |
||
| 95 | list_initialize(head2); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** Copy the link structure */ |
||
| 99 | void copy_link_rcu(link_t * src, link_t* dest) |
||
| 100 | { |
||
| 101 | dest->next = src->next; |
||
| 102 | if (dest->next) |
||
| 103 | dest->next->prev = dest; |
||
| 104 | dest->prev = src->prev; |
||
| 105 | if (dest->prev) |
||
| 106 | dest->prev->next = dest; |
||
| 107 | } |
||
| 108 | |||
| 109 | /** @} |
||
| 110 | */ |