Skip to content

Commit

Permalink
Add comments for singleInstance creation mechanism in giteaclient.go (n…
Browse files Browse the repository at this point in the history
…ephio-project#534)

This change removes a conditional statement which is never executed.

---------

Signed-off-by: Kushal Harish Naidu <[email protected]>
  • Loading branch information
kushnaidu authored and PrimalPimmy committed Aug 2, 2024
1 parent fc9b901 commit ac6d0e0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion controllers/pkg/giteaclient/giteaclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ func GetClient(ctx context.Context, client resource.APIPatchingApplicator) (Gite
if client.Client == nil {
return nil, fmt.Errorf("failed creating gitea client, value of client.Client cannot be nil")
}

// check if an instance is created using check-lock-check pattern implementation
if singleInstance == nil {
// Create a lock
lock.Lock()
defer lock.Unlock()
// Check instance is still null as another thread of execution may have initialized it before the lock was acquired.
if singleInstance == nil {
singleInstance = &gc{client: client}
log.FromContext(ctx).Info("Gitea Client Instance created now.")
Expand Down

0 comments on commit ac6d0e0

Please sign in to comment.