"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7315/ios/app/broadcast-extension/Atomic.swift" (2 Jun 2023, 535 Bytes) of package /linux/misc/jitsi-meet-7315.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Swift source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 
    2 import Foundation
    3 
    4 @propertyWrapper
    5 struct Atomic<Value> {
    6 
    7     private var value: Value
    8     private let lock = NSLock()
    9 
   10     init(wrappedValue value: Value) {
   11         self.value = value
   12     }
   13 
   14     var wrappedValue: Value {
   15       get { return load() }
   16       set { store(newValue: newValue) }
   17     }
   18 
   19     func load() -> Value {
   20         lock.lock()
   21         defer { lock.unlock() }
   22         return value
   23     }
   24 
   25     mutating func store(newValue: Value) {
   26         lock.lock()
   27         defer { lock.unlock() }
   28         value = newValue
   29     }
   30 }