Skip to content

Commit a6c16d0

Browse files
committed
Adding DISPATCH_SOURCE_TYPE_DATA_REPLACE to the Swift overlay
(Radar rdar://problem/30518517)
1 parent 7ca0a63 commit a6c16d0

File tree

4 files changed

+38
-21
lines changed

4 files changed

+38
-21
lines changed

src/swift/Dispatch.apinotes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Protocols:
9191
SwiftName: DispatchSourceUserDataOr
9292
- Name: OS_dispatch_source_data_add
9393
SwiftName: DispatchSourceUserDataAdd
94+
- Name: OS_dispatch_source_data_replace
95+
SwiftName: DispatchSourceUserDataReplace
9496
- Name: OS_dispatch_source_vnode
9597
SwiftName: DispatchSourceFileSystemObject
9698
- Name: OS_dispatch_source_write

src/swift/DispatchStubs.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@protocol OS_dispatch_source_timer;
2727
@protocol OS_dispatch_source_data_add;
2828
@protocol OS_dispatch_source_data_or;
29+
@protocol OS_dispatch_source_data_replace;
2930
@protocol OS_dispatch_source_vnode;
3031
@protocol OS_dispatch_source_write;
3132

@@ -44,6 +45,7 @@ static void _dispatch_overlay_constructor() {
4445
class_addProtocol(source, @protocol(OS_dispatch_source_timer));
4546
class_addProtocol(source, @protocol(OS_dispatch_source_data_add));
4647
class_addProtocol(source, @protocol(OS_dispatch_source_data_or));
48+
class_addProtocol(source, @protocol(OS_dispatch_source_data_replace));
4749
class_addProtocol(source, @protocol(OS_dispatch_source_vnode));
4850
class_addProtocol(source, @protocol(OS_dispatch_source_write));
4951
}
@@ -186,6 +188,7 @@ _swift_dispatch_retain(dispatch_object_t obj) {
186188

187189
SOURCE(DATA_ADD)
188190
SOURCE(DATA_OR)
191+
SOURCE(DATA_REPLACE)
189192
#if HAVE_MACH
190193
SOURCE(MACH_SEND)
191194
SOURCE(MACH_RECV)

src/swift/Source.swift

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ public extension DispatchSource {
201201
let source = dispatch_source_create(_swift_dispatch_source_type_data_or(), 0, 0, queue?.__wrapped)
202202
return DispatchSource(source: source) as DispatchSourceUserDataOr
203203
}
204+
205+
public class func makeUserDataReplaceSource(queue: DispatchQueue? = nil) -> DispatchSourceUserDataReplace {
206+
let source = dispatch_source_create(_swift_dispatch_source_type_data_replace(), 0, 0, queue?.__wrapped)
207+
return DispatchSource(source: source) as DispatchSourceUserDataReplace
208+
}
204209

205210
#if !os(Linux) && !os(Android)
206211
public class func makeFileSystemObjectSource(fileDescriptor: Int32, eventMask: FileSystemEvent, queue: DispatchQueue? = nil) -> DispatchSourceFileSystemObject {
@@ -318,45 +323,48 @@ public extension DispatchSourceFileSystemObject {
318323
#endif
319324

320325
public extension DispatchSourceUserDataAdd {
321-
/// @function mergeData
322-
///
323-
/// @abstract
324-
/// Merges data into a dispatch source of type DISPATCH_SOURCE_TYPE_DATA_ADD or
325-
/// DISPATCH_SOURCE_TYPE_DATA_OR and submits its event handler block to its
326-
/// target queue.
326+
/// Merges data into a dispatch source of type `DISPATCH_SOURCE_TYPE_DATA_ADD`
327+
/// and submits its event handler block to its target queue.
327328
///
328-
/// @param value
329-
/// The value to coalesce with the pending data using a logical OR or an ADD
330-
/// as specified by the dispatch source type. A value of zero has no effect
331-
/// and will not result in the submission of the event handler block.
329+
/// - parameter data: the value to add to the current pending data. A value of zero
330+
/// has no effect and will not result in the submission of the event handler block.
332331
public func add(data: UInt) {
333332
dispatch_source_merge_data((self as! DispatchSource).__wrapped, data)
334333
}
335334
}
336335

337336
public extension DispatchSourceUserDataOr {
338-
/// @function mergeData
339-
///
340-
/// @abstract
341-
/// Merges data into a dispatch source of type DISPATCH_SOURCE_TYPE_DATA_ADD or
342-
/// DISPATCH_SOURCE_TYPE_DATA_OR and submits its event handler block to its
343-
/// target queue.
337+
/// Merges data into a dispatch source of type `DISPATCH_SOURCE_TYPE_DATA_OR` and
338+
/// submits its event handler block to its target queue.
344339
///
345-
/// @param value
346-
/// The value to coalesce with the pending data using a logical OR or an ADD
347-
/// as specified by the dispatch source type. A value of zero has no effect
348-
/// and will not result in the submission of the event handler block.
340+
/// - parameter data: The value to OR into the current pending data. A value of zero
341+
/// has no effect and will not result in the submission of the event handler block.
349342
public func or(data: UInt) {
350343
dispatch_source_merge_data((self as! DispatchSource).__wrapped, data)
351344
}
352345
}
353346

347+
public extension DispatchSourceUserDataReplace {
348+
/// Merges data into a dispatch source of type `DISPATCH_SOURCE_TYPE_DATA_REPLACE`
349+
/// and submits its event handler block to its target queue.
350+
///
351+
/// - parameter data: The value that will replace the current pending data.
352+
/// A value of zero will be stored but will not result in the submission of the event
353+
/// handler block.
354+
public func replace(data: UInt) {
355+
dispatch_source_merge_data((self as! DispatchSource).__wrapped, data)
356+
}
357+
}
358+
354359
@_silgen_name("_swift_dispatch_source_type_DATA_ADD")
355360
internal func _swift_dispatch_source_type_data_add() -> dispatch_source_type_t
356361

357362
@_silgen_name("_swift_dispatch_source_type_DATA_OR")
358363
internal func _swift_dispatch_source_type_data_or() -> dispatch_source_type_t
359364

365+
@_silgen_name("_swift_dispatch_source_type_DATA_REPLACE")
366+
internal func _swift_dispatch_source_type_data_replace() -> dispatch_source_type_t
367+
360368
#if HAVE_MACH
361369
@_silgen_name("_swift_dispatch_source_type_MACH_SEND")
362370
internal func _swift_dispatch_source_type_mach_send() -> dispatch_source_type_t

src/swift/Wrapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public class DispatchSource : DispatchObject,
158158
DispatchSourceProtocol, DispatchSourceRead,
159159
DispatchSourceSignal, DispatchSourceTimer,
160160
DispatchSourceUserDataAdd, DispatchSourceUserDataOr,
161-
DispatchSourceWrite {
161+
DispatchSourceUserDataReplace, DispatchSourceWrite {
162162
internal let __wrapped:dispatch_source_t
163163

164164
final internal override func wrapped() -> dispatch_object_t {
@@ -243,6 +243,10 @@ public protocol DispatchSourceUserDataOr : DispatchSourceProtocol {
243243
func or(data: UInt)
244244
}
245245

246+
public protocol DispatchSourceUserDataReplace : DispatchSourceProtocol {
247+
func replace(data: UInt)
248+
}
249+
246250
#if HAVE_MACH
247251
public protocol DispatchSourceMachSend : DispatchSourceProtocol {
248252
public var handle: mach_port_t { get }

0 commit comments

Comments
 (0)