0001    /**
0002     * Copyright IBM Corporation 2015
0003     *
0004     * Licensed under the Apache License, Version 2.0 (the "License");
0005     * you may not use this file except in compliance with the License.
0006     * You may obtain a copy of the License at
0007     *
0008     * http://www.apache.org/licenses/LICENSE-2.0
0009     *
0010     * Unless required by applicable law or agreed to in writing, software
0011     * distributed under the License is distributed on an "AS IS" BASIS,
0012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     * See the License for the specific language governing permissions and
0014     * limitations under the License.
0015     **/
0016    
0017    import Dispatch
0018    
0019    // MARK: Queue
0020    
0021    public class Queue
Queue.swift:96
    public static func queueIfFirstOnMain(queue: Queue, block: () -> Void) {
{ 0022 0023 /// 0024 /// Lock to ensure 0025 /// 0026 private static var onMainOnceLock
Queue.swift:99
        SysUtils.doOnce(&onMainOnceLock) {
: Int = 0 0027 0028 /// 0029 /// Handle to the libDispatch queue 0030 /// 0031 private let osQueue
Queue.swift:66
        osQueue = dispatch_queue_create(label != nil ? label! : "",
Queue.swift:77
        dispatch_async(osQueue, block)
Queue.swift:86
        dispatch_sync(osQueue, block)
: dispatch_queue_t 0032 0033 0034 /// 0035 /// Initializes a Queue instance 0036 /// 0037 /// - Parameter type: QueueType (SERIAL or PARALLEL) 0038 /// - Parameter label: Optional String describing the Queue 0039 /// 0040 /// - Returns: Queue instance 0041 /// 0042 public init(type: QueueType, label: String?=nil) { 0043 0044 #if os(Linux) 0045 0046 /// **Note:** When using Linux, use the shim for initializing a concurrent Queue. 0047 /// 0048 let concurrent: COpaquePointer = get_dispatch_queue_concurrent() 0049 0050 #else 0051 0052 let concurrent = DISPATCH_QUEUE_CONCURRENT 0053 0054 #endif 0055 0056 #if os(Linux) 0057 0058 let serial: COpaquePointer = nil 0059 0060 #else 0061 0062 let serial = DISPATCH_QUEUE_SERIAL 0063 0064 #endif 0065 0066 osQueue = dispatch_queue_create(label != nil ? label! : "", 0067 type == QueueType.PARALLEL ? concurrent : serial) 0068 } 0069 0070 0071 /// 0072 /// Run a block asynchronously 0073 /// 0074 /// - Parameter block: a closure () -> Void 0075 /// 0076 public func queueAsync
Queue.swift:105
            queue.queueAsync(block)
(block: () -> Void) { 0077 dispatch_async(osQueue, block) 0078 } 0079 0080 /// 0081 /// Run a block synchronously 0082 /// 0083 /// - Parameter block: a closure () -> Void 0084 /// 0085 public func queueSync(block: () -> Void) { 0086 dispatch_sync(osQueue, block) 0087 } 0088 0089 0090 /// 0091 /// Run a block once a main lock has been obtained 0092 /// 0093 /// - Parameter queue: Queue 0094 /// - Parameter block: a closure () -> Void 0095 /// 0096 public static func queueIfFirstOnMain(queue: Queue, block: () -> Void) { 0097 var onQueue = true 0098 0099 SysUtils.doOnce(&onMainOnceLock) { 0100 dispatch_async(dispatch_get_main_queue(), block); 0101 onQueue = false 0102 } 0103 0104 if onQueue { 0105 queue.queueAsync(block) 0106 } 0107 } 0108 } 0109 0110 /// 0111 /// QueueType values 0112 /// 0113 public enum QueueType
Queue.swift:42
    public init(type: QueueType, label: String?=nil) {
Queue.swift:67
            type == QueueType.PARALLEL ? concurrent : serial)
{ 0114 0115 case SERIAL, PARALLEL
Queue.swift:67
            type == QueueType.PARALLEL ? concurrent : serial)
0116 0117 } 0118