Skip to content

Commit a32d551

Browse files
committed
use !os(Linux) instead of HAVE_MACH where appropriate
also make vnode source unavailable on linux
1 parent d94123b commit a32d551

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/swift/DispatchStubs.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,15 @@ SOURCE(MACH_SEND)
179179
SOURCE(MACH_RECV)
180180
SOURCE(MEMORYPRESSURE)
181181
#endif
182+
#ifndef __linux__
182183
SOURCE(PROC)
184+
#endif
183185
SOURCE(READ)
184186
SOURCE(SIGNAL)
185187
SOURCE(TIMER)
188+
#ifndef __linux__
186189
SOURCE(VNODE)
190+
#endif
187191
SOURCE(WRITE)
188192

189193
// See comment in CFFuntime.c explaining why objc_retainAutoreleasedReturnValue is needed.

src/swift/Source.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public extension DispatchSource {
113113
}
114114
#endif
115115

116-
#if HAVE_MACH
116+
#if !os(Linux)
117117
public struct ProcessEvent : OptionSet, RawRepresentable {
118118
public let rawValue: UInt
119119
public init(rawValue: UInt) { self.rawValue = rawValue }
@@ -171,7 +171,7 @@ public extension DispatchSource {
171171
}
172172
#endif
173173

174-
#if HAVE_MACH
174+
#if !os(Linux)
175175
public class func process(identifier: pid_t, eventMask: ProcessEvent, queue: DispatchQueue? = nil) -> DispatchSourceProcess {
176176
let source = dispatch_source_create(_swift_dispatch_source_type_proc(), UInt(identifier), eventMask.rawValue, queue?.__wrapped)
177177
return DispatchSource(source: source) as DispatchSourceProcess
@@ -203,10 +203,12 @@ public extension DispatchSource {
203203
return DispatchSource(source: source) as DispatchSourceUserDataOr
204204
}
205205

206+
#if !os(Linux)
206207
public class func fileSystemObject(fileDescriptor: Int32, eventMask: FileSystemEvent, queue: DispatchQueue? = nil) -> DispatchSourceFileSystemObject {
207208
let source = dispatch_source_create(_swift_dispatch_source_type_vnode(), UInt(fileDescriptor), eventMask.rawValue, queue?.__wrapped)
208209
return DispatchSource(source: source) as DispatchSourceFileSystemObject
209210
}
211+
#endif
210212

211213
public class func write(fileDescriptor: Int32, queue: DispatchQueue? = nil) -> DispatchSourceWrite {
212214
let source = dispatch_source_create(_swift_dispatch_source_type_write(), UInt(fileDescriptor), 0, queue?.__wrapped)
@@ -254,7 +256,7 @@ public extension DispatchSourceMemoryPressure {
254256
}
255257
#endif
256258

257-
#if HAVE_MACH
259+
#if !os(Linux)
258260
public extension DispatchSourceProcess {
259261
public var handle: pid_t {
260262
return pid_t(dispatch_source_get_handle(self as! DispatchSource))
@@ -330,6 +332,7 @@ public extension DispatchSourceTimer {
330332
}
331333
}
332334

335+
#if !os(Linux)
333336
public extension DispatchSourceFileSystemObject {
334337
public var handle: Int32 {
335338
return Int32(dispatch_source_get_handle((self as! DispatchSource).__wrapped))
@@ -345,6 +348,7 @@ public extension DispatchSourceFileSystemObject {
345348
return DispatchSource.FileSystemEvent(rawValue: data)
346349
}
347350
}
351+
#endif
348352

349353
public extension DispatchSourceUserDataAdd {
350354
/// @function mergeData
@@ -388,6 +392,7 @@ internal func _swift_dispatch_source_type_data_add() -> dispatch_source_type_t
388392
@_silgen_name("_swift_dispatch_source_type_DATA_OR")
389393
internal func _swift_dispatch_source_type_data_or() -> dispatch_source_type_t
390394

395+
#if HAVE_MACH
391396
@_silgen_name("_swift_dispatch_source_type_MACH_SEND")
392397
internal func _swift_dispatch_source_type_mach_send() -> dispatch_source_type_t
393398

@@ -396,9 +401,12 @@ internal func _swift_dispatch_source_type_mach_recv() -> dispatch_source_type_t
396401

397402
@_silgen_name("_swift_dispatch_source_type_MEMORYPRESSURE")
398403
internal func _swift_dispatch_source_type_memorypressure() -> dispatch_source_type_t
404+
#endif
399405

406+
#if !os(Linux)
400407
@_silgen_name("_swift_dispatch_source_type_PROC")
401408
internal func _swift_dispatch_source_type_proc() -> dispatch_source_type_t
409+
#endif
402410

403411
@_silgen_name("_swift_dispatch_source_type_READ")
404412
internal func _swift_dispatch_source_type_read() -> dispatch_source_type_t
@@ -409,8 +417,10 @@ internal func _swift_dispatch_source_type_signal() -> dispatch_source_type_t
409417
@_silgen_name("_swift_dispatch_source_type_TIMER")
410418
internal func _swift_dispatch_source_type_timer() -> dispatch_source_type_t
411419

420+
#if !os(Linux)
412421
@_silgen_name("_swift_dispatch_source_type_VNODE")
413422
internal func _swift_dispatch_source_type_vnode() -> dispatch_source_type_t
423+
#endif
414424

415425
@_silgen_name("_swift_dispatch_source_type_WRITE")
416426
internal func _swift_dispatch_source_type_write() -> dispatch_source_type_t

src/swift/Wrapper.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ public class DispatchQueue : DispatchObject {
139139
}
140140
}
141141

142+
// FIXME: the list of implemented protocols is OS dependent.
143+
// need to properly conditionalize this declaration.
142144
public class DispatchSource : DispatchObject,
143145
DispatchSourceType, DispatchSourceRead,
144146
DispatchSourceSignal, DispatchSourceTimer,
145147
DispatchSourceUserDataAdd, DispatchSourceUserDataOr,
146-
DispatchSourceFileSystemObject, DispatchSourceWrite {
148+
DispatchSourceWrite {
147149
internal let __wrapped:dispatch_source_t
148150

149151
internal override func wrapped() -> dispatch_object_t {
@@ -218,7 +220,7 @@ public protocol DispatchSourceMemoryPressure : DispatchSourceType {
218220
}
219221
#endif
220222

221-
#if HAVE_MACH
223+
#if !os(Linux)
222224
public protocol DispatchSourceProcess : DispatchSourceType {
223225
var handle: pid_t { get }
224226

@@ -250,13 +252,15 @@ public protocol DispatchSourceTimer : DispatchSourceType {
250252
func setTimer(walltime start: DispatchWallTime, interval: Double, leeway: DispatchTimeInterval)
251253
}
252254

255+
#if !os(Linux)
253256
public protocol DispatchSourceFileSystemObject : DispatchSourceType {
254257
var handle: Int32 { get }
255258

256259
var data: DispatchSource.FileSystemEvent { get }
257260

258261
var mask: DispatchSource.FileSystemEvent { get }
259262
}
263+
#endif
260264

261265
public protocol DispatchSourceWrite : DispatchSourceType {
262266

0 commit comments

Comments
 (0)