github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/cos/bitflags.go (about)

     1  // Package cos provides common low-level types and utilities for all aistore projects
     2  /*
     3   * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package cos
     6  
     7  import "sync/atomic"
     8  
     9  type BitFlags uint64
    10  
    11  func (f BitFlags) Set(flags BitFlags) BitFlags {
    12  	return f | flags
    13  }
    14  
    15  func (f BitFlags) Clear(flags BitFlags) BitFlags {
    16  	return f &^ flags
    17  }
    18  
    19  func (f BitFlags) IsSet(flags BitFlags) bool {
    20  	return f&flags == flags
    21  }
    22  
    23  func (f BitFlags) IsAnySet(flags BitFlags) bool {
    24  	return f&flags != 0
    25  }
    26  
    27  // atomic
    28  
    29  func SetfAtomic(f *uint64, flags uint64) (ok bool) {
    30  	return atomic.CompareAndSwapUint64(f, *f, *f|flags)
    31  }
    32  
    33  func ClearfAtomic(f *uint64, flags uint64) (ok bool) {
    34  	return atomic.CompareAndSwapUint64(f, *f, *f&^flags)
    35  }
    36  
    37  func IsSetfAtomic(f *uint64, flags uint64) (yes bool) {
    38  	return atomic.LoadUint64(f)&flags == flags
    39  }
    40  
    41  func IsAnySetfAtomic(f *uint64, flags uint64) (yes bool) {
    42  	return atomic.LoadUint64(f)&flags != 0
    43  }