2014-05-27 17:16:13 -07:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-16 21:38:14 -08:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-11-19 00:49:13 -08:00
|
|
|
// Refer to the license.txt file included.
|
2014-05-27 17:16:13 -07:00
|
|
|
|
2014-06-05 19:35:36 -07:00
|
|
|
#include <algorithm>
|
2015-05-06 00:06:12 -07:00
|
|
|
#include "common/assert.h"
|
2016-09-20 23:52:38 -07:00
|
|
|
#include "core/hle/kernel/event.h"
|
2018-08-01 19:40:00 -07:00
|
|
|
#include "core/hle/kernel/object.h"
|
2014-06-05 19:35:36 -07:00
|
|
|
#include "core/hle/kernel/thread.h"
|
2014-05-27 17:16:13 -07:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2016-09-18 18:01:46 -07:00
|
|
|
Event::Event() {}
|
|
|
|
Event::~Event() {}
|
2015-01-31 16:56:59 -08:00
|
|
|
|
2015-01-31 18:14:40 -08:00
|
|
|
SharedPtr<Event> Event::Create(ResetType reset_type, std::string name) {
|
2015-01-22 21:11:25 -08:00
|
|
|
SharedPtr<Event> evt(new Event);
|
2014-06-09 19:46:54 -07:00
|
|
|
|
2015-01-15 16:29:46 -08:00
|
|
|
evt->signaled = false;
|
2015-07-01 15:10:28 -07:00
|
|
|
evt->reset_type = reset_type;
|
2015-01-22 21:11:25 -08:00
|
|
|
evt->name = std::move(name);
|
2015-01-14 20:33:37 -08:00
|
|
|
|
2015-01-31 18:14:40 -08:00
|
|
|
return evt;
|
2014-05-27 17:16:13 -07:00
|
|
|
}
|
|
|
|
|
2017-01-01 13:53:22 -08:00
|
|
|
bool Event::ShouldWait(Thread* thread) const {
|
2015-01-22 21:11:25 -08:00
|
|
|
return !signaled;
|
|
|
|
}
|
2014-05-27 17:16:13 -07:00
|
|
|
|
2017-01-01 13:53:22 -08:00
|
|
|
void Event::Acquire(Thread* thread) {
|
|
|
|
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
|
2014-05-27 17:16:13 -07:00
|
|
|
|
2017-01-01 16:23:19 -08:00
|
|
|
if (reset_type == ResetType::OneShot)
|
2015-01-22 21:11:25 -08:00
|
|
|
signaled = false;
|
|
|
|
}
|
2014-05-27 17:16:13 -07:00
|
|
|
|
2015-01-22 21:11:25 -08:00
|
|
|
void Event::Signal() {
|
|
|
|
signaled = true;
|
|
|
|
WakeupAllWaitingThreads();
|
2014-05-27 17:16:13 -07:00
|
|
|
}
|
|
|
|
|
2015-01-22 21:11:25 -08:00
|
|
|
void Event::Clear() {
|
|
|
|
signaled = false;
|
2014-05-27 17:16:13 -07:00
|
|
|
}
|
|
|
|
|
2017-01-01 16:23:19 -08:00
|
|
|
void Event::WakeupAllWaitingThreads() {
|
|
|
|
WaitObject::WakeupAllWaitingThreads();
|
|
|
|
|
|
|
|
if (reset_type == ResetType::Pulse)
|
|
|
|
signaled = false;
|
|
|
|
}
|
|
|
|
|
2018-01-19 23:48:02 -08:00
|
|
|
} // namespace Kernel
|