Merge pull request #8628 from hangscer8/clean_atomicBool
This commit is contained in:
commit
f3a07934b4
@ -27,6 +27,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
@ -62,7 +63,7 @@ type Init struct {
|
|||||||
io *processIO
|
io *processIO
|
||||||
runtime *runc.Runc
|
runtime *runc.Runc
|
||||||
// pausing preserves the pausing state.
|
// pausing preserves the pausing state.
|
||||||
pausing *atomicBool
|
pausing atomic.Bool
|
||||||
status int
|
status int
|
||||||
exited time.Time
|
exited time.Time
|
||||||
pid int
|
pid int
|
||||||
@ -97,7 +98,6 @@ func New(id string, runtime *runc.Runc, stdio stdio.Stdio) *Init {
|
|||||||
p := &Init{
|
p := &Init{
|
||||||
id: id,
|
id: id,
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
pausing: new(atomicBool),
|
|
||||||
stdio: stdio,
|
stdio: stdio,
|
||||||
status: 0,
|
status: 0,
|
||||||
waitBlock: make(chan struct{}),
|
waitBlock: make(chan struct{}),
|
||||||
@ -240,7 +240,7 @@ func (p *Init) ExitedAt() time.Time {
|
|||||||
|
|
||||||
// Status of the process
|
// Status of the process
|
||||||
func (p *Init) Status(ctx context.Context) (string, error) {
|
func (p *Init) Status(ctx context.Context) (string, error) {
|
||||||
if p.pausing.get() {
|
if p.pausing.Load() {
|
||||||
return "pausing", nil
|
return "pausing", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,12 +235,12 @@ func (s *runningState) transition(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *runningState) Pause(ctx context.Context) error {
|
func (s *runningState) Pause(ctx context.Context) error {
|
||||||
s.p.pausing.set(true)
|
s.p.pausing.Store(true)
|
||||||
// NOTE "pausing" will be returned in the short window
|
// NOTE "pausing" will be returned in the short window
|
||||||
// after `transition("paused")`, before `pausing` is reset
|
// after `transition("paused")`, before `pausing` is reset
|
||||||
// to false. That doesn't break the state machine, just
|
// to false. That doesn't break the state machine, just
|
||||||
// delays the "paused" state a little bit.
|
// delays the "paused" state a little bit.
|
||||||
defer s.p.pausing.set(false)
|
defer s.p.pausing.Store(false)
|
||||||
|
|
||||||
if err := s.p.runtime.Pause(ctx, s.p.id); err != nil {
|
if err := s.p.runtime.Pause(ctx, s.p.id); err != nil {
|
||||||
return s.p.runtimeError(err, "OCI runtime pause failed")
|
return s.p.runtimeError(err, "OCI runtime pause failed")
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
@ -54,20 +53,6 @@ func (s *safePid) get() int {
|
|||||||
return s.pid
|
return s.pid
|
||||||
}
|
}
|
||||||
|
|
||||||
type atomicBool int32
|
|
||||||
|
|
||||||
func (ab *atomicBool) set(b bool) {
|
|
||||||
if b {
|
|
||||||
atomic.StoreInt32((*int32)(ab), 1)
|
|
||||||
} else {
|
|
||||||
atomic.StoreInt32((*int32)(ab), 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ab *atomicBool) get() bool {
|
|
||||||
return atomic.LoadInt32((*int32)(ab)) == 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(mlaventure): move to runc package?
|
// TODO(mlaventure): move to runc package?
|
||||||
func getLastRuntimeError(r *runc.Runc) (string, error) {
|
func getLastRuntimeError(r *runc.Runc) (string, error) {
|
||||||
if r.Log == "" {
|
if r.Log == "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user