File tree Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Original file line number Diff line number Diff line change @@ -397,13 +397,13 @@ func (d dockerOpt) GetKV() (string, string) {
397
397
return d .key , d .value
398
398
}
399
399
400
- // writeLimiter limits the total output written across one or more streams.
401
- type writeLimiter struct {
400
+ // sharedWriteLimiter limits the total output written across one or more streams.
401
+ type sharedWriteLimiter struct {
402
402
delegate io.Writer
403
403
limit * int64
404
404
}
405
405
406
- func (w writeLimiter ) Write (p []byte ) (int , error ) {
406
+ func (w sharedWriteLimiter ) Write (p []byte ) (int , error ) {
407
407
if len (p ) == 0 {
408
408
return 0 , nil
409
409
}
@@ -418,11 +418,7 @@ func (w writeLimiter) Write(p []byte) (int, error) {
418
418
}
419
419
n , err := w .delegate .Write (p )
420
420
if n > 0 {
421
- newLimit := limit - int64 (n )
422
- for ! atomic .CompareAndSwapInt64 (w .limit , limit , newLimit ) {
423
- limit = atomic .LoadInt64 (w .limit )
424
- newLimit = limit - int64 (n )
425
- }
421
+ atomic .AddInt64 (w .limit , - 1 * int64 (n ))
426
422
}
427
423
if err == nil && truncated {
428
424
err = errMaximumWrite
@@ -434,7 +430,7 @@ func limitedWriter(w io.Writer, limit *int64) io.Writer {
434
430
if w == nil {
435
431
return nil
436
432
}
437
- return & writeLimiter {
433
+ return & sharedWriteLimiter {
438
434
delegate : w ,
439
435
limit : limit ,
440
436
}
You can’t perform that action at this time.
0 commit comments