File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import (
21
21
"io/ioutil"
22
22
"os"
23
23
"path/filepath"
24
+ "sync"
24
25
25
26
oci "github.com/opencontainers/runtime-spec/specs-go"
26
27
"github.com/pkg/errors"
41
42
42
43
// Externally set CDI Spec validation function.
43
44
specValidator func (* cdi.Spec ) error
45
+ validatorLock sync.RWMutex
44
46
)
45
47
46
48
// Spec represents a single CDI Spec. It is usually loaded from a
@@ -249,11 +251,16 @@ func ParseSpec(data []byte) (*cdi.Spec, error) {
249
251
// is used for extra CDI Spec content validation whenever a Spec file
250
252
// loaded (using ReadSpec() or NewSpec()) or written (Spec.Write()).
251
253
func SetSpecValidator (fn func (* cdi.Spec ) error ) {
254
+ validatorLock .Lock ()
255
+ defer validatorLock .Unlock ()
252
256
specValidator = fn
253
257
}
254
258
255
259
// validateSpec validates the Spec using the extneral validator.
256
260
func validateSpec (raw * cdi.Spec ) error {
261
+ validatorLock .RLock ()
262
+ defer validatorLock .RUnlock ()
263
+
257
264
if specValidator == nil {
258
265
return nil
259
266
}
You can’t perform that action at this time.
0 commit comments