Skip to content

Commit

Permalink
fix: prevent disk duplication in the list because of a data race. It …
Browse files Browse the repository at this point in the history
…causes the popup view or widget to stop updating the value (#1624)
  • Loading branch information
exelban committed Sep 29, 2023
1 parent 48322fc commit 0b15c14
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Modules/Disk/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public struct drive: Codable {
}

public class Disks: Codable {
private var queue: DispatchQueue = DispatchQueue(label: "eu.exelban.Stats.Disk.SynchronizedArray", attributes: .concurrent)
private var queue: DispatchQueue = DispatchQueue(label: "eu.exelban.Stats.Disk.SynchronizedArray")
private var array: [drive] = []

enum CodingKeys: String, CodingKey {
Expand Down Expand Up @@ -108,7 +108,9 @@ public class Disks: Codable {

public func append( _ element: drive) {
self.queue.async(flags: .barrier) {
self.array.append(element)
if !self.array.contains(where: {$0.BSDName == element.BSDName}) {
self.array.append(element)
}
}
}

Expand Down

0 comments on commit 0b15c14

Please sign in to comment.