Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 188154
b: refs/heads/master
c: a2f46ee
h: refs/heads/master
v: v3
  • Loading branch information
Neil Horman authored and David S. Miller committed Mar 16, 2010
1 parent bd60dd0 commit dd28d36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c3259c8a7060d480e8eb2166da0a99d6879146b4
refs/heads/master: a2f46ee1ba5ee249ce2ca1ee7a7a0ac46529fb4f
26 changes: 16 additions & 10 deletions trunk/net/tipc/ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ void tipc_ref_table_stop(void)

u32 tipc_ref_acquire(void *object, spinlock_t **lock)
{
struct reference *entry;
u32 index;
u32 index_mask;
u32 next_plus_upper;
u32 ref;
struct reference *entry = NULL;

if (!object) {
err("Attempt to acquire reference to non-existent object\n");
Expand All @@ -175,30 +175,36 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
index = tipc_ref_table.first_free;
entry = &(tipc_ref_table.entries[index]);
index_mask = tipc_ref_table.index_mask;
/* take lock in case a previous user of entry still holds it */
spin_lock_bh(&entry->lock);
next_plus_upper = entry->ref;
tipc_ref_table.first_free = next_plus_upper & index_mask;
ref = (next_plus_upper & ~index_mask) + index;
entry->ref = ref;
entry->object = object;
*lock = &entry->lock;
}
else if (tipc_ref_table.init_point < tipc_ref_table.capacity) {
index = tipc_ref_table.init_point++;
entry = &(tipc_ref_table.entries[index]);
spin_lock_init(&entry->lock);
spin_lock_bh(&entry->lock);
ref = tipc_ref_table.start_mask + index;
entry->ref = ref;
entry->object = object;
*lock = &entry->lock;
}
else {
ref = 0;
}
write_unlock_bh(&ref_table_lock);

/*
* Grab the lock so no one else can modify this entry
* While we assign its ref value & object pointer
*/
if (entry) {
spin_lock_bh(&entry->lock);
entry->ref = ref;
entry->object = object;
*lock = &entry->lock;
/*
* keep it locked, the caller is responsible
* for unlocking this when they're done with it
*/
}

return ref;
}

Expand Down

0 comments on commit dd28d36

Please sign in to comment.