<commit_before>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/net/socket_spec.h>
#include <vespa/vespalib/util/benchmark_timer.h>
#include <vespa/fnet/frt/frt.h>
#include <mutex>
#include <condition_variable>

using vespalib::SocketSpec;
using vespalib::BenchmarkTimer;

constexpr double timeout = 60.0;
constexpr double short_timeout = 0.1;

//-------------------------------------------------------------

#include "my_crypto_engine.hpp"
vespalib::CryptoEngine::SP crypto;

//-------------------------------------------------------------

class RequestLatch : public FRT_IRequestWait {
private:
    FRT_RPCRequest *_req;
    std::mutex _lock;
    std::condition_variable _cond;
public:
    RequestLatch() : _req(nullptr), _lock(), _cond() {}
    ~RequestLatch() { ASSERT_TRUE(_req == nullptr); }
    bool has_req() {
        std::lock_guard guard(_lock);
        return (_req != nullptr);
    }
    FRT_RPCRequest *read() {
        std::unique_lock guard(_lock);
        _cond.wait(guard, [&req = _req]{ return (req != nullptr); });
        auto ret = _req;
        _req = nullptr;
        _cond.notify_all();
        return ret;
    }
    void write(FRT_RPCRequest *req) {
        std::unique_lock guard(_lock);
        _cond.wait(guard, [&req = _req]{ return (req == nullptr); });
        _req = req;
        _cond.notify_all();
    }
    void RequestDone(FRT_RPCRequest *req) override { write(req); }
};

//-------------------------------------------------------------

class MyReq {
private:
    FRT_RPCRequest *_req;
public:<commit_msg>use generic latch<commit_after>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/net/socket_spec.h>
#include <vespa/vespalib/util/benchmark_timer.h>
#include <vespa/vespalib/util/latch.h>
#include <vespa/fnet/frt/frt.h>
#include <mutex>
#include <condition_variable>

using vespalib::SocketSpec;
using vespalib::BenchmarkTimer;

constexpr double timeout = 60.0;
constexpr double short_timeout = 0.1;

//-------------------------------------------------------------

#include "my_crypto_engine.hpp"
vespalib::CryptoEngine::SP crypto;

//-------------------------------------------------------------

class RequestLatch : public FRT_IRequestWait {
private:
    vespalib::Latch<FRT_RPCRequest*> _latch;
public:
    RequestLatch() : _latch() {}
    ~RequestLatch() { ASSERT_TRUE(!has_req()); }
    bool has_req() { return _latch.has_value(); }
    FRT_RPCRequest *read() { return _latch.read(); }
    void write(FRT_RPCRequest *req) { _latch.write(req); }
    void RequestDone(FRT_RPCRequest *req) override { write(req); }
};

//-------------------------------------------------------------

class MyReq {
private:
    FRT_RPCRequest *_req;
public:
{'fraction_non_alphanumeric': 0.2402291105121294, 'fraction_numerical': 0.007412398921832884, 'mean_word_length': 2.3322109988776654, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5504702', 'n_tokens_mistral': 938, 'n_tokens_neox': 929, 'n_words': 203}