2018-11-26 23:31:22 +00: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-04 23:54:18 +00:00
|
|
|
#include "core/hle/kernel/errors.h"
|
2018-11-26 23:31:22 +00: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;
|
|
|
|
|
|
|
|
bool ReadableEvent::ShouldWait(Thread* thread) const {
|
2018-11-27 14:18:29 +00:00
|
|
|
return !signaled;
|
2018-11-26 23:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReadableEvent::Acquire(Thread* thread) {
|
|
|
|
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
|
|
|
|
|
2018-11-27 14:18:29 +00:00
|
|
|
if (reset_type == ResetType::OneShot)
|
|
|
|
signaled = false;
|
2018-11-26 23:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReadableEvent::Signal() {
|
2018-11-27 14:18:29 +00:00
|
|
|
signaled = true;
|
|
|
|
WakeupAllWaitingThreads();
|
2018-11-26 23:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReadableEvent::Clear() {
|
2018-11-27 14:18:29 +00:00
|
|
|
signaled = false;
|
2018-11-26 23:31:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 23:54:18 +00:00
|
|
|
ResultCode ReadableEvent::Reset() {
|
|
|
|
if (!signaled) {
|
|
|
|
return ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Clear();
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-11-26 23:31:22 +00:00
|
|
|
void ReadableEvent::WakeupAllWaitingThreads() {
|
2018-11-27 14:18:29 +00:00
|
|
|
WaitObject::WakeupAllWaitingThreads();
|
|
|
|
|
|
|
|
if (reset_type == ResetType::Pulse)
|
|
|
|
signaled = false;
|
2018-11-26 23:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Kernel
|