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