mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 04:53:09 +08:00
feat(drivers): add a driver that divides large files into multiple chunks (#1153)
This commit is contained in:
@@ -57,6 +57,11 @@ var (
|
||||
Supported []*HashType
|
||||
)
|
||||
|
||||
func GetHashByName(name string) (ht *HashType, ok bool) {
|
||||
ht, ok = name2hash[name]
|
||||
return
|
||||
}
|
||||
|
||||
// RegisterHash adds a new Hash to the list and returns its Type
|
||||
func RegisterHash(name, alias string, width int, newFunc func() hash.Hash) *HashType {
|
||||
return RegisterHashWithParam(name, alias, width, func(a ...any) hash.Hash { return newFunc() })
|
||||
|
||||
+26
-15
@@ -200,26 +200,37 @@ type SyncClosers struct {
|
||||
var _ SyncClosersIF = (*SyncClosers)(nil)
|
||||
|
||||
func (c *SyncClosers) AcquireReference() bool {
|
||||
ref := atomic.AddInt32(&c.ref, 1)
|
||||
if ref > 0 {
|
||||
// log.Debugf("SyncClosers.AcquireReference %p,ref=%d\n", c, ref)
|
||||
return true
|
||||
for {
|
||||
ref := atomic.LoadInt32(&c.ref)
|
||||
if ref < 0 {
|
||||
return false
|
||||
}
|
||||
newRef := ref + 1
|
||||
if atomic.CompareAndSwapInt32(&c.ref, ref, newRef) {
|
||||
log.Debugf("AcquireReference %p: %d", c, newRef)
|
||||
return true
|
||||
}
|
||||
}
|
||||
atomic.StoreInt32(&c.ref, math.MinInt16)
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *SyncClosers) Close() error {
|
||||
ref := atomic.AddInt32(&c.ref, -1)
|
||||
if ref < -1 {
|
||||
atomic.StoreInt32(&c.ref, math.MinInt16)
|
||||
return nil
|
||||
for {
|
||||
ref := atomic.LoadInt32(&c.ref)
|
||||
if ref < 0 {
|
||||
return nil
|
||||
}
|
||||
newRef := ref - 1
|
||||
if newRef <= 0 {
|
||||
newRef = math.MinInt16
|
||||
}
|
||||
if atomic.CompareAndSwapInt32(&c.ref, ref, newRef) {
|
||||
log.Debugf("Close %p: %d", c, ref)
|
||||
if newRef > 0 {
|
||||
return nil
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
// log.Debugf("SyncClosers.Close %p,ref=%d\n", c, ref+1)
|
||||
if ref > 0 {
|
||||
return nil
|
||||
}
|
||||
atomic.StoreInt32(&c.ref, math.MinInt16)
|
||||
|
||||
var errs []error
|
||||
for _, closer := range c.closers {
|
||||
|
||||
Reference in New Issue
Block a user