2018-11-27 00:31:22 +01:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include "common/assert.h"
|
2018-12-05 00:54:18 +01:00
|
|
|
#include "core/hle/kernel/errors.h"
|
2018-11-27 00:31:22 +01:00
|
|
|
#include "core/hle/kernel/object.h"
|
|
|
|
#include "core/hle/kernel/readable_event.h"
|
|
|
|
#include "core/hle/kernel/thread.h"
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
ReadableEvent::ReadableEvent(KernelCore& kernel) : WaitObject{kernel} {}
|
|
|
|
ReadableEvent::~ReadableEvent() = default;
|
|
|
|
|
2019-04-02 00:19:42 +02:00
|
|
|
bool ReadableEvent::ShouldWait(const Thread* thread) const {
|
2018-11-27 15:18:29 +01:00
|
|
|
return !signaled;
|
2018-11-27 00:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReadableEvent::Acquire(Thread* thread) {
|
|
|
|
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
|
|
|
|
|
2018-11-27 15:18:29 +01:00
|
|
|
if (reset_type == ResetType::OneShot)
|
|
|
|
signaled = false;
|
2018-11-27 00:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReadableEvent::Signal() {
|
2018-11-27 15:18:29 +01:00
|
|
|
signaled = true;
|
|
|
|
WakeupAllWaitingThreads();
|
2018-11-27 00:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReadableEvent::Clear() {
|
2018-11-27 15:18:29 +01:00
|
|
|
signaled = false;
|
2018-11-27 00:31:22 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:54:18 +01:00
|
|
|
ResultCode ReadableEvent::Reset() {
|
|
|
|
if (!signaled) {
|
|
|
|
return ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Clear();
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-11-27 00:31:22 +01:00
|
|
|
} // namespace Kernel
|