Browse Source

Moved load out of the loop, compare_exchange_weak will update the value so the load is redundant

Jorrit Rouwe 3 years ago
parent
commit
360db20371
1 changed files with 1 additions and 1 deletions
  1. 1 1
      Jolt/Core/LockFreeHashMap.inl

+ 1 - 1
Jolt/Core/LockFreeHashMap.inl

@@ -181,9 +181,9 @@ inline typename LockFreeHashMap<Key, Value>::KeyValue *LockFreeHashMap<Key, Valu
 	atomic<uint32> &offset = mBuckets[inKeyHash & (mNumBuckets - 1)];
 	atomic<uint32> &offset = mBuckets[inKeyHash & (mNumBuckets - 1)];
 
 
 	// Add this entry as the first element in the linked list
 	// Add this entry as the first element in the linked list
+	uint32 old_offset = offset.load(memory_order_relaxed);
 	for (;;)
 	for (;;)
 	{
 	{
-		uint32 old_offset = offset.load(memory_order_relaxed);
 		kv->mNextOffset = old_offset;
 		kv->mNextOffset = old_offset;
 		if (offset.compare_exchange_weak(old_offset, write_offset, memory_order_release))
 		if (offset.compare_exchange_weak(old_offset, write_offset, memory_order_release))
 			break;
 			break;