// Copyright 2018 gf Author(https://github.com/gogf/gf). All Rights Reserved. // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. // Package gmlock implements a concurrent-safe memory-based locker. package gmlock var ( // Default locker. locker = New() ) // Lock locks the with writing lock. // If there's a write/reading lock the , // it will blocks until the lock is released. func Lock(key string) { locker.Lock(key) } // TryLock tries locking the with writing lock, // it returns true if success, or if there's a write/reading lock the , // it returns false. func TryLock(key string) bool { return locker.TryLock(key) } // Unlock unlocks the writing lock of the . func Unlock(key string) { locker.Unlock(key) } // RLock locks the with reading lock. // If there's a writing lock on , // it will blocks until the writing lock is released. func RLock(key string) { locker.RLock(key) } // TryRLock tries locking the with reading lock. // It returns true if success, or if there's a writing lock on , it returns false. func TryRLock(key string) bool { return locker.TryRLock(key) } // RUnlock unlocks the reading lock of the . func RUnlock(key string) { locker.RUnlock(key) } // LockFunc locks the with writing lock and callback function . // If there's a write/reading lock the , // it will blocks until the lock is released. // // It releases the lock after is executed. func LockFunc(key string, f func()) { locker.LockFunc(key, f) } // RLockFunc locks the with reading lock and callback function . // If there's a writing lock the , // it will blocks until the lock is released. // // It releases the lock after is executed. func RLockFunc(key string, f func()) { locker.RLockFunc(key, f) } // TryLockFunc locks the with writing lock and callback function . // It returns true if success, or else if there's a write/reading lock the , it return false. // // It releases the lock after is executed. func TryLockFunc(key string, f func()) bool { return locker.TryLockFunc(key, f) } // TryRLockFunc locks the with reading lock and callback function . // It returns true if success, or else if there's a writing lock the , it returns false. // // It releases the lock after is executed. func TryRLockFunc(key string, f func()) bool { return locker.TryRLockFunc(key, f) } // Remove removes mutex with given . func Remove(key string) { locker.Remove(key) }