Rather than manually pass around a $table_already_locked method add a method to lock which checks if the lock is currently owned?