diff options
author | Wim <wim@42.be> | 2023-08-05 20:43:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 20:43:19 +0200 |
commit | 56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (patch) | |
tree | b1355645342667209263cbd355dc0b4254f1e8fe /vendor/github.com/mattermost/logr/levelcache.go | |
parent | 9459495484d6e06a3d46de64fccd8d06f7ccc72c (diff) | |
download | matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.gz matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.tar.bz2 matterbridge-msglm-56e7bd01ca09ad52b0c4f48f146a20a4f1b78696.zip |
Diffstat (limited to 'vendor/github.com/mattermost/logr/levelcache.go')
-rw-r--r-- | vendor/github.com/mattermost/logr/levelcache.go | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/vendor/github.com/mattermost/logr/levelcache.go b/vendor/github.com/mattermost/logr/levelcache.go deleted file mode 100644 index 2cefb61d..00000000 --- a/vendor/github.com/mattermost/logr/levelcache.go +++ /dev/null @@ -1,98 +0,0 @@ -package logr - -import ( - "fmt" - "sync" -) - -// LevelStatus represents whether a level is enabled and -// requires a stack trace. -type LevelStatus struct { - Enabled bool - Stacktrace bool - empty bool -} - -type levelCache interface { - setup() - get(id LevelID) (LevelStatus, bool) - put(id LevelID, status LevelStatus) error - clear() -} - -// syncMapLevelCache uses sync.Map which may better handle large concurrency -// scenarios. -type syncMapLevelCache struct { - m sync.Map -} - -func (c *syncMapLevelCache) setup() { - c.clear() -} - -func (c *syncMapLevelCache) get(id LevelID) (LevelStatus, bool) { - if id > MaxLevelID { - return LevelStatus{}, false - } - s, _ := c.m.Load(id) - status := s.(LevelStatus) - return status, !status.empty -} - -func (c *syncMapLevelCache) put(id LevelID, status LevelStatus) error { - if id > MaxLevelID { - return fmt.Errorf("level id cannot exceed MaxLevelID (%d)", MaxLevelID) - } - c.m.Store(id, status) - return nil -} - -func (c *syncMapLevelCache) clear() { - var i LevelID - for i = 0; i < MaxLevelID; i++ { - c.m.Store(i, LevelStatus{empty: true}) - } -} - -// arrayLevelCache using array and a mutex. -type arrayLevelCache struct { - arr [MaxLevelID + 1]LevelStatus - mux sync.RWMutex -} - -func (c *arrayLevelCache) setup() { - c.clear() -} - -//var dummy = LevelStatus{} - -func (c *arrayLevelCache) get(id LevelID) (LevelStatus, bool) { - if id > MaxLevelID { - return LevelStatus{}, false - } - c.mux.RLock() - status := c.arr[id] - ok := !status.empty - c.mux.RUnlock() - return status, ok -} - -func (c *arrayLevelCache) put(id LevelID, status LevelStatus) error { - if id > MaxLevelID { - return fmt.Errorf("level id cannot exceed MaxLevelID (%d)", MaxLevelID) - } - c.mux.Lock() - defer c.mux.Unlock() - - c.arr[id] = status - return nil -} - -func (c *arrayLevelCache) clear() { - c.mux.Lock() - defer c.mux.Unlock() - - for i := range c.arr { - c.arr[i] = LevelStatus{empty: true} - } -} |