Cleared up a potential eternal loop.
TRQ-2237 unlock a mutex before trying to lock the job mutex.
trq-2187 and trq-2007 recheck a count after losing the job mutex to make sure we haven't already changed the state.