mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
always use atomic refcounting
This commit is contained in:
parent
c21cf9b8d6
commit
a2b4f64c6e
1 changed files with 6 additions and 23 deletions
|
@ -179,10 +179,6 @@ pub const IncN = fn (?[*]u8, u64) callconv(.C) void;
|
||||||
pub const Dec = fn (?[*]u8) callconv(.C) void;
|
pub const Dec = fn (?[*]u8) callconv(.C) void;
|
||||||
|
|
||||||
const REFCOUNT_MAX_ISIZE: isize = 0;
|
const REFCOUNT_MAX_ISIZE: isize = 0;
|
||||||
// Only top bit set.
|
|
||||||
const REFCOUNT_IS_ATOMIC_MASK: isize = std.math.minInt(isize);
|
|
||||||
// All other bits of the refcount.
|
|
||||||
const REFCOUNT_VALUE_MASK = ~REFCOUNT_IS_ATOMIC_MASK;
|
|
||||||
|
|
||||||
pub const IntWidth = enum(u8) {
|
pub const IntWidth = enum(u8) {
|
||||||
U8 = 0,
|
U8 = 0,
|
||||||
|
@ -229,12 +225,7 @@ pub fn increfRcPtrC(ptr_to_refcount: *isize, amount: isize) callconv(.C) void {
|
||||||
ptr_to_refcount.* = refcount +% amount;
|
ptr_to_refcount.* = refcount +% amount;
|
||||||
},
|
},
|
||||||
.atomic => {
|
.atomic => {
|
||||||
// If the first bit of the refcount is set, this variable is atomic.
|
_ = @atomicRmw(isize, ptr_to_refcount, .Add, amount, .monotonic);
|
||||||
if (refcount & REFCOUNT_IS_ATOMIC_MASK != 0) {
|
|
||||||
_ = @atomicRmw(isize, ptr_to_refcount, .Add, amount, .monotonic);
|
|
||||||
} else {
|
|
||||||
ptr_to_refcount.* = refcount +% amount;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
}
|
}
|
||||||
|
@ -393,17 +384,9 @@ inline fn decref_ptr_to_refcount(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.atomic => {
|
.atomic => {
|
||||||
// If the first bit of the refcount is set, this variable is atomic.
|
const last = @atomicRmw(isize, &refcount_ptr[0], .Sub, 1, .monotonic);
|
||||||
if (refcount_ptr[0] & REFCOUNT_IS_ATOMIC_MASK != 0) {
|
if (last == 1) {
|
||||||
const last = @atomicRmw(isize, &refcount_ptr[0], .Sub, 1, .monotonic);
|
free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted);
|
||||||
if (last & REFCOUNT_VALUE_MASK == 1) {
|
|
||||||
free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
refcount_ptr[0] = refcount -% 1;
|
|
||||||
if (refcount == 1) {
|
|
||||||
free_ptr_to_refcount(refcount_ptr, alignment, elements_refcounted);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.none => unreachable,
|
.none => unreachable,
|
||||||
|
@ -437,7 +420,7 @@ pub inline fn rcUnique(refcount: isize) bool {
|
||||||
return refcount == 1;
|
return refcount == 1;
|
||||||
},
|
},
|
||||||
.atomic => {
|
.atomic => {
|
||||||
return refcount & REFCOUNT_VALUE_MASK == 1;
|
return refcount == 1;
|
||||||
},
|
},
|
||||||
.none => {
|
.none => {
|
||||||
return false;
|
return false;
|
||||||
|
@ -451,7 +434,7 @@ pub inline fn rcConstant(refcount: isize) bool {
|
||||||
return refcount == REFCOUNT_MAX_ISIZE;
|
return refcount == REFCOUNT_MAX_ISIZE;
|
||||||
},
|
},
|
||||||
.atomic => {
|
.atomic => {
|
||||||
return refcount & REFCOUNT_VALUE_MASK == REFCOUNT_MAX_ISIZE & REFCOUNT_VALUE_MASK;
|
return refcount == REFCOUNT_MAX_ISIZE;
|
||||||
},
|
},
|
||||||
.none => {
|
.none => {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue