mirror of
https://github.com/oracle/zfssa-csi-driver.git
synced 2025-09-07 23:59:32 +00:00
Initial publication of ZFSSA CSI driver
This commit is contained in:
42
pkg/utils/sync.go
Normal file
42
pkg/utils/sync.go
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates.
|
||||
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
||||
*/
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Bolt struct {
|
||||
mutex sync.Mutex
|
||||
cv *sync.Cond
|
||||
context context.Context
|
||||
}
|
||||
|
||||
func NewBolt() *Bolt {
|
||||
bolt := new(Bolt)
|
||||
bolt.cv = sync.NewCond(&bolt.mutex)
|
||||
return bolt
|
||||
}
|
||||
|
||||
func (l *Bolt) Lock(ctx context.Context) {
|
||||
l.mutex.Lock()
|
||||
for l.context != nil {
|
||||
l.cv.Wait()
|
||||
}
|
||||
l.context = ctx
|
||||
l.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (l *Bolt) Unlock(ctx context.Context) {
|
||||
l.mutex.Lock()
|
||||
if l.context != ctx {
|
||||
panic("wrong owner unlocking fs")
|
||||
}
|
||||
l.context = nil
|
||||
l.cv.Signal()
|
||||
l.mutex.Unlock()
|
||||
}
|
Reference in New Issue
Block a user