<commit_before>/*************************************************************************
> File Name: SyncBuffer.h
> Project Name: Hearthstonepp
> Author: <NAME>
> Purpose: Synchronized Buffer
> Created Time: 2018/05/20
> Copyright (c) 2018, <NAME>
*************************************************************************/
#ifndef HEARTHSTONEPP_SYNCBUFFER_H
#define HEARTHSTONEPP_SYNCBUFFER_H

#include <condition_variable>
#include <mutex>

namespace Hearthstonepp
{
// BufferType must be copy-assignable and movable
template <typename BufferType>
class SyncBuffer
{
 public:
    SyncBuffer() : m_readable(false)
    {
        // Do Nothing
    }

    // Not copy-assignable
    SyncBuffer(SyncBuffer&&) = delete;

    SyncBuffer(const SyncBuffer&) = delete;

    SyncBuffer& operator=(SyncBuffer&&) = delete;

    SyncBuffer& operator=(const SyncBuffer&) = delete;

    void WriteBuffer(BufferType&& buffer)
    {
        std::unique_lock lock(m_mtx);
        m_cond.wait(lock, [=]() { return !m_readable; });

        m_buffer = std::move(buffer);

        m_readable = true;
        m_cond.notify_one();
    }

    void WriteBuffer(const BufferType& buffer)
    {
        std::unique_lock lock(m_mtx);
        m_cond.wait(lock, [=]() { return !m_readable; });

        m_buffer = buffer;

        m_readable = true;
        m_cond.notify_one();
    }

    void ReadBuffer(BufferType& buffer)
    {
        std::unique_lock lock(m_mtx);<commit_msg>[ci skip] Update SyncBuffer - Fix type conversion warning<commit_after>/*************************************************************************
> File Name: SyncBuffer.h
> Project Name: Hearthstonepp
> Author: <NAME>
> Purpose: Synchronized Buffer
> Created Time: 2018/05/20
> Copyright (c) 2018, <NAME>
*************************************************************************/
#ifndef HEARTHSTONEPP_SYNCBUFFER_H
#define HEARTHSTONEPP_SYNCBUFFER_H

#include <condition_variable>
#include <mutex>

namespace Hearthstonepp
{
// BufferType must be copy-assignable and movable
template <typename BufferType>
class SyncBuffer
{
 public:
    SyncBuffer() : m_readable(false)
    {
        // Do Nothing
    }

    // Not copy-assignable
    SyncBuffer(SyncBuffer&&) = delete;

    SyncBuffer(const SyncBuffer&) = delete;

    SyncBuffer& operator=(SyncBuffer&&) = delete;

    SyncBuffer& operator=(const SyncBuffer&) = delete;

    void WriteBuffer(BufferType&& buffer)
    {
        std::unique_lock<std::mutex> lock(m_mtx);
        m_cond.wait(lock, [=]() { return !m_readable; });

        m_buffer = std::move(buffer);

        m_readable = true;
        m_cond.notify_one();
    }

    void WriteBuffer(const BufferType& buffer)
    {
        std::unique_lock<std::mutex> lock(m_mtx);
        m_cond.wait(lock, [=]() { return !m_readable; });

        m_buffer = buffer;

        m_readable = true;
        m_cond.notify_one();
    }

    void ReadBuffer(BufferType& buffer)
    {
        std::unique_lock<std::mutex> lock(m_mtx);
{'fraction_non_alphanumeric': 0.2086403215003349, 'fraction_numerical': 0.008037508372404554, 'mean_word_length': 3.6671875, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 28, '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': '2986393', 'n_tokens_mistral': 968, 'n_tokens_neox': 884, 'n_words': 188}