Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions associate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
* @syncronize().
*/
mutex_t lock;
/**
* Lock guarding the structure of the list. Only the first reference list
* in a chain uses it.
*/
ThinLock structureLock;
/**
* Array of references.
*/
Expand Down Expand Up @@ -135,12 +140,14 @@ static void setReference(struct reference_list *list,
case OBJC_ASSOCIATION_ASSIGN:
break;
}
// While inserting into the list, we need to lock it temporarily.
// While inserting into the list, we need to lock it temporarily. An
// existing reference is updated in place.
struct reference *r = findReference(list, key);
if (NULL == r)
{
auto lock = acquire_locks_for_pointers(list);
// If there's an existing reference, then we can update it, otherwise we
// have to install a new one
std::lock_guard<ThinLock> lock{list->structureLock};
// Another thread may have installed this key since the search above.
r = findReference(list, key);
if (NULL == r)
{
// Search for an unused slot
Expand Down