0001    #if os(Linux)
0002        import Glibc
0003    #else
0004        import Darwin
0005    #endif
0006    
0007    #if os(Linux)
0008    public let DISPATCH_QUEUE_CONCURRENT = 200
0009    public let DISPATCH_QUEUE_SERIAL = 201
0010    
0011    public typealias dispatch_queue_t = DispatchQueue
0012    
0013    public func dispatch_queue_create(name: String,
0014        _ type: Int ) -> dispatch_queue_t {
0015    
0016        let queue: DispatchQueue
0017    
0018        if type == DISPATCH_QUEUE_SERIAL {
0019            queue = SerialQueue(identifier: name)
0020        } else {
0021            queue = ConcurrentQueue(identifier: name)
0022        }
0023    
0024        return queue
0025    }
0026    
0027    public let DISPATCH_QUEUE_PRIORITY_HIGH = 0,
0028        DISPATCH_QUEUE_PRIORITY_LOW = 0,
0029        DISPATCH_QUEUE_PRIORITY_DEFAULT = 0,
0030        DISPATCH_QUEUE_PRIORITY_BACKGROUND = 0
0031    
0032    public func dispatch_get_global_queue( type: Int, _ flags: Int ) -> dispatch_queue_t {
0033        return Echo.instance.globalQueue
0034    }
0035    
0036    public func dispatch_sync( queue: Int, _ block: () -> () ) {
0037        block()
0038    }
0039    
0040    public func dispatch_async(queue: dispatch_queue_t, _ block: () -> ()) {
0041        queue.addEvent(block)
0042    }
0043    
0044    public let DISPATCH_TIME_NOW = 0, NSEC_PER_SEC = 1_000_000_000
0045    
0046    public func dispatch_time( now: Int, _ nsec: Int64 ) -> Int64 {
0047        return nsec
0048    }
0049    
0050    public func dispatch_after(delay: Int64, _ queue: dispatch_queue_t,
0051                               _ block: () -> ()) {
0052        dispatch_async(queue, {
0053            sleep(UInt32(Int(delay)/NSEC_PER_SEC))
0054            block()
0055        })
0056    }
0057    
0058    public func dispatch_get_main_queue() -> dispatch_queue_t {
0059        return Echo.instance.mainQueue
0060    }
0061    
0062    #endif
0063