File tree Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -57,14 +57,17 @@ public final class DatabasePool: DatabaseWriter {
57
57
readerConfiguration. allowsUnsafeTransactions = false
58
58
59
59
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
+ } )
68
71
69
72
// Activate WAL Mode unless readonly
70
73
if !configuration. readonly {
Original file line number Diff line number Diff line change @@ -53,13 +53,24 @@ final class Pool<T> {
53
53
private let barrierQueue : DispatchQueue
54
54
private let semaphoreWaitingQueue : DispatchQueue // Inspired by https://khanlou.com/2016/04/the-GCD-handbook/
55
55
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
+ {
57
68
GRDBPrecondition ( maximumCount > 0 , " Pool size must be at least 1 " )
58
69
self . makeElement = makeElement
59
70
self . itemsSemaphore = DispatchSemaphore ( value: maximumCount)
60
71
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 )
63
74
}
64
75
65
76
/// Returns a tuple (element, release)
You can’t perform that action at this time.
0 commit comments