diff --git a/src/swift/Dispatch.apinotes b/src/swift/Dispatch.apinotes index 6e804515a..d40bb68a4 100644 --- a/src/swift/Dispatch.apinotes +++ b/src/swift/Dispatch.apinotes @@ -91,6 +91,8 @@ Protocols: SwiftName: DispatchSourceUserDataOr - Name: OS_dispatch_source_data_add SwiftName: DispatchSourceUserDataAdd +- Name: OS_dispatch_source_data_replace + SwiftName: DispatchSourceUserDataReplace - Name: OS_dispatch_source_vnode SwiftName: DispatchSourceFileSystemObject - Name: OS_dispatch_source_write diff --git a/src/swift/DispatchStubs.cc b/src/swift/DispatchStubs.cc index c81768ab8..2c76b7b47 100644 --- a/src/swift/DispatchStubs.cc +++ b/src/swift/DispatchStubs.cc @@ -26,6 +26,7 @@ @protocol OS_dispatch_source_timer; @protocol OS_dispatch_source_data_add; @protocol OS_dispatch_source_data_or; +@protocol OS_dispatch_source_data_replace; @protocol OS_dispatch_source_vnode; @protocol OS_dispatch_source_write; @@ -44,6 +45,7 @@ static void _dispatch_overlay_constructor() { class_addProtocol(source, @protocol(OS_dispatch_source_timer)); class_addProtocol(source, @protocol(OS_dispatch_source_data_add)); class_addProtocol(source, @protocol(OS_dispatch_source_data_or)); + class_addProtocol(source, @protocol(OS_dispatch_source_data_replace)); class_addProtocol(source, @protocol(OS_dispatch_source_vnode)); class_addProtocol(source, @protocol(OS_dispatch_source_write)); } @@ -186,6 +188,7 @@ _swift_dispatch_retain(dispatch_object_t obj) { SOURCE(DATA_ADD) SOURCE(DATA_OR) +SOURCE(DATA_REPLACE) #if HAVE_MACH SOURCE(MACH_SEND) SOURCE(MACH_RECV) diff --git a/src/swift/Source.swift b/src/swift/Source.swift index 801ae71e3..a3a7e7903 100644 --- a/src/swift/Source.swift +++ b/src/swift/Source.swift @@ -201,6 +201,11 @@ public extension DispatchSource { let source = dispatch_source_create(_swift_dispatch_source_type_data_or(), 0, 0, queue?.__wrapped) return DispatchSource(source: source) as DispatchSourceUserDataOr } + + public class func makeUserDataReplaceSource(queue: DispatchQueue? = nil) -> DispatchSourceUserDataReplace { + let source = dispatch_source_create(_swift_dispatch_source_type_data_replace(), 0, 0, queue?.__wrapped) + return DispatchSource(source: source) as DispatchSourceUserDataReplace + } #if !os(Linux) && !os(Android) public class func makeFileSystemObjectSource(fileDescriptor: Int32, eventMask: FileSystemEvent, queue: DispatchQueue? = nil) -> DispatchSourceFileSystemObject { @@ -318,45 +323,48 @@ public extension DispatchSourceFileSystemObject { #endif public extension DispatchSourceUserDataAdd { - /// @function mergeData - /// - /// @abstract - /// Merges data into a dispatch source of type DISPATCH_SOURCE_TYPE_DATA_ADD or - /// DISPATCH_SOURCE_TYPE_DATA_OR and submits its event handler block to its - /// target queue. + /// Merges data into a dispatch source of type `DISPATCH_SOURCE_TYPE_DATA_ADD` + /// and submits its event handler block to its target queue. /// - /// @param value - /// The value to coalesce with the pending data using a logical OR or an ADD - /// as specified by the dispatch source type. A value of zero has no effect - /// and will not result in the submission of the event handler block. + /// - parameter data: the value to add to the current pending data. A value of zero + /// has no effect and will not result in the submission of the event handler block. public func add(data: UInt) { dispatch_source_merge_data((self as! DispatchSource).__wrapped, data) } } public extension DispatchSourceUserDataOr { - /// @function mergeData - /// - /// @abstract - /// Merges data into a dispatch source of type DISPATCH_SOURCE_TYPE_DATA_ADD or - /// DISPATCH_SOURCE_TYPE_DATA_OR and submits its event handler block to its - /// target queue. + /// Merges data into a dispatch source of type `DISPATCH_SOURCE_TYPE_DATA_OR` and + /// submits its event handler block to its target queue. /// - /// @param value - /// The value to coalesce with the pending data using a logical OR or an ADD - /// as specified by the dispatch source type. A value of zero has no effect - /// and will not result in the submission of the event handler block. + /// - parameter data: The value to OR into the current pending data. A value of zero + /// has no effect and will not result in the submission of the event handler block. public func or(data: UInt) { dispatch_source_merge_data((self as! DispatchSource).__wrapped, data) } } +public extension DispatchSourceUserDataReplace { + /// Merges data into a dispatch source of type `DISPATCH_SOURCE_TYPE_DATA_REPLACE` + /// and submits its event handler block to its target queue. + /// + /// - parameter data: The value that will replace the current pending data. + /// A value of zero will be stored but will not result in the submission of the event + /// handler block. + public func replace(data: UInt) { + dispatch_source_merge_data((self as! DispatchSource).__wrapped, data) + } +} + @_silgen_name("_swift_dispatch_source_type_DATA_ADD") internal func _swift_dispatch_source_type_data_add() -> dispatch_source_type_t @_silgen_name("_swift_dispatch_source_type_DATA_OR") internal func _swift_dispatch_source_type_data_or() -> dispatch_source_type_t +@_silgen_name("_swift_dispatch_source_type_DATA_REPLACE") +internal func _swift_dispatch_source_type_data_replace() -> dispatch_source_type_t + #if HAVE_MACH @_silgen_name("_swift_dispatch_source_type_MACH_SEND") internal func _swift_dispatch_source_type_mach_send() -> dispatch_source_type_t diff --git a/src/swift/Wrapper.swift b/src/swift/Wrapper.swift index ece006d6b..5a551dfba 100644 --- a/src/swift/Wrapper.swift +++ b/src/swift/Wrapper.swift @@ -158,7 +158,7 @@ public class DispatchSource : DispatchObject, DispatchSourceProtocol, DispatchSourceRead, DispatchSourceSignal, DispatchSourceTimer, DispatchSourceUserDataAdd, DispatchSourceUserDataOr, - DispatchSourceWrite { + DispatchSourceUserDataReplace, DispatchSourceWrite { internal let __wrapped:dispatch_source_t final internal override func wrapped() -> dispatch_object_t { @@ -243,6 +243,10 @@ public protocol DispatchSourceUserDataOr : DispatchSourceProtocol { func or(data: UInt) } +public protocol DispatchSourceUserDataReplace : DispatchSourceProtocol { + func replace(data: UInt) +} + #if HAVE_MACH public protocol DispatchSourceMachSend : DispatchSourceProtocol { public var handle: mach_port_t { get }