mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fix: added queue to GPU list to prevent data race (#2417)
This commit is contained in:
@@ -54,8 +54,30 @@ public struct GPU_Info: Codable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct GPUs: Codable {
|
||||
public var list: [GPU_Info] = []
|
||||
public class GPUs: Codable {
|
||||
private var queue: DispatchQueue = DispatchQueue(label: "eu.exelban.Stats.GPU.SynchronizedArray")
|
||||
|
||||
private var _list: [GPU_Info] = []
|
||||
public var list: [GPU_Info] {
|
||||
get { self.queue.sync { self._list } }
|
||||
set { self.queue.sync { self._list = newValue } }
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case list
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.list = try container.decode(Array<GPU_Info>.self, forKey: CodingKeys.list)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(list, forKey: .list)
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
||||
internal func active() -> [GPU_Info] {
|
||||
return self.list.filter{ $0.state && $0.utilization != nil }.sorted{ $0.utilization ?? 0 > $1.utilization ?? 0 }
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>679</string>
|
||||
<string>680</string>
|
||||
<key>Description</key>
|
||||
<string>Simple macOS system monitor in your menu bar</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.11.33</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>679</string>
|
||||
<string>680</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
|
||||
Reference in New Issue
Block a user