The function:
public func OSAtomicCompareAndSwapPtr(_ __oldValue: UnsafeMutableRawPointer!, _ __newValue: UnsafeMutableRawPointer!, ___theValue: UnsafeMutablePointer<UnsafeMutableRawPointer?>!) -> Bool
requires a type of UnsafeMutablePointer<UnsafeMutableRawPointer?>
for the a parameter theValue
but I'm having trouble figuring out how to make one from a type UnsafeMutablePointer<T?>
Any thoughts on how I could do this?
EDIT:
for the curious about why I am trying to do this, I am trying to create a generic wrapper around this to create a bounded MPMC queue in swift as outlined in this blog post. Here is my wrapper so far
func compareAndSwap<T: AnyObject>(current: T?, future: T?, toPtr: UnsafeMutablePointer<T?>) -> Bool {
let currentPtr = current.map(Unmanaged.passUnretained)?.toOpaque()
let futurePtr = future.map(Unmanaged.passRetained)?.toOpaque()
if OSAtomicCompareAndSwapPtr(currentPtr, futurePtr, ????) {
return true
}
return false