mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
Cleanup
This commit is contained in:
1 parent
e818d40c2a
commit
ae8ffeabc9
2 files changed
+9
-9
No files matched your search
@@ -44,7 +44,7 @@ public final class Database {
|
||||
|
||||
/// The value for the dispatch queue specific that holds the Database identity.
|
||||
/// See preconditionValidQueue.
|
||||
var databaseQueueID: UnsafeMutablePointer<Void> = nil
|
||||
var dispatchQueueID: UnsafeMutablePointer<Void> = nil
|
||||
|
||||
init(path: String, configuration: Configuration, schemaCache: DatabaseSchemaCacheType) throws {
|
||||
self.configuration = configuration
|
||||
@@ -187,10 +187,10 @@ extension Database {
|
||||
|
||||
/// The key for the dispatch queue specific that holds the Database identity.
|
||||
/// See preconditionValidQueue.
|
||||
static let databaseQueueIDKey = unsafeBitCast(Database.self, UnsafePointer<Void>.self) // some unique pointer
|
||||
static let dispatchQueueIDKey = unsafeBitCast(Database.self, UnsafePointer<Void>.self) // some unique pointer
|
||||
|
||||
func preconditionValidQueue() {
|
||||
precondition(databaseQueueID == nil || databaseQueueID == dispatch_get_specific(Database.databaseQueueIDKey), "Database was not used on the correct thread. If you get this error while iterating the result of a fetch() method, consider using the array returned by fetchAll() instead.")
|
||||
precondition(dispatchQueueID == nil || dispatchQueueID == dispatch_get_specific(Database.dispatchQueueIDKey), "Database was not used on the correct thread. If you get this error while iterating the result of a fetch() method, consider using the array returned by fetchAll() instead.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1157,7 +1157,7 @@ public struct DatabaseEvent {
|
||||
|
||||
/// The protocol for all types that can fetch values from a database.
|
||||
///
|
||||
/// It is adopted by DatabaseQueue, and DatabasePool, and Database.
|
||||
/// It is adopted by DatabaseQueue, DatabasePool, and Database.
|
||||
///
|
||||
/// You don't use the protocol directly. Instead, you provide a DatabaseReader
|
||||
/// to fetching methods:
|
||||
|
||||
@@ -43,16 +43,16 @@ final class SerializedDatabase {
|
||||
self.queue = dispatch_queue_create("com.github.groue.GRDB", nil)
|
||||
|
||||
// Activate database.preconditionValidQueue()
|
||||
let databaseQueueID = unsafeBitCast(database, UnsafeMutablePointer<Void>.self)
|
||||
dispatch_queue_set_specific(queue, Database.databaseQueueIDKey, databaseQueueID, nil)
|
||||
database.databaseQueueID = databaseQueueID
|
||||
let dispatchQueueID = unsafeBitCast(database, UnsafeMutablePointer<Void>.self)
|
||||
dispatch_queue_set_specific(queue, Database.dispatchQueueIDKey, dispatchQueueID, nil)
|
||||
database.dispatchQueueID = dispatchQueueID
|
||||
}
|
||||
|
||||
func inDatabase<T>(block: (db: Database) throws -> T) rethrows -> T {
|
||||
// This method is NOT reentrant.
|
||||
//
|
||||
// Avoiding dispatch_sync and calling block() right away if the specific
|
||||
// is currently self.databaseQueueID looks like a promising solution:
|
||||
// is currently self.dispatchQueueID looks like a promising solution:
|
||||
//
|
||||
// serializedDatabase.inDatabase { db in
|
||||
// serializedDatabase.inDatabase { db in
|
||||
@@ -73,7 +73,7 @@ final class SerializedDatabase {
|
||||
//
|
||||
// I try not to ship half-baked solutions, so until a complete solution
|
||||
// is found to this problem, I prefer discouraging reentrancy.
|
||||
precondition(database.databaseQueueID != dispatch_get_specific(Database.databaseQueueIDKey), "Database methods are not reentrant.")
|
||||
precondition(database.dispatchQueueID != dispatch_get_specific(Database.dispatchQueueIDKey), "Database methods are not reentrant.")
|
||||
return try dispatchSync(queue) {
|
||||
try block(db: self.database)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user