diff options
author | Dario Maiocchi <dmaiocchi@suse.com> | 2017-11-20 22:58:08 +0100 |
---|---|---|
committer | Alvaro <alvaro.saurin@gmail.com> | 2017-11-22 16:41:34 +0100 |
commit | 88c0dfcca51f4d301810380dacd119a9f291417c (patch) | |
tree | 3cc1989971c79abf043da151d761f21eb3c67a7c /libvirt/pool_sync.go | |
parent | 61fe2db30a7bb1f953c147cf9abbc0447fea2fce (diff) | |
download | terraform-provider-libvirt-88c0dfcca51f4d301810380dacd119a9f291417c.tar terraform-provider-libvirt-88c0dfcca51f4d301810380dacd119a9f291417c.tar.gz |
use poolMutexKV for locking resources.
Diffstat (limited to 'libvirt/pool_sync.go')
-rw-r--r-- | libvirt/pool_sync.go | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/libvirt/pool_sync.go b/libvirt/pool_sync.go deleted file mode 100644 index a50528bc..00000000 --- a/libvirt/pool_sync.go +++ /dev/null @@ -1,49 +0,0 @@ -package libvirt - -import ( - "sync" -) - -// LVirtPoolSync makes possible to synchronize operations -// against libvirt pools. -// Doing pool.Refresh() operations while uploading or removing -// a volume into the pool causes errors inside of libvirtd -type LVirtPoolSync struct { - PoolLocks map[string]*sync.Mutex - internalMutex sync.Mutex -} - -// NewLVirtPoolSync allocates a new instance of LVirtPoolSync -func NewLVirtPoolSync() LVirtPoolSync { - pool := LVirtPoolSync{} - pool.PoolLocks = make(map[string]*sync.Mutex) - - return pool -} - -// AcquireLock acquires a lock for the specified pool -func (ps LVirtPoolSync) AcquireLock(pool string) { - ps.internalMutex.Lock() - defer ps.internalMutex.Unlock() - - lock, exists := ps.PoolLocks[pool] - if !exists { - lock = new(sync.Mutex) - ps.PoolLocks[pool] = lock - } - - lock.Lock() -} - -// ReleaseLock releases the look for the specified pool -func (ps LVirtPoolSync) ReleaseLock(pool string) { - ps.internalMutex.Lock() - defer ps.internalMutex.Unlock() - - lock, exists := ps.PoolLocks[pool] - if !exists { - return - } - - lock.Unlock() -} |