<commit_before>#include "mutex.hpp"
#include "connection.hpp"
#include "condition_variable.hpp"
#include "../common/assert.hpp"

#include "rsg.pb.h"

rsg::ConditionVariable::ConditionVariable(uint64_t remote_address) :
    _remote_address(remote_address) {
}

rsg::ConditionVariablePtr rsg::ConditionVariable::create()
{
    rsg::pb::Decision decision;
    decision.set_conditionvariablecreate(true);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    if (!ack.success())
        return nullptr;
    return rsg::ConditionVariablePtr(new rsg::ConditionVariable(ack.conditionvariablecreate().address()));
}

rsg::ConditionVariable::~ConditionVariable()
{
    rsg::pb::Decision decision;
    auto comm = new rsg::pb::ConditionVariable();
    comm->set_address(_remote_address);
}

void rsg::ConditionVariable::wait(rsg::MutexPtr lock)
{
    rsg::pb::Decision decision;
    auto comm = new rsg::pb::ConditionVariable();
    auto mutex = new rsg::pb::Mutex();
    comm->set_address(_remote_address);
    mutex->set_address(lock->_remote_address);
    auto cv_wait  = new rsg::pb::Decision_ConditionVariableWait();
    cv_wait->set_allocated_mutex(mutex);
    cv_wait->set_allocated_conditionvariable(comm);
    decision.set_allocated_conditionvariablewait(cv_wait);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not wait on ConditionVariable");
}

std::cv_status rsg::ConditionVariable::wait_until(rsg::MutexPtr lock, double timeout_time)
{
    rsg::pb::Decision decision;
    auto comm = new rsg::pb::ConditionVariable();
    auto mutex = new rsg::pb::Mutex();
    comm->set_address(_remote_address);
    mutex->set_address(lock->_remote_address);
    auto cv_waituntil  = new rsg::pb::Decision_ConditionVariableWaitUntil();
    cv_waituntil->set_allocated_mutex(mutex);
    cv_waituntil->set_allocated_conditionvariable(comm);
    cv_waituntil->set_timeout_time(timeout_time);
    decision.set_allocated_conditionvariablewaituntil(cv_waituntil);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not wait_until on ConditionVariable");

    return 0 == ack.conditionvariablewaituntil() ? std::cv_status::no_timeout : std::cv_status::timeout;
}

std::cv_status rsg::ConditionVariable::wait_for(rsg::MutexPtr lock, double duration)
{
    rsg::pb::Decision decision;
    auto comm = new rsg::pb::ConditionVariable();
    auto mutex = new rsg::pb::Mutex();
    comm->set_address(_remote_address);
    mutex->set_address(lock->_remote_address);
    auto cv_waitfor  = new rsg::pb::Decision_ConditionVariableWaitFor();
    cv_waitfor->set_allocated_mutex(mutex);
    cv_waitfor->set_allocated_conditionvariable(comm);
    cv_waitfor->set_duration(duration);
    decision.set_allocated_conditionvariablewaitfor(cv_waitfor);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not wait_for on ConditionVariable");

    return 0 == ack.conditionvariablewaituntil() ? std::cv_status::no_timeout : std::cv_status::timeout;
}

void rsg::ConditionVariable::notify_one()
{
    rsg::pb::Decision decision;
    auto comm = new rsg::pb::ConditionVariable();
    comm->set_address(_remote_address);
    decision.set_allocated_conditionvariablenotifyone(comm);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not notify_one on ConditionVariable");
}

void rsg::ConditionVariable::notify_all()
{
    rsg::pb::Decision decision;
    auto comm = new rsg::pb::ConditionVariable();
    comm->set_address(_remote_address);
    decision.set_allocated_conditionvariablenotifyall(comm);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not notify_one on ConditionVariable");
}<commit_msg>librsg: refactor copypasta error in condvars<commit_after>#include "mutex.hpp"
#include "connection.hpp"
#include "condition_variable.hpp"
#include "../common/assert.hpp"

#include "rsg.pb.h"

rsg::ConditionVariable::ConditionVariable(uint64_t remote_address) :
    _remote_address(remote_address) {
}

rsg::ConditionVariablePtr rsg::ConditionVariable::create()
{
    rsg::pb::Decision decision;
    decision.set_conditionvariablecreate(true);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    if (!ack.success())
        return nullptr;
    return rsg::ConditionVariablePtr(new rsg::ConditionVariable(ack.conditionvariablecreate().address()));
}

rsg::ConditionVariable::~ConditionVariable()
{
    rsg::pb::Decision decision;
    auto cond_var = new rsg::pb::ConditionVariable();
    cond_var->set_address(_remote_address);
}

void rsg::ConditionVariable::wait(rsg::MutexPtr lock)
{
    rsg::pb::Decision decision;
    auto cond_var = new rsg::pb::ConditionVariable();
    auto mutex = new rsg::pb::Mutex();
    cond_var->set_address(_remote_address);
    mutex->set_address(lock->_remote_address);
    auto cv_wait  = new rsg::pb::Decision_ConditionVariableWait();
    cv_wait->set_allocated_mutex(mutex);
    cv_wait->set_allocated_conditionvariable(cond_var);
    decision.set_allocated_conditionvariablewait(cv_wait);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not wait on ConditionVariable");
}

std::cv_status rsg::ConditionVariable::wait_until(rsg::MutexPtr lock, double timeout_time)
{
    rsg::pb::Decision decision;
    auto cond_var = new rsg::pb::ConditionVariable();
    auto mutex = new rsg::pb::Mutex();
    cond_var->set_address(_remote_address);
    mutex->set_address(lock->_remote_address);
    auto cv_waituntil  = new rsg::pb::Decision_ConditionVariableWaitUntil();
    cv_waituntil->set_allocated_mutex(mutex);
    cv_waituntil->set_allocated_conditionvariable(cond_var);
    cv_waituntil->set_timeout_time(timeout_time);
    decision.set_allocated_conditionvariablewaituntil(cv_waituntil);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not wait_until on ConditionVariable");

    return 0 == ack.conditionvariablewaituntil() ? std::cv_status::no_timeout : std::cv_status::timeout;
}

std::cv_status rsg::ConditionVariable::wait_for(rsg::MutexPtr lock, double duration)
{
    rsg::pb::Decision decision;
    auto cond_var = new rsg::pb::ConditionVariable();
    auto mutex = new rsg::pb::Mutex();
    cond_var->set_address(_remote_address);
    mutex->set_address(lock->_remote_address);
    auto cv_waitfor  = new rsg::pb::Decision_ConditionVariableWaitFor();
    cv_waitfor->set_allocated_mutex(mutex);
    cv_waitfor->set_allocated_conditionvariable(cond_var);
    cv_waitfor->set_duration(duration);
    decision.set_allocated_conditionvariablewaitfor(cv_waitfor);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not wait_for on ConditionVariable");

    return 0 == ack.conditionvariablewaituntil() ? std::cv_status::no_timeout : std::cv_status::timeout;
}

void rsg::ConditionVariable::notify_one()
{
    rsg::pb::Decision decision;
    auto cond_var = new rsg::pb::ConditionVariable();
    cond_var->set_address(_remote_address);
    decision.set_allocated_conditionvariablenotifyone(cond_var);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not notify_one on ConditionVariable");
}

void rsg::ConditionVariable::notify_all()
{
    rsg::pb::Decision decision;
    auto cond_var = new rsg::pb::ConditionVariable();
    cond_var->set_address(_remote_address);
    decision.set_allocated_conditionvariablenotifyall(cond_var);

    rsg::pb::DecisionAck ack;
    rsg::connection->send_decision(decision, ack);
    RSG_ENFORCE(ack.success(), "Could not notify_one on ConditionVariable");
}
{'fraction_non_alphanumeric': 0.13352521586785132, 'fraction_numerical': 0.0010011262670504317, 'mean_word_length': 6.110320284697509, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, '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': '5272706', 'n_tokens_mistral': 2609, 'n_tokens_neox': 2569, 'n_words': 383}