<commit_before>// Copyright 2018 plutoo
#include "types.h"
#include "result.h"
#include "kernel/svc.h"
#include "kernel/cond_var.h"
#include "../internal.h"

void condvarInit(CondVar* c, Mutex* m) {
    c->tag = 0;
    c->mutex = m;
}

void condvarWaitTimeout(CondVar* c, u64 timeout) {
    Result rc;

    rc = svcWaitProcessWideKeyAtomic(&c->tag, (u32*) c->mutex, getThreadVars()->handle, timeout);

    // On timeout, we need to acquire it manually.
    if (rc == 0xEA01)
        mutexLock(c->mutex);
}

void condvarWait(CondVar* c) {
    return condvarWaitTimeout(c, -1);
}

Result condvarWake(CondVar* c, int num) {
    return svcSignalProcessWideKey((u32*) &c->tag, num);
}

Result condvarWakeOne(CondVar* c) {
    return condvarWake(c, 1);
}

Result condvarWakeAll(CondVar* c) {
    return condvarWake(c, -1);
}<commit_msg>Condvar bugfix<commit_after>// Copyright 2018 plutoo
#include "types.h"
#include "result.h"
#include "kernel/svc.h"
#include "kernel/cond_var.h"
#include "../internal.h"

void condvarInit(CondVar* c, Mutex* m) {
    c->tag = 0;
    c->mutex = m;
}

void condvarWaitTimeout(CondVar* c, u64 timeout) {
    Result rc;

    rc = svcWaitProcessWideKeyAtomic(&c->tag, (u32*) c->mutex, getThreadVars()->handle, timeout);

    // On timeout, we need to acquire it manually.
    if (rc == 0xEA01)
        mutexLock(c->mutex);
}

void condvarWait(CondVar* c) {
    return condvarWaitTimeout(c, -1ull);
}

Result condvarWake(CondVar* c, int num) {
    return svcSignalProcessWideKey((u32*) &c->tag, num);
}

Result condvarWakeOne(CondVar* c) {
    return condvarWake(c, 1);
}

Result condvarWakeAll(CondVar* c) {
    return condvarWake(c, -1);
}
{'fraction_non_alphanumeric': 0.15504807692307693, 'fraction_numerical': 0.020432692307692308, 'mean_word_length': 3.8401162790697674, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6689958', 'n_tokens_mistral': 665, 'n_tokens_neox': 635, 'n_words': 151}