put a limit on how many deliveries we actually send it in parallel

This commit is contained in:
Ted Unangst 2019-04-16 20:34:27 -04:00
parent 562d4e34c1
commit 7d538d465f
1 changed files with 25 additions and 0 deletions

View File

@ -18,6 +18,7 @@ package main
import (
"log"
notrand "math/rand"
"sync"
"time"
)
@ -54,7 +55,31 @@ func sayitagain(goarounds int, username string, rcpt string, msg []byte) {
}
}
var trucksout = 0
var maxtrucksout = 10
var garagelock sync.Mutex
var garagebell = sync.NewCond(&garagelock)
func truckgoesout() {
garagelock.Lock()
for trucksout >= maxtrucksout {
garagebell.Wait()
}
trucksout++
garagelock.Unlock()
}
func truckcomesin() {
garagelock.Lock()
trucksout--
garagebell.Broadcast()
garagelock.Unlock()
}
func deliverate(goarounds int, username string, rcpt string, msg []byte) {
truckgoesout()
defer truckcomesin()
keyname, key := ziggy(username)
var inbox string
// already did the box indirection