Skip to content

Commit

Permalink
Merge branch 'master' of github.com:OpenKitten/BSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Obbut committed Sep 17, 2016
2 parents 244fce2 + bb2e0f1 commit 9aaacbc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
)
```

Expand Down
1 change: 1 addition & 0 deletions Sources/Document+Subscripts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extension Document {
storage.insert(contentsOf: newValue.bytes, at: meta.dataPosition)
storage[meta.elementTypePosition] = newValue.typeIdentifier
updateDocumentHeader()
self.elementPositions = buildElementPositionsCache()

return
}
Expand Down
9 changes: 7 additions & 2 deletions Sources/ObjectId.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import Dispatch

#if os(Linux)
import Glibc
Expand Down Expand Up @@ -38,6 +39,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()
Expand All @@ -51,8 +54,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
}
Expand Down

0 comments on commit 9aaacbc

Please sign in to comment.