<commit_before>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "isequencedtaskexecutor.h"
#include <vector>

namespace vespalib {
    struct ExecutorStats;
    class SyncableThreadExecutor;
}

namespace search {

/**
 * Class to run multiple tasks in parallel, but tasks with same
 * id has to be run in sequence.
 */
class SequencedTaskExecutor final : public ISequencedTaskExecutor
{
    using Stats = vespalib::ExecutorStats;
    std::unique_ptr<std::vector<std::unique_ptr<vespalib::SyncableThreadExecutor>>> _executors;

    SequencedTaskExecutor(std::unique_ptr<std::vector<std::unique_ptr<vespalib::SyncableThreadExecutor>>> executor);
public:
    enum class Optimize {LATENCY, THROUGHPUT};
    using ISequencedTaskExecutor::getExecutorId;

    ~SequencedTaskExecutor();

    void setTaskLimit(uint32_t taskLimit) override;
    void executeTask(ExecutorId id, vespalib::Executor::Task::UP task) override;
    void sync() override;
    Stats getStats() override;
    static std::unique_ptr<ISequencedTaskExecutor> create(uint32_t threads, uint32_t taskLimit = 1000, Optimize optimize = Optimize::THROUGHPUT);
};

} // namespace search<commit_msg>Add comment about thread safety.<commit_after>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "isequencedtaskexecutor.h"
#include <vector>

namespace vespalib {
    struct ExecutorStats;
    class SyncableThreadExecutor;
}

namespace search {

/**
 * Class to run multiple tasks in parallel, but tasks with same
 * id has to be run in sequence.
 */
class SequencedTaskExecutor final : public ISequencedTaskExecutor
{
    using Stats = vespalib::ExecutorStats;
    std::unique_ptr<std::vector<std::unique_ptr<vespalib::SyncableThreadExecutor>>> _executors;

    SequencedTaskExecutor(std::unique_ptr<std::vector<std::unique_ptr<vespalib::SyncableThreadExecutor>>> executor);
public:
    enum class Optimize {LATENCY, THROUGHPUT};
    using ISequencedTaskExecutor::getExecutorId;

    ~SequencedTaskExecutor();

    void setTaskLimit(uint32_t taskLimit) override;
    void executeTask(ExecutorId id, vespalib::Executor::Task::UP task) override;
    void sync() override;
    Stats getStats() override;

    /*
     * Note that if you choose Optimize::THROUGHPUT, you must ensure only a single producer, or synchronize on the outside.
     */
    static std::unique_ptr<ISequencedTaskExecutor>
    create(uint32_t threads, uint32_t taskLimit = 1000, Optimize optimize = Optimize::LATENCY);
};

} // namespace search
{'fraction_non_alphanumeric': 0.09313725490196079, 'fraction_numerical': 0.012066365007541479, 'mean_word_length': 5.1841491841491845, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '255438', 'n_tokens_mistral': 815, 'n_tokens_neox': 763, 'n_words': 223}