Re: [PATCH 2/3] KVM: Use atomic_long_cmpxchg() instead of an open-coded variant

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/26/21 01:31, Maciej S. Szmigiero wrote:
-		if ((long)old == atomic_long_read(&slots->last_used_slot))
-			atomic_long_set(&slots->last_used_slot, (long)new);
+		/*
+		 * The atomicity isn't strictly required here since we are
+		 * operating on an inactive memslots set anyway.
+		 */
+		atomic_long_cmpxchg(&slots->last_used_slot,
+				    (unsigned long)old, (unsigned long)new);

I think using read/set is more readable than a comment saying that atomicity is not required.

It's a fairly common pattern, and while I agree that it's a PITA to write atomic_long_read and atomic_long_set, the person that reads the code is also helped by read/set, because they know they have to think about ownership invariants rather than concurrency invariants.

Paolo




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux