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