Merge pull request #923 from vieux/improve_locks_mesos

Improve locks mesos
This commit is contained in:
Victor Vieux 2015-06-09 13:58:06 -07:00
commit 722b0e962d
2 changed files with 5 additions and 8 deletions

View File

@ -397,7 +397,7 @@ func (c *Cluster) scheduleTask(t *task) bool {
for _, offer := range s.offers {
c.removeOffer(offer)
}
s.Unlock()
c.Unlock()
t.error <- err
return true
}

View File

@ -21,27 +21,23 @@ func NewQueue() *Queue {
// Add tries to Do the item, if it's not possible, add the item to the queue for future tries
func (q *Queue) Add(item Item) {
q.Lock()
defer q.Unlock()
if !item.Do() {
q.Lock()
q.items[item.ID()] = item
q.Unlock()
}
}
// Remove an item from the queue
func (q *Queue) Remove(items ...Item) {
q.Lock()
defer q.Unlock()
q.remove(items...)
q.Unlock()
}
// Process tries to Do all the items in the queue and remove the items successfully done
func (q *Queue) Process() {
q.Lock()
defer q.Unlock()
toRemove := []Item{}
for _, item := range q.items {
if item.Do() {
@ -50,6 +46,7 @@ func (q *Queue) Process() {
}
q.remove(toRemove...)
q.Unlock()
}
func (q *Queue) remove(items ...Item) {