Skip to content

Commit ee92db9

Browse files
committed
Pool has a QoS
1 parent de42664 commit ee92db9

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

GRDB/Core/DatabasePool.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,17 @@ public final class DatabasePool: DatabaseWriter {
5757
readerConfiguration.allowsUnsafeTransactions = false
5858

5959
var readerCount = 0
60-
readerPool = Pool(maximumCount: configuration.maximumReaderCount, makeElement: {
61-
readerCount += 1 // protected by Pool (TODO: document this protection behavior)
62-
return try SerializedDatabase(
63-
path: path,
64-
configuration: readerConfiguration,
65-
defaultLabel: "GRDB.DatabasePool",
66-
purpose: "reader.\(readerCount)")
67-
})
60+
readerPool = Pool(
61+
maximumCount: configuration.maximumReaderCount,
62+
qos: configuration.readQoS,
63+
makeElement: {
64+
readerCount += 1 // protected by Pool (TODO: document this protection behavior)
65+
return try SerializedDatabase(
66+
path: path,
67+
configuration: readerConfiguration,
68+
defaultLabel: "GRDB.DatabasePool",
69+
purpose: "reader.\(readerCount)")
70+
})
6871

6972
// Activate WAL Mode unless readonly
7073
if !configuration.readonly {

GRDB/Utils/Pool.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,24 @@ final class Pool<T> {
5353
private let barrierQueue: DispatchQueue
5454
private let semaphoreWaitingQueue: DispatchQueue // Inspired by https://khanlou.com/2016/04/the-GCD-handbook/
5555

56-
init(maximumCount: Int, makeElement: @escaping () throws -> T) {
56+
/// Creates a Pool.
57+
///
58+
/// - parameters:
59+
/// - maximumCount: The maximum number of elements.
60+
/// - qos: The quality of service of asynchronous accesses.
61+
/// - makeElement: A function that creates an element. It is called
62+
/// on demand.
63+
init(
64+
maximumCount: Int,
65+
qos: DispatchQoS = .unspecified,
66+
makeElement: @escaping () throws -> T)
67+
{
5768
GRDBPrecondition(maximumCount > 0, "Pool size must be at least 1")
5869
self.makeElement = makeElement
5970
self.itemsSemaphore = DispatchSemaphore(value: maximumCount)
6071
self.itemsGroup = DispatchGroup()
61-
self.barrierQueue = DispatchQueue(label: "GRDB.Pool.barrier", attributes: [.concurrent])
62-
self.semaphoreWaitingQueue = DispatchQueue(label: "GRDB.Pool.wait")
72+
self.barrierQueue = DispatchQueue(label: "GRDB.Pool.barrier", qos: qos, attributes: [.concurrent])
73+
self.semaphoreWaitingQueue = DispatchQueue(label: "GRDB.Pool.wait", qos: qos)
6374
}
6475

6576
/// Returns a tuple (element, release)

0 commit comments

Comments
 (0)