Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
internal/ceb: use CAS rather than set channel nil
Browse files Browse the repository at this point in the history
This lets us continue to check using a channel read.
  • Loading branch information
mitchellh committed Nov 29, 2020
1 parent 025203a commit deb54d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/ceb/ceb.go
Expand Up @@ -72,7 +72,8 @@ type CEB struct {
// FIRST child command is ready to be started. This can be closed before
// any command is sent to childCmdCh. It indicates that the child process
// watcher can begin executing.
childReadyCh chan struct{}
childReadySent uint32
childReadyCh chan struct{}

// childCmdBase is the base command to use for making any changes to the
// child; use the copyCmd() function to copy this safetly to make changes.
Expand Down
4 changes: 2 additions & 2 deletions internal/ceb/child_exec.go
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"sync/atomic"
"syscall"
"time"

Expand Down Expand Up @@ -41,9 +42,8 @@ func (ceb *CEB) initChildCmd(ctx context.Context, cfg *config) error {
// markChildCmdReady will allow watchChildCmd to begin executing commands.
// This should be called once and should not be called concurrently.
func (ceb *CEB) markChildCmdReady() {
if ceb.childReadyCh != nil {
if atomic.CompareAndSwapUint32(&ceb.childReadySent, 0, 1) {
close(ceb.childReadyCh)
ceb.childReadyCh = nil
}
}

Expand Down

0 comments on commit deb54d0

Please sign in to comment.