Merge pull request #119 from dagger/small-cleanup

Small cleanup
This commit is contained in:
Andrea Luzzardi 2021-02-16 14:41:18 -08:00 committed by GitHub
commit 31f1cd9f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 27 deletions

View File

@ -35,19 +35,3 @@ func Err(err error) error {
}
return errors.New(cueerrors.Details(err, &cueerrors.Config{}))
}
func Lock() {
cc.Lock()
}
func Unlock() {
cc.Unlock()
}
func RLock() {
cc.RLock()
}
func RUnlock() {
cc.RUnlock()
}

View File

@ -10,10 +10,26 @@ import (
// (we call it compiler to avoid confusion with dagger runtime)
// Use this instead of cue.Runtime
type Compiler struct {
sync.RWMutex
l sync.RWMutex
cue.Runtime
}
func (cc *Compiler) lock() {
cc.l.Lock()
}
func (cc *Compiler) unlock() {
cc.l.Unlock()
}
func (cc *Compiler) rlock() {
cc.l.RLock()
}
func (cc *Compiler) runlock() {
cc.l.RUnlock()
}
func (cc *Compiler) Cue() *cue.Runtime {
return &(cc.Runtime)
}
@ -24,8 +40,8 @@ func (cc *Compiler) EmptyStruct() (*Value, error) {
}
func (cc *Compiler) Compile(name string, src interface{}) (*Value, error) {
cc.Lock()
defer cc.Unlock()
cc.lock()
defer cc.unlock()
inst, err := cc.Cue().Compile(name, src)
if err != nil {

View File

@ -29,8 +29,8 @@ func wrapValue(v cue.Value, inst *cue.Instance) *Value {
// Fill the value in-place, unlike Merge which returns a copy.
func (v *Value) Fill(x interface{}) error {
cc.Lock()
defer cc.Unlock()
cc.lock()
defer cc.unlock()
// If calling Fill() with a Value, we want to use the underlying
// cue.Value to fill.
@ -44,8 +44,8 @@ func (v *Value) Fill(x interface{}) error {
// LookupPath is a concurrency safe wrapper around cue.Value.LookupPath
func (v *Value) LookupPath(p cue.Path) *Value {
cc.RLock()
defer cc.RUnlock()
cc.rlock()
defer cc.runlock()
return v.Wrap(v.val.LookupPath(p))
}
@ -147,9 +147,9 @@ func (v *Value) Merge(x interface{}, path ...string) (*Value, error) {
x = xval.val
}
cc.Lock()
cc.lock()
result := v.Wrap(v.val.Fill(x, path...))
cc.Unlock()
cc.unlock()
return result, result.Validate()
}
@ -220,8 +220,8 @@ func (v *Value) Validate() error {
// Return cue source for this value
func (v *Value) Source() ([]byte, error) {
cc.RLock()
defer cc.RUnlock()
cc.rlock()
defer cc.runlock()
return cueformat.Node(v.val.Eval().Syntax())
}