优化并发读写限制

This commit is contained in:
GoEdgeLab
2024-05-01 12:42:35 +08:00
parent 2b35971a66
commit c50a0de9eb
5 changed files with 59 additions and 8 deletions

View File

@@ -2,7 +2,9 @@
package fsutils
import "os"
import (
"os"
)
func Remove(filename string) (err error) {
WriterLimiter.Ack()
@@ -31,3 +33,24 @@ func WriteFile(filename string, data []byte, perm os.FileMode) (err error) {
WriterLimiter.Release()
return
}
func OpenFile(name string, flag int, perm os.FileMode) (f *os.File, err error) {
if flag&os.O_RDONLY == os.O_RDONLY {
ReaderLimiter.Ack()
}
f, err = os.OpenFile(name, flag, perm)
if flag&os.O_RDONLY == os.O_RDONLY {
ReaderLimiter.Release()
}
return
}
func Open(name string) (f *os.File, err error) {
ReaderLimiter.Ack()
f, err = os.Open(name)
ReaderLimiter.Release()
return
}