-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-System.ThreadingenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions
Milestone
Description
I recently needed to use Interlocked.CompareExchange inside a function with the following form:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool TryClaimSlot(ref uint entryKey, int key)
{
var entryKeyValue = entryKey;
//zero keys are claimed via hash
if (entryKeyValue == 0 & key != 0)
{
entryKeyValue = Interlocked.CompareExchange(ref entryKey, key, 0);
if (entryKeyValue == 0)
{
// claimed a new slot
this.allocatedSlotCount.Increment();
return true;
}
}
return key == entryKeyValue;
}problem is that it can´t be done because the Interlocked.CompareExchange<T> requires it to be a class.
Also if anyone knows a workaround for it, I would appreciate it.
Metadata
Metadata
Assignees
Labels
area-System.ThreadingenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additions