| ... | @@ -43,9 +43,15 @@ const SpinlockTable = struct { | ... | @@ -43,9 +43,15 @@ const SpinlockTable = struct { |
| 43 | const max_spinlocks = 64; | 43 | const max_spinlocks = 64; |
| 44 | | 44 | |
| 45 | const Spinlock = struct { | 45 | const Spinlock = struct { |
| | 46 | // SPARC ldstub instruction will write a 255 into the memory location. |
| | 47 | // We'll use that as a sign that the lock is currently held. |
| | 48 | // See also: Section B.7 in SPARCv8 spec & A.29 in SPARCv9 spec. |
| | 49 | const sparc_lock: type = enum(u8) { Unlocked = 0, Locked = 255 }; |
| | 50 | const other_lock: type = enum(usize) { Unlocked = 0, Locked }; |
| | 51 | |
| 46 | // Prevent false sharing by providing enough padding between two | 52 | // Prevent false sharing by providing enough padding between two |
| 47 | // consecutive spinlock elements | 53 | // consecutive spinlock elements |
| 48 | v: if (arch.isSPARC()) enum(u8) { Unlocked = 0, Locked = 255 } else enum(usize) { Unlocked = 0, Locked } align(cache_line_size) = .Unlocked, | 54 | v: if (arch.isSPARC()) sparc_lock else other_lock align(cache_line_size) = .Unlocked, |
| 49 | | 55 | |
| 50 | fn acquire(self: *@This()) void { | 56 | fn acquire(self: *@This()) void { |
| 51 | while (true) { | 57 | while (true) { |