github.com/pion/webrtc/v4@v4.0.1/atomicbool.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package webrtc
     5  
     6  import "sync/atomic"
     7  
     8  type atomicBool struct {
     9  	val int32
    10  }
    11  
    12  func (b *atomicBool) set(value bool) { // nolint: unparam
    13  	var i int32
    14  	if value {
    15  		i = 1
    16  	}
    17  
    18  	atomic.StoreInt32(&(b.val), i)
    19  }
    20  
    21  func (b *atomicBool) get() bool {
    22  	return atomic.LoadInt32(&(b.val)) != 0
    23  }
    24  
    25  func (b *atomicBool) swap(value bool) bool {
    26  	var i int32
    27  	if value {
    28  		i = 1
    29  	}
    30  	return atomic.SwapInt32(&(b.val), i) != 0
    31  }