File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ type JsonDB struct {
2222}
2323
2424var jsonDbLocks = make (map [string ]* sync.Mutex )
25+ var jsonDbLocksMutex sync.Mutex
2526
2627func NewJsonDB () TorrServerDB {
2728 settingsDB := & JsonDB {
@@ -109,18 +110,22 @@ func (v *JsonDB) Rem(xPath, name string) {
109110}
110111
111112func (v * JsonDB ) lock (filename string ) {
112- var mtx sync.Mutex
113- if mtx , ok := jsonDbLocks [filename ]; ! ok {
114- mtx = new (sync.Mutex )
115- jsonDbLocks [v .Path ] = mtx
113+ jsonDbLocksMutex .Lock ()
114+ mtx , ok := jsonDbLocks [filename ]
115+ if ! ok {
116+ mtx = & sync.Mutex {}
117+ jsonDbLocks [filename ] = mtx
116118 }
119+ jsonDbLocksMutex .Unlock ()
117120 mtx .Lock ()
118121}
119122
120123func (v * JsonDB ) unlock (filename string ) {
124+ jsonDbLocksMutex .Lock ()
121125 if mtx , ok := jsonDbLocks [filename ]; ok {
122126 mtx .Unlock ()
123127 }
128+ jsonDbLocksMutex .Unlock ()
124129}
125130
126131func (v * JsonDB ) xPathToFilename (xPath string ) (string , error ) {
You can’t perform that action at this time.
0 commit comments