mirror of
https://github.com/multipleof4/ntfy.git
synced 2026-10-16 08:27:55 +00:00
RWMutex
This commit is contained in:
+5
-5
@@ -34,7 +34,7 @@ type Store struct {
|
|||||||
sizes map[string]int64 // File ID -> size, for subtracting on Remove
|
sizes map[string]int64 // File ID -> size, for subtracting on Remove
|
||||||
localIDs func() ([]string, error) // Returns file IDs that should exist locally, used for sync()
|
localIDs func() ([]string, error) // Returns file IDs that should exist locally, used for sync()
|
||||||
closeChan chan struct{}
|
closeChan chan struct{}
|
||||||
mu sync.Mutex // Protects size and sizes
|
mu sync.RWMutex // Protects size and sizes
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFileStore creates a new file-system backed attachment cache
|
// NewFileStore creates a new file-system backed attachment cache
|
||||||
@@ -191,15 +191,15 @@ func (c *Store) sync() error {
|
|||||||
|
|
||||||
// Size returns the current total size of all attachments
|
// Size returns the current total size of all attachments
|
||||||
func (c *Store) Size() int64 {
|
func (c *Store) Size() int64 {
|
||||||
c.mu.Lock()
|
c.mu.RLock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.RUnlock()
|
||||||
return c.size
|
return c.size
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remaining returns the remaining capacity for attachments
|
// Remaining returns the remaining capacity for attachments
|
||||||
func (c *Store) Remaining() int64 {
|
func (c *Store) Remaining() int64 {
|
||||||
c.mu.Lock()
|
c.mu.RLock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.RUnlock()
|
||||||
remaining := c.limit - c.size
|
remaining := c.limit - c.size
|
||||||
if remaining < 0 {
|
if remaining < 0 {
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user