Built-in primop for CAS on foreign data (Addr#)?
With large mutable pinned arrays appearing to lead to GC performance degradation (#18798), in trying to implement a concurrent mutable Bloom filter, I have to use foreign (allocated with
calloc(3)) memory, but I'd also like to use CAS, which is only supported for
MutableByteArray#. I expected to find this built-in, given that it would be essentially the same as
caseIntArray#, only slightly simpler, by not having to add an initial offset (as in the mutable byte array case).
Add a new primop (precise name TBD) that does what
casIntArray# does, but on raw
Addr# pointers to a suitably aligned block of memory.
I should note that after implementing a working prototype for 8.10, changes in the master branch indirectly led me (via
bits-atomic, which seems to provide CAS via FFI for GCC-based builds.
So the case for having CAS for
Addr# built-in, is perhaps that:
- Not dependent on GCC, uses the same machinery as CAS for
- No need for FFI wrappers.
- All the necessary code is basically already there—it just needs a slightly different front-end for the case where the array at hand is a raw pointer to foreign memory.
If I were to provide an implementation (with tests, ...), would there be interest in adopting such a new primop?