Skip to content

Commit 7c5ae60

Browse files
committed
memfs: Remove memfs.WithoutMutex
Ensure memfs is thread-safe at all times. In case the single thread performance is more important (probably outside of go-git) that can be fixed with future optimisation. In the context of go-git, this should not be a concern as there are other bottlenecks (e.g. sha1cd). Signed-off-by: Paulo Gomes <[email protected]>
1 parent a989507 commit 7c5ae60

File tree

5 files changed

+6
-63
lines changed

5 files changed

+6
-63
lines changed

memfs/memory.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,17 @@ const separator = filepath.Separator
2222
// Memory a very convenient filesystem based on memory files.
2323
type Memory struct {
2424
s *storage
25-
26-
m mutex
2725
}
2826

2927
// New returns a new Memory filesystem.
3028
func New(opts ...Option) billy.Filesystem {
31-
o := &options{
32-
// Enable thread-safety by default.
33-
newMutex: newMutex,
34-
}
35-
29+
o := &options{}
3630
for _, opt := range opts {
3731
opt(o)
3832
}
3933

4034
fs := &Memory{
41-
s: newStorage(o.newMutex),
42-
m: o.newMutex(),
35+
s: newStorage(),
4336
}
4437
_, err := fs.s.New("/", 0755|os.ModeDir, 0)
4538
if err != nil {

memfs/memory_option.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,4 @@ package memfs
33
type Option func(*options)
44

55
type options struct {
6-
newMutex func() mutex
7-
}
8-
9-
// WithoutMutex disables thread safety. This is a temporary option
10-
// for users to opt-out from the default setting.
11-
func WithoutMutex() Option {
12-
return func(o *options) {
13-
o.newMutex = newNoOpMutex
14-
}
156
}

memfs/mutex.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

memfs/storage.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"strings"
9+
"sync"
910
"time"
1011

1112
"github.com/go-git/go-billy/v6"
@@ -15,16 +16,14 @@ type storage struct {
1516
files map[string]*file
1617
children map[string]map[string]*file
1718

18-
mf mutex
19-
mc mutex
19+
mf sync.RWMutex
20+
mc sync.RWMutex
2021
}
2122

22-
func newStorage(newMutex func() mutex) *storage {
23+
func newStorage() *storage {
2324
return &storage{
2425
files: make(map[string]*file, 0),
2526
children: make(map[string]map[string]*file, 0),
26-
mc: newMutex(),
27-
mf: newMutex(),
2827
}
2928
}
3029

test/bench_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ func BenchmarkCompare(b *testing.B) {
5555
{
5656
name: "memfs",
5757
fn: fn,
58-
sut: memfs.New(memfs.WithoutMutex()),
59-
openF: billyOpen,
60-
createF: billyCreate,
61-
},
62-
{
63-
name: "memfs_mutex",
64-
fn: fn,
6558
sut: memfs.New(),
6659
openF: billyOpen,
6760
createF: billyCreate,

0 commit comments

Comments
 (0)