Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/ref.c: TIPC object registry code |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Per Liden | 593a5f2 | 2006-01-11 19:14:19 +0100 | [diff] [blame] | 4 | * Copyright (c) 1991-2006, Ericsson AB |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 5 | * Copyright (c) 2004-2007, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 10 | * |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. Neither the names of the copyright holders nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * Alternatively, this software may be distributed under the terms of the |
| 21 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 22 | * Software Foundation. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #include "core.h" |
| 38 | #include "ref.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 39 | |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 40 | /** |
| 41 | * struct reference - TIPC object reference entry |
| 42 | * @object: pointer to object associated with reference entry |
| 43 | * @lock: spinlock controlling access to object |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 44 | * @ref: reference value for object (combines instance & array index info) |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 45 | */ |
| 46 | |
| 47 | struct reference { |
| 48 | void *object; |
| 49 | spinlock_t lock; |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 50 | u32 ref; |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * struct tipc_ref_table - table of TIPC object reference entries |
| 55 | * @entries: pointer to array of reference entries |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 56 | * @capacity: array index of first unusable entry |
| 57 | * @init_point: array index of first uninitialized entry |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 58 | * @first_free: array index of first unused object reference entry |
| 59 | * @last_free: array index of last unused object reference entry |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 60 | * @index_mask: bitmask for array index portion of reference values |
| 61 | * @start_mask: initial value for instance value portion of reference values |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 62 | */ |
| 63 | |
| 64 | struct ref_table { |
| 65 | struct reference *entries; |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 66 | u32 capacity; |
| 67 | u32 init_point; |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 68 | u32 first_free; |
| 69 | u32 last_free; |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 70 | u32 index_mask; |
| 71 | u32 start_mask; |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 74 | /* |
| 75 | * Object reference table consists of 2**N entries. |
| 76 | * |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 77 | * State Object ptr Reference |
| 78 | * ----- ---------- --------- |
| 79 | * In use non-NULL XXXX|own index |
| 80 | * (XXXX changes each time entry is acquired) |
| 81 | * Free NULL YYYY|next free index |
| 82 | * (YYYY is one more than last used XXXX) |
| 83 | * Uninitialized NULL 0 |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 84 | * |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 85 | * Entry 0 is not used; this allows index 0 to denote the end of the free list. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 86 | * |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 87 | * Note that a reference value of 0 does not necessarily indicate that an |
| 88 | * entry is uninitialized, since the last entry in the free list could also |
| 89 | * have a reference value of 0 (although this is unlikely). |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 90 | */ |
| 91 | |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 92 | static struct ref_table tipc_ref_table = { NULL }; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 93 | |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 94 | static DEFINE_RWLOCK(ref_table_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 95 | |
| 96 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 97 | * tipc_ref_table_init - create reference table for objects |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 98 | */ |
| 99 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 100 | int tipc_ref_table_init(u32 requested_size, u32 start) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 101 | { |
| 102 | struct reference *table; |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 103 | u32 actual_size; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 104 | |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 105 | /* account for unused entry, then round up size to a power of 2 */ |
| 106 | |
| 107 | requested_size++; |
| 108 | for (actual_size = 16; actual_size < requested_size; actual_size <<= 1) |
| 109 | /* do nothing */ ; |
| 110 | |
| 111 | /* allocate table & mark all entries as uninitialized */ |
| 112 | |
| 113 | table = __vmalloc(actual_size * sizeof(struct reference), |
| 114 | GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 115 | if (table == NULL) |
| 116 | return -ENOMEM; |
| 117 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 118 | tipc_ref_table.entries = table; |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 119 | tipc_ref_table.capacity = requested_size; |
| 120 | tipc_ref_table.init_point = 1; |
| 121 | tipc_ref_table.first_free = 0; |
| 122 | tipc_ref_table.last_free = 0; |
| 123 | tipc_ref_table.index_mask = actual_size - 1; |
| 124 | tipc_ref_table.start_mask = start & ~tipc_ref_table.index_mask; |
| 125 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 126 | return TIPC_OK; |
| 127 | } |
| 128 | |
| 129 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 130 | * tipc_ref_table_stop - destroy reference table for objects |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 131 | */ |
| 132 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 133 | void tipc_ref_table_stop(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 134 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 135 | if (!tipc_ref_table.entries) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 136 | return; |
| 137 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 138 | vfree(tipc_ref_table.entries); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 139 | tipc_ref_table.entries = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 143 | * tipc_ref_acquire - create reference to an object |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 144 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 145 | * Return a unique reference value which can be translated back to the pointer |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 146 | * 'object' at a later time. Also, pass back a pointer to the lock protecting |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 147 | * the object, but without locking it. |
| 148 | */ |
| 149 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 150 | u32 tipc_ref_acquire(void *object, spinlock_t **lock) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 151 | { |
| 152 | struct reference *entry; |
| 153 | u32 index; |
| 154 | u32 index_mask; |
| 155 | u32 next_plus_upper; |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 156 | u32 ref; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 157 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 158 | if (!object) { |
| 159 | err("Attempt to acquire reference to non-existent object\n"); |
| 160 | return 0; |
| 161 | } |
| 162 | if (!tipc_ref_table.entries) { |
| 163 | err("Reference table not found during acquisition attempt\n"); |
| 164 | return 0; |
| 165 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 166 | |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 167 | /* take a free entry, if available; otherwise initialize a new entry */ |
| 168 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 169 | write_lock_bh(&ref_table_lock); |
| 170 | if (tipc_ref_table.first_free) { |
| 171 | index = tipc_ref_table.first_free; |
| 172 | entry = &(tipc_ref_table.entries[index]); |
| 173 | index_mask = tipc_ref_table.index_mask; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 174 | /* take lock in case a previous user of entry still holds it */ |
| 175 | spin_lock_bh(&entry->lock); |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 176 | next_plus_upper = entry->ref; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 177 | tipc_ref_table.first_free = next_plus_upper & index_mask; |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 178 | ref = (next_plus_upper & ~index_mask) + index; |
| 179 | entry->ref = ref; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 180 | entry->object = object; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 181 | spin_unlock_bh(&entry->lock); |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 182 | *lock = &entry->lock; |
| 183 | } |
| 184 | else if (tipc_ref_table.init_point < tipc_ref_table.capacity) { |
| 185 | index = tipc_ref_table.init_point++; |
| 186 | entry = &(tipc_ref_table.entries[index]); |
| 187 | spin_lock_init(&entry->lock); |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 188 | ref = tipc_ref_table.start_mask + index; |
| 189 | entry->ref = ref; |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 190 | entry->object = object; |
| 191 | *lock = &entry->lock; |
| 192 | } |
| 193 | else { |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 194 | ref = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 195 | } |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 196 | write_unlock_bh(&ref_table_lock); |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 197 | |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 198 | return ref; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 202 | * tipc_ref_discard - invalidate references to an object |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 203 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 204 | * Disallow future references to an object and free up the entry for re-use. |
| 205 | * Note: The entry's spin_lock may still be busy after discard |
| 206 | */ |
| 207 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 208 | void tipc_ref_discard(u32 ref) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 209 | { |
| 210 | struct reference *entry; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 211 | u32 index; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 212 | u32 index_mask; |
| 213 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 214 | if (!tipc_ref_table.entries) { |
| 215 | err("Reference table not found during discard attempt\n"); |
| 216 | return; |
| 217 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 218 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 219 | index_mask = tipc_ref_table.index_mask; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 220 | index = ref & index_mask; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 221 | entry = &(tipc_ref_table.entries[index]); |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 222 | |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 223 | write_lock_bh(&ref_table_lock); |
| 224 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 225 | if (!entry->object) { |
| 226 | err("Attempt to discard reference to non-existent object\n"); |
| 227 | goto exit; |
| 228 | } |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 229 | if (entry->ref != ref) { |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 230 | err("Attempt to discard non-existent reference\n"); |
| 231 | goto exit; |
| 232 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 233 | |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 234 | /* |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 235 | * mark entry as unused; increment instance part of entry's reference |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 236 | * to invalidate any subsequent references |
| 237 | */ |
| 238 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 239 | entry->object = NULL; |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 240 | entry->ref = (ref & ~index_mask) + (index_mask + 1); |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 241 | |
| 242 | /* append entry to free entry list */ |
| 243 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 244 | if (tipc_ref_table.first_free == 0) |
| 245 | tipc_ref_table.first_free = index; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 246 | else |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 247 | tipc_ref_table.entries[tipc_ref_table.last_free].ref |= index; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 248 | tipc_ref_table.last_free = index; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 249 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 250 | exit: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 251 | write_unlock_bh(&ref_table_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 254 | /** |
| 255 | * tipc_ref_lock - lock referenced object and return pointer to it |
| 256 | */ |
| 257 | |
| 258 | void *tipc_ref_lock(u32 ref) |
| 259 | { |
| 260 | if (likely(tipc_ref_table.entries)) { |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 261 | struct reference *entry; |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 262 | |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 263 | entry = &tipc_ref_table.entries[ref & |
| 264 | tipc_ref_table.index_mask]; |
| 265 | if (likely(entry->ref != 0)) { |
| 266 | spin_lock_bh(&entry->lock); |
| 267 | if (likely((entry->ref == ref) && (entry->object))) |
| 268 | return entry->object; |
| 269 | spin_unlock_bh(&entry->lock); |
Allan Stephens | 0089509 | 2008-04-16 18:21:47 -0700 | [diff] [blame] | 270 | } |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 271 | } |
| 272 | return NULL; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * tipc_ref_unlock - unlock referenced object |
| 277 | */ |
| 278 | |
| 279 | void tipc_ref_unlock(u32 ref) |
| 280 | { |
| 281 | if (likely(tipc_ref_table.entries)) { |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 282 | struct reference *entry; |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 283 | |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 284 | entry = &tipc_ref_table.entries[ref & |
| 285 | tipc_ref_table.index_mask]; |
| 286 | if (likely((entry->ref == ref) && (entry->object))) |
| 287 | spin_unlock_bh(&entry->lock); |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 288 | else |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 289 | err("Attempt to unlock non-existent reference\n"); |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * tipc_ref_deref - return pointer referenced object (without locking it) |
| 295 | */ |
| 296 | |
| 297 | void *tipc_ref_deref(u32 ref) |
| 298 | { |
| 299 | if (likely(tipc_ref_table.entries)) { |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 300 | struct reference *entry; |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 301 | |
Allan Stephens | bcff122 | 2008-04-16 18:22:20 -0700 | [diff] [blame] | 302 | entry = &tipc_ref_table.entries[ref & |
| 303 | tipc_ref_table.index_mask]; |
| 304 | if (likely(entry->ref == ref)) |
| 305 | return entry->object; |
Allan Stephens | 4784b7c | 2008-04-16 18:21:16 -0700 | [diff] [blame] | 306 | } |
| 307 | return NULL; |
| 308 | } |
| 309 | |