Improve gearman shutdown with extra thread lock checks

When quiting turbo-hipster make sure all threads stop properly.
Previously when the gearman_client disconnects the waitForServer
method would release and the client would then wait for a job
it isn't going to receive because turbo-hipster is shutting down.

Change-Id: If9c13e4858c2281c021ca4540ec9475c4d46c615