move the task_cancelled() check under mutex. Also remove the redundant check