'Generates a new, unique task_id.'

def GenerateTaskID(self):

    random_number = (utils.PRNG.GetUShort() + 1)
    with GrrMessage.lock:
        next_id_base = GrrMessage.next_id_base
        id_base = ((next_id_base + random_number) & 4294967295)
        if (id_base < next_id_base):
            time.sleep(0.001)
        GrrMessage.next_id_base = id_base
    time_base = ((long((time.time() * 1000)) & 536870911) << 32)
    priority_prefix = (self.max_priority - self.priority)
    task_id = (time_base | id_base)
    task_id |= (priority_prefix << 61)
    self.Set('task_id', task_id)
    return task_id
