Skip to content

Adding DISPATCH_SOURCE_TYPE_DATA_REPLACE to the Swift overlay #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/swift/Dispatch.apinotes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/swift/DispatchStubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
Expand Down Expand Up @@ -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)
Expand Down
48 changes: 28 additions & 20 deletions src/swift/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/swift/Wrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
Expand Down