Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/nvml/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package nvml
//go:generate moq -out mock/extendedinterface.go -pkg mock . ExtendedInterface:ExtendedInterface
type ExtendedInterface interface {
LookupSymbol(string) error
GetErrors() []error
}

// libraryOptions hold the paramaters than can be set by a LibraryOption
Expand Down
17 changes: 15 additions & 2 deletions pkg/nvml/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type library struct {
path string
refcount refcount
dl dynamicLibrary

errors []error
}

var _ Interface = (*library)(nil)
Expand Down Expand Up @@ -98,13 +100,21 @@ func (l *library) LookupSymbol(name string) error {
return l.dl.Lookup(name)
}

// GetErrors returns errors that are associated with the library but not NVML.
func (l *library) GetErrors() []error {
return l.errors
}

// load initializes the library and updates the versioned symbols.
// Multiple calls to an already loaded library will return without error.
func (l *library) load() (rerr error) {
l.Lock()
defer l.Unlock()

defer func() { l.refcount.IncOnNoError(rerr) }()
defer func() {
l.errors = append(l.errors, rerr)
l.refcount.IncOnNoError(rerr)
}()
if l.refcount > 0 {
return nil
}
Expand All @@ -129,7 +139,10 @@ func (l *library) close() (rerr error) {
l.Lock()
defer l.Unlock()

defer func() { l.refcount.DecOnNoError(rerr) }()
defer func() {
l.errors = append(l.errors, rerr)
l.refcount.DecOnNoError(rerr)
}()
if l.refcount != 1 {
return nil
}
Expand Down