|
@@ -5,7 +5,11 @@
|
|
|
// Created by Damian Kolakowski on 13/07/16.
|
|
// Created by Damian Kolakowski on 13/07/16.
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
-import Foundation
|
|
|
|
|
|
|
+#if os(Linux)
|
|
|
|
|
+ import Glibc
|
|
|
|
|
+#else
|
|
|
|
|
+ import Foundation
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
extension Socket {
|
|
extension Socket {
|
|
|
|
|
|
|
@@ -43,41 +47,4 @@ func sendfile(source: Int32, _ target: Int32, _: off_t, _: UnsafeMutablePointer<
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-public class NSLock {
|
|
|
|
|
-
|
|
|
|
|
- private var mutex = pthread_mutex_t()
|
|
|
|
|
-
|
|
|
|
|
- init() { pthread_mutex_init(&mutex, nil) }
|
|
|
|
|
-
|
|
|
|
|
- public func lock() { pthread_mutex_lock(&mutex) }
|
|
|
|
|
-
|
|
|
|
|
- public func unlock() { pthread_mutex_unlock(&mutex) }
|
|
|
|
|
-
|
|
|
|
|
- deinit { pthread_mutex_destroy(&mutex) }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-let DISPATCH_QUEUE_PRIORITY_BACKGROUND = 0
|
|
|
|
|
-
|
|
|
|
|
-private class dispatch_context {
|
|
|
|
|
- let block: ((Void) -> Void)
|
|
|
|
|
- init(_ block: ((Void) -> Void)) {
|
|
|
|
|
- self.block = block
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func dispatch_get_global_queue(queueId: Int, _ arg: Int) -> Int { return 0 }
|
|
|
|
|
-
|
|
|
|
|
-func dispatch_async(queueId: Int, _ block: ((Void) -> Void)) {
|
|
|
|
|
- let unmanagedDispatchContext = Unmanaged.passRetained(dispatch_context(block))
|
|
|
|
|
- let context = UnsafeMutablePointer<Void>(unmanagedDispatchContext.toOpaque())
|
|
|
|
|
- var pthread: pthread_t = 0
|
|
|
|
|
- pthread_create(&pthread, nil, { (context: UnsafeMutablePointer<Void>) -> UnsafeMutablePointer<Void> in
|
|
|
|
|
- let unmanaged = Unmanaged<dispatch_context>.fromOpaque(COpaquePointer(context))
|
|
|
|
|
- unmanaged.takeUnretainedValue().block()
|
|
|
|
|
- unmanaged.release()
|
|
|
|
|
- return context
|
|
|
|
|
- }, context)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
#endif
|
|
#endif
|