From 2fcc89ba0fab7f3c0119da49ec01867d1a1bfbe7 Mon Sep 17 00:00:00 2001 From: Robbert Brandsma Date: Tue, 13 Sep 2016 12:51:32 +0200 Subject: [PATCH 1/4] Fixed a bug --- Sources/Document+Subscripts.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Document+Subscripts.swift b/Sources/Document+Subscripts.swift index d38fe1b..7ed50ff 100644 --- a/Sources/Document+Subscripts.swift +++ b/Sources/Document+Subscripts.swift @@ -54,6 +54,7 @@ extension Document { storage.insert(contentsOf: newValue.bytes, at: meta.dataPosition) storage[meta.elementTypePosition] = newValue.typeIdentifier updateDocumentHeader() + self.elementPositions = buildElementPositionsCache() return } From 51382579c876ce81862af5850e389fbc4c63694a Mon Sep 17 00:00:00 2001 From: Robbert Brandsma Date: Tue, 13 Sep 2016 12:52:27 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ee26e6..51b265c 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ import PackageDescription let package = Package( name: "MyApp", - dependencies: [.Package(url: "https://github.com/OpenKitten/BSON.git", majorVersion: 3, minor: 6)] + dependencies: [.Package(url: "https://github.com/OpenKitten/BSON.git", majorVersion: 3, minor: 7)] ) ``` From bdbebde3ba80f9851a76ee74bc5a4d3170a3e3aa Mon Sep 17 00:00:00 2001 From: Robbert Brandsma Date: Thu, 15 Sep 2016 20:49:35 +0200 Subject: [PATCH 3/4] Fix possible data race in ObjectID generation --- Sources/ObjectId.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/ObjectId.swift b/Sources/ObjectId.swift index f547a2e..e6c7443 100644 --- a/Sources/ObjectId.swift +++ b/Sources/ObjectId.swift @@ -38,6 +38,8 @@ public struct ObjectId { internal var _storage: [UInt8] + private static let counterQueue = DispatchQueue(label: "org.mongokitten.bson.oidcounter") + /// Generate a new random ObjectId. public init() { let currentTime = Date() @@ -51,8 +53,10 @@ public struct ObjectId { data += ObjectId.random.bytes // And add a counter as 2 bytes and increment it - data += ObjectId.counter.bytes - ObjectId.counter = ObjectId.counter &+ 1 + ObjectId.counterQueue.sync { + data += ObjectId.counter.bytes + ObjectId.counter = ObjectId.counter &+ 1 + } self._storage = data } From bb2e0f1f53b27a43a7bc9f33187a8ff1e6b1c29e Mon Sep 17 00:00:00 2001 From: Robbert Brandsma Date: Thu, 15 Sep 2016 21:02:50 +0200 Subject: [PATCH 4/4] Import Dispatch for Linux! --- Sources/ObjectId.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/ObjectId.swift b/Sources/ObjectId.swift index e6c7443..63d1fd6 100644 --- a/Sources/ObjectId.swift +++ b/Sources/ObjectId.swift @@ -7,6 +7,7 @@ // import Foundation +import Dispatch #if os(Linux) import Glibc