DISPATCH_QUEUE_CONCURRENT / DISPATCH_QUEUE_SERIAL


(Drew Crawford) #1

I've noticed that, when imported to Swift, the definitions for DISPATCH_QUEUE_CONCURRENT and DISPATCH_QUEUE_SERIAL aren't correct.

Specifically, the Linux program I'm porting has build errors of the form

error: use of unresolved identifier 'DISPATCH_QUEUE_CONCURRENT'

and

error: cannot convert value of type '()' to expected argument type 'dispatch_queue_attr_t' (aka 'COpaquePointer')
private let queue = dispatch_queue_create("foo", DISPATCH_QUEUE_SERIAL)
                                                                                ^~~~~~~~~~~~~~~~~~~~~

"Using the source, luke <https://github.com/apple/swift-corelibs-libdispatch/blob/acd56f625cce04d280fa83712e0add9c34506073/dispatch/queue.h#L437>" suggests that

DISPATCH_QUEUE_CONCURRENT is defined to a function invocation <https://github.com/apple/swift-corelibs-libdispatch/blob/acd56f625cce04d280fa83712e0add9c34506073/dispatch/queue.h#L437>, which may not be imported by the Swift importer. I guess this problem is resolved somehow on Darwin (perhaps by somehow explaining to Swift to use a constant for this value?) but the mechanism is not clear.
DISPATCH_QUEUE_SERIAL (aka NULL) is apparently imported as a closure for some reason

I used Cmd-Opt-J to take a look at where these symbols come from on Xcode, and it seems that, indeed, they don't come from dispatch.h. But I'm not sure, in that case, where they come from.

Maybe somebody can give me a hint how to go about working around / resolving this?

Drew


(Dave Grove) #2

From: Drew Crawford via swift-corelibs-dev <swift-corelibs-dev@swift.org>
To: swift-corelibs-dev@swift.org
Date: 02/06/2016 08:06 PM
Subject: [swift-corelibs-dev] DISPATCH_QUEUE_CONCURRENT /
DISPATCH_QUEUE_SERIAL
Sent by: swift-corelibs-dev-bounces@swift.org

I've noticed that, when imported to Swift, the definitions for
DISPATCH_QUEUE_CONCURRENT and DISPATCH_QUEUE_SERIAL aren't correct.

Specifically, the Linux program I'm porting has build errors of the form

error: use of unresolved identifier 'DISPATCH_QUEUE_CONCURRENT'

and

error: cannot convert value of type '()' to expected argument type
'dispatch_queue_attr_t' (aka 'COpaquePointer')
private let queue = dispatch_queue_create("foo", DISPATCH_QUEUE_SERIAL)

^~~~~~~~~~~~~~~~~~~~~

"Using the source, luke" suggests that

DISPATCH_QUEUE_CONCURRENT is defined to a function invocation, which
may not be imported by the Swift importer. I guess this problem is
resolved somehow on Darwin (perhaps by somehow explaining to Swift
to use a constant for this value?) but the mechanism is not clear.
DISPATCH_QUEUE_SERIAL (aka NULL) is apparently imported as a closure
for some reason

I used Cmd-Opt-J to take a look at where these symbols come from on
Xcode, and it seems that, indeed, they don't come from dispatch.h.
But I'm not sure, in that case, where they come from.

Maybe somebody can give me a hint how to go about working around /
resolving this?

Hi Drew,

  Try picking up the changes from this pull request:
https://github.com/apple/swift-corelibs-libdispatch/pull/43

  It adapts the Swift wrapper used on Darwin for Linux and builds it
into libdispatch.

  Since libdisaptch is not built with objective C support on Linux,
there is additional work beyond this pull request that still needs to be
done (the Swift importer also appears to not understand the
dispatch_object_t union type). But this pull request should allow
DISPATCH_QUEUE_SERIAL and DISPATCH_QUEUE_CONCURRENT to work.

--dave