LCOV - code coverage report
Current view: top level - pebble/internal/cache - refcnt_normal.go (source / functions) Hit Total Coverage
Test: 2024-04-04 08:16Z 65d5ba68 - tests + meta.lcov Lines: 16 23 69.6 %
Date: 2024-04-04 08:17:08 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2020 The LevelDB-Go and Pebble Authors. All rights reserved. Use
       2             : // of this source code is governed by a BSD-style license that can be found in
       3             : // the LICENSE file.
       4             : 
       5             : //go:build !tracing
       6             : // +build !tracing
       7             : 
       8             : package cache
       9             : 
      10             : import (
      11             :         "fmt"
      12             :         "sync/atomic"
      13             : 
      14             :         "github.com/cockroachdb/redact"
      15             : )
      16             : 
      17             : // refcnt provides an atomic reference count. This version is used when the
      18             : // "tracing" build tag is not enabled. See refcnt_tracing.go for the "tracing"
      19             : // enabled version.
      20             : type refcnt struct {
      21             :         val atomic.Int32
      22             : }
      23             : 
      24             : // initialize the reference count to the specified value.
      25           2 : func (v *refcnt) init(val int32) {
      26           2 :         v.val.Store(val)
      27           2 : }
      28             : 
      29           2 : func (v *refcnt) refs() int32 {
      30           2 :         return v.val.Load()
      31           2 : }
      32             : 
      33           2 : func (v *refcnt) acquire() {
      34           2 :         switch v := v.val.Add(1); {
      35           0 :         case v <= 1:
      36           0 :                 panic(redact.Safe(fmt.Sprintf("pebble: inconsistent reference count: %d", v)))
      37             :         }
      38             : }
      39             : 
      40           2 : func (v *refcnt) release() bool {
      41           2 :         switch v := v.val.Add(-1); {
      42           0 :         case v < 0:
      43           0 :                 panic(redact.Safe(fmt.Sprintf("pebble: inconsistent reference count: %d", v)))
      44           2 :         case v == 0:
      45           2 :                 return true
      46           2 :         default:
      47           2 :                 return false
      48             :         }
      49             : }
      50             : 
      51           2 : func (v *refcnt) trace(msg string) {
      52           2 : }
      53             : 
      54           0 : func (v *refcnt) traces() string {
      55           0 :         return ""
      56           0 : }
      57             : 
      58             : // Silence unused warning.
      59             : var _ = (*refcnt)(nil).traces

Generated by: LCOV version 1.14