golang mfs - additional sync structs ant methods
mfs.RWTMutex is like sync.RWMutex
mx := mfs.RWTMutex{}
mx.Lock()
// DO Something
mx.Unlock()
and mfs.RWTMutex contains TryLock
// ctx - sime context
ctx := context.Background()
mx := mfs.RWTMutex{}
isLocked := mx.TryLock(ctx)
if isLocked {
// DO Something
mx.Unlock()
} else {
// DO Something else
}
mfs.PMutex is like sync.RWMutex
mfs.PMutex is like mfs.RWTMutex
mx := mfs.RWTMutex{}
mx.Lock()
// DO Something
mx.Reduce()
// Now mutex like RLock()
// DO Something
mx.RUnlock()
mx := mfs.RWTMutex{}
mx.RLock()
// DO Something
mx.Promote()
// Now mutex like Lock()
// DO Something
mx.Unlock()
// ctx is some context
mx := mfs.RWTMutex{}
mx.RLock()
// DO Something
isLocked := mx.TryPromote()
if isLocked {
// Now mutex like Lock()
// DO Something
mx.Unlock()
} else {
// Mutex is not locked (like call mx.RUnlock())
// DO Something else
}
It should be locked befor regular methods like Lock or Promote are
Ilya Shcherbina
+7(903)192-4239
[email protected]