From f60f736ec1b16a0d7163f2e4c724c20b46180cfd Mon Sep 17 00:00:00 2001 From: GWlodarek Date: Thu, 28 Jul 2016 10:40:51 -0400 Subject: [PATCH] Resolves #5 --- Sources/IBMDB/SwiftDB2.swift | 28 +++++++++++++++++++--------- Tests/IBMDB/ConnectTests.swift | 4 ++-- Tests/IBMDB/DisconnectTests.swift | 2 +- Tests/IBMDB/QueryTests.swift | 24 ++++++++++++------------ 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Sources/IBMDB/SwiftDB2.swift b/Sources/IBMDB/SwiftDB2.swift index 801e584..9e4982a 100755 --- a/Sources/IBMDB/SwiftDB2.swift +++ b/Sources/IBMDB/SwiftDB2.swift @@ -27,6 +27,14 @@ import Darwin import IBMCliDarwin #endif +// Custom named queues +#if os(Linux) +let queue = dispatch_queue_create("swift-for-db2", DISPATCH_QUEUE_CONCURRENT) +#else +let queue = DispatchQueue(label: "swift-for-db2", attributes: .concurrent) +#endif + + /** * IBMDB Class * @@ -34,6 +42,7 @@ import IBMCliDarwin */ public class IBMDB { + /** * Empty constructor to initialize IBMDB. */ @@ -80,11 +89,11 @@ public class IBMDB { } #if os(Linux) - dispatch_async(dispatch_get_global_queue(Int(DISPATCH_QUEUE_PRIORITY_HIGH), 0), { + dispatch_async(queue) { run() - }) + } #else - DispatchQueue.main.async { + queue.sync { run() } #endif @@ -194,11 +203,11 @@ public class Connection { } #if os(Linux) - dispatch_async(dispatch_get_global_queue(Int(DISPATCH_QUEUE_PRIORITY_HIGH), 0), { + dispatch_async(queue) { run() - }) + } #else - DispatchQueue.main.async { + queue.sync { run() } #endif @@ -344,14 +353,15 @@ public class Connection { } #if os(Linux) - dispatch_async(dispatch_get_global_queue(Int(DISPATCH_QUEUE_PRIORITY_HIGH), 0), { + dispatch_async(queue) { run() - }) + } #else - DispatchQueue.main.async { + queue.sync { run() } #endif + } diff --git a/Tests/IBMDB/ConnectTests.swift b/Tests/IBMDB/ConnectTests.swift index f16845b..be58b88 100755 --- a/Tests/IBMDB/ConnectTests.swift +++ b/Tests/IBMDB/ConnectTests.swift @@ -58,7 +58,7 @@ class ConnectTests : XCTestCase { expectation.fulfill() } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -76,7 +76,7 @@ class ConnectTests : XCTestCase { expectation.fulfill() } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } diff --git a/Tests/IBMDB/DisconnectTests.swift b/Tests/IBMDB/DisconnectTests.swift index 2d9255c..a310e3a 100755 --- a/Tests/IBMDB/DisconnectTests.swift +++ b/Tests/IBMDB/DisconnectTests.swift @@ -63,7 +63,7 @@ class DisconnectTests : XCTestCase { expectation.fulfill() } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } diff --git a/Tests/IBMDB/QueryTests.swift b/Tests/IBMDB/QueryTests.swift index c52bcf0..fdac8fb 100755 --- a/Tests/IBMDB/QueryTests.swift +++ b/Tests/IBMDB/QueryTests.swift @@ -133,7 +133,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -193,7 +193,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -252,7 +252,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -295,7 +295,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -347,7 +347,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -398,7 +398,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -447,7 +447,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -505,7 +505,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -563,7 +563,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -611,7 +611,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -670,7 +670,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") } @@ -728,7 +728,7 @@ class QueryTests : XCTestCase { } - self.waitForExpectations(withTimeout: 300) { error in + self.waitForExpectations(withTimeout: 600) { error in if let error = error { XCTFail("waitForExpectationsWithTimeout errored: \(error)") }