aboutsummaryrefslogtreecommitdiffhomepage
path: root/usagepool.go
diff options
context:
space:
mode:
authorMatt Holt <[email protected]>2022-08-03 11:04:51 -0600
committerGitHub <[email protected]>2022-08-03 11:04:51 -0600
commit1960a0dc117dd30fb507b390ddf93b2ef371b9ad (patch)
tree42837b24d53dd449ac153d7b1d252ee8422e4729 /usagepool.go
parent63c7720e84176184698730fed0ca7c402c53481a (diff)
downloadcaddy-1960a0dc117dd30fb507b390ddf93b2ef371b9ad.tar.gz
caddy-1960a0dc117dd30fb507b390ddf93b2ef371b9ad.zip
httpserver: Configurable shutdown delay (#4906)
Diffstat (limited to 'usagepool.go')
-rw-r--r--usagepool.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/usagepool.go b/usagepool.go
index 923402183..c34441554 100644
--- a/usagepool.go
+++ b/usagepool.go
@@ -194,6 +194,21 @@ func (up *UsagePool) Delete(key any) (deleted bool, err error) {
return
}
+// References returns the number of references (count of usages) to a
+// key in the pool, and true if the key exists, or false otherwise.
+func (up *UsagePool) References(key interface{}) (int, bool) {
+ up.RLock()
+ upv, loaded := up.pool[key]
+ up.RUnlock()
+ if loaded {
+ // I wonder if it'd be safer to read this value during
+ // our lock on the UsagePool... guess we'll see...
+ refs := atomic.LoadInt32(&upv.refs)
+ return int(refs), true
+ }
+ return 0, false
+}
+
// Constructor is a function that returns a new value
// that can destruct itself when it is no longer needed.
type Constructor func() (Destructor, error)