This repository was archived by the owner on Jan 28, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-15
lines changed Expand file tree Collapse file tree 1 file changed +6
-15
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,8 @@ import (
20
20
type mapping struct {
21
21
path string
22
22
23
- mut sync.RWMutex
24
- txmut sync.RWMutex
25
- db * bolt.DB
23
+ mut sync.RWMutex
24
+ db * bolt.DB
26
25
27
26
// in create mode there's only one transaction closed explicitly by
28
27
// commit function
@@ -129,20 +128,19 @@ func (m *mapping) rollback() error {
129
128
}
130
129
131
130
func (m * mapping ) transaction (writable bool , f func (* bolt.Tx ) error ) error {
131
+ m .clientMut .Lock ()
132
+ defer m .clientMut .Unlock ()
133
+
132
134
var tx * bolt.Tx
133
135
var err error
134
136
if m .create {
135
- m .clientMut .Lock ()
136
137
if m .tx == nil {
137
138
m .tx , err = m .db .Begin (true )
138
139
if err != nil {
139
- m .clientMut .Unlock ()
140
140
return err
141
141
}
142
142
}
143
143
144
- m .clientMut .Unlock ()
145
-
146
144
tx = m .tx
147
145
} else {
148
146
tx , err = m .db .Begin (writable )
@@ -151,15 +149,8 @@ func (m *mapping) transaction(writable bool, f func(*bolt.Tx) error) error {
151
149
}
152
150
}
153
151
154
- m .txmut .Lock ()
155
152
err = f (tx )
156
- m .txmut .Unlock ()
157
-
158
- m .clientMut .Lock ()
159
- create := m .create
160
- m .clientMut .Unlock ()
161
-
162
- if create {
153
+ if m .create {
163
154
return err
164
155
}
165
156
You can’t perform that action at this time.
0 commit comments