Fix cross-thread access issues

This commit is contained in:
Aaron L Bratcher 2022-05-07 19:57:57 -04:00
parent bf12bb179b
commit c2eea0cbc9
3 changed files with 16 additions and 7 deletions

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "AgileDB"
s.version = "6.5.1"
s.version = "6.5.2"
s.summary = "Save and retrieve full object graphs to SQLite"
s.homepage = "https://github.com/AaronBratcher/AgileDB"

View File

@ -2243,7 +2243,6 @@ private extension AgileDB {
return
}
self.autoCloseTimer?.suspend()
self.automaticallyClosed = true
} else {
self.isOpen = false
@ -2496,12 +2495,15 @@ private extension AgileDB {
@discardableResult
private func addBlock(_ block: Any) -> UInt {
var executionBlockReference: UInt = 0
blockQueue.sync {
if blockReference > (UInt.max - 5) {
blockReference = 1
} else {
blockReference += 1
}
executionBlockReference = blockReference
}
blockQueue.async {
@ -2511,7 +2513,7 @@ private extension AgileDB {
self.threadLock.signal()
}
return blockReference
return executionBlockReference
}
override func main() {
@ -2525,7 +2527,12 @@ private extension AgileDB {
}
}
while queuedBlocks.isNotEmpty {
var hasBlocks = false
blockQueue.sync {
hasBlocks = queuedBlocks.isNotEmpty
}
while hasBlocks {
if isDebugging {
Thread.sleep(forTimeInterval: 0.1)
}
@ -2535,11 +2542,15 @@ private extension AgileDB {
queuedBlocks.removeFirst()
block()
}
hasBlocks = queuedBlocks.isNotEmpty
}
}
lastActivity = Date().timeIntervalSince1970
autoCloseTimer?.resume()
if !automaticallyClosed {
autoCloseTimer?.resume()
}
threadLock.wait()
}

View File

@ -123,8 +123,6 @@ class SyncTests: XCTestCase {
db.open()
XCTAssert(db.unsyncedTables.count == 1)
let unsyncedTables = db.unsyncedTables
// will be deleted
db.setValueInTable(DBTable(name: "table8"), for: "testKey1", to: "{\"numValue\":10,\"account\":\"ACCT1\",\"dateValue\":\"2014-8-19T18:23:42.434-05:00\",\"arrayValue\":[1,2,3,4,5]}", autoDeleteAfter: nil)