aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/ref.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/ref.c')
-rw-r--r--net/tipc/ref.c81
1 files changed, 34 insertions, 47 deletions
diff --git a/net/tipc/ref.c b/net/tipc/ref.c
index 1853cca66c68..89cbab24d08f 100644
--- a/net/tipc/ref.c
+++ b/net/tipc/ref.c
@@ -36,30 +36,18 @@
36 36
37#include "core.h" 37#include "core.h"
38#include "ref.h" 38#include "ref.h"
39#include "port.h"
40#include "subscr.h"
41#include "name_distr.h"
42#include "name_table.h"
43#include "config.h"
44#include "discover.h"
45#include "bearer.h"
46#include "node.h"
47#include "bcast.h"
48 39
49/** 40/**
50 * struct reference - TIPC object reference entry 41 * struct reference - TIPC object reference entry
51 * @object: pointer to object associated with reference entry 42 * @object: pointer to object associated with reference entry
52 * @lock: spinlock controlling access to object 43 * @lock: spinlock controlling access to object
53 * @data: reference value for object (combines instance & array index info) 44 * @ref: reference value for object (combines instance & array index info)
54 */ 45 */
55 46
56struct reference { 47struct reference {
57 void *object; 48 void *object;
58 spinlock_t lock; 49 spinlock_t lock;
59 union { 50 u32 ref;
60 u32 next_plus_upper;
61 u32 reference;
62 } data;
63}; 51};
64 52
65/** 53/**
@@ -165,7 +153,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
165 u32 index; 153 u32 index;
166 u32 index_mask; 154 u32 index_mask;
167 u32 next_plus_upper; 155 u32 next_plus_upper;
168 u32 reference; 156 u32 ref;
169 157
170 if (!object) { 158 if (!object) {
171 err("Attempt to acquire reference to non-existent object\n"); 159 err("Attempt to acquire reference to non-existent object\n");
@@ -185,10 +173,10 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
185 index_mask = tipc_ref_table.index_mask; 173 index_mask = tipc_ref_table.index_mask;
186 /* take lock in case a previous user of entry still holds it */ 174 /* take lock in case a previous user of entry still holds it */
187 spin_lock_bh(&entry->lock); 175 spin_lock_bh(&entry->lock);
188 next_plus_upper = entry->data.next_plus_upper; 176 next_plus_upper = entry->ref;
189 tipc_ref_table.first_free = next_plus_upper & index_mask; 177 tipc_ref_table.first_free = next_plus_upper & index_mask;
190 reference = (next_plus_upper & ~index_mask) + index; 178 ref = (next_plus_upper & ~index_mask) + index;
191 entry->data.reference = reference; 179 entry->ref = ref;
192 entry->object = object; 180 entry->object = object;
193 spin_unlock_bh(&entry->lock); 181 spin_unlock_bh(&entry->lock);
194 *lock = &entry->lock; 182 *lock = &entry->lock;
@@ -197,17 +185,17 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
197 index = tipc_ref_table.init_point++; 185 index = tipc_ref_table.init_point++;
198 entry = &(tipc_ref_table.entries[index]); 186 entry = &(tipc_ref_table.entries[index]);
199 spin_lock_init(&entry->lock); 187 spin_lock_init(&entry->lock);
200 reference = tipc_ref_table.start_mask + index; 188 ref = tipc_ref_table.start_mask + index;
201 entry->data.reference = reference; 189 entry->ref = ref;
202 entry->object = object; 190 entry->object = object;
203 *lock = &entry->lock; 191 *lock = &entry->lock;
204 } 192 }
205 else { 193 else {
206 reference = 0; 194 ref = 0;
207 } 195 }
208 write_unlock_bh(&ref_table_lock); 196 write_unlock_bh(&ref_table_lock);
209 197
210 return reference; 198 return ref;
211} 199}
212 200
213/** 201/**
@@ -238,26 +226,25 @@ void tipc_ref_discard(u32 ref)
238 err("Attempt to discard reference to non-existent object\n"); 226 err("Attempt to discard reference to non-existent object\n");
239 goto exit; 227 goto exit;
240 } 228 }
241 if (entry->data.reference != ref) { 229 if (entry->ref != ref) {
242 err("Attempt to discard non-existent reference\n"); 230 err("Attempt to discard non-existent reference\n");
243 goto exit; 231 goto exit;
244 } 232 }
245 233
246 /* 234 /*
247 * mark entry as unused; increment upper bits of entry's data field 235 * mark entry as unused; increment instance part of entry's reference
248 * to invalidate any subsequent references 236 * to invalidate any subsequent references
249 */ 237 */
250 238
251 entry->object = NULL; 239 entry->object = NULL;
252 entry->data.next_plus_upper = (ref & ~index_mask) + (index_mask + 1); 240 entry->ref = (ref & ~index_mask) + (index_mask + 1);
253 241
254 /* append entry to free entry list */ 242 /* append entry to free entry list */
255 243
256 if (tipc_ref_table.first_free == 0) 244 if (tipc_ref_table.first_free == 0)
257 tipc_ref_table.first_free = index; 245 tipc_ref_table.first_free = index;
258 else 246 else
259 tipc_ref_table.entries[tipc_ref_table.last_free]. 247 tipc_ref_table.entries[tipc_ref_table.last_free].ref |= index;
260 data.next_plus_upper |= index;
261 tipc_ref_table.last_free = index; 248 tipc_ref_table.last_free = index;
262 249
263exit: 250exit:
@@ -271,15 +258,15 @@ exit:
271void *tipc_ref_lock(u32 ref) 258void *tipc_ref_lock(u32 ref)
272{ 259{
273 if (likely(tipc_ref_table.entries)) { 260 if (likely(tipc_ref_table.entries)) {
274 struct reference *r; 261 struct reference *entry;
275 262
276 r = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask]; 263 entry = &tipc_ref_table.entries[ref &
277 264 tipc_ref_table.index_mask];
278 if (likely(r->data.reference != 0)) { 265 if (likely(entry->ref != 0)) {
279 spin_lock_bh(&r->lock); 266 spin_lock_bh(&entry->lock);
280 if (likely((r->data.reference == ref) && (r->object))) 267 if (likely((entry->ref == ref) && (entry->object)))
281 return r->object; 268 return entry->object;
282 spin_unlock_bh(&r->lock); 269 spin_unlock_bh(&entry->lock);
283 } 270 }
284 } 271 }
285 return NULL; 272 return NULL;
@@ -292,15 +279,14 @@ void *tipc_ref_lock(u32 ref)
292void tipc_ref_unlock(u32 ref) 279void tipc_ref_unlock(u32 ref)
293{ 280{
294 if (likely(tipc_ref_table.entries)) { 281 if (likely(tipc_ref_table.entries)) {
295 struct reference *r; 282 struct reference *entry;
296
297 r = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask];
298 283
299 if (likely((r->data.reference == ref) && (r->object))) 284 entry = &tipc_ref_table.entries[ref &
300 spin_unlock_bh(&r->lock); 285 tipc_ref_table.index_mask];
286 if (likely((entry->ref == ref) && (entry->object)))
287 spin_unlock_bh(&entry->lock);
301 else 288 else
302 err("tipc_ref_unlock() invoked using " 289 err("Attempt to unlock non-existent reference\n");
303 "invalid reference\n");
304 } 290 }
305} 291}
306 292
@@ -311,11 +297,12 @@ void tipc_ref_unlock(u32 ref)
311void *tipc_ref_deref(u32 ref) 297void *tipc_ref_deref(u32 ref)
312{ 298{
313 if (likely(tipc_ref_table.entries)) { 299 if (likely(tipc_ref_table.entries)) {
314 struct reference *r; 300 struct reference *entry;
315 301
316 r = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask]; 302 entry = &tipc_ref_table.entries[ref &
317 if (likely(r->data.reference == ref)) 303 tipc_ref_table.index_mask];
318 return r->object; 304 if (likely(entry->ref == ref))
305 return entry->object;
319 } 306 }
320 return NULL; 307 return NULL;
321} 308}