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
|
|
|
|
|
|
|
#include <map>
|
2014-06-05 19:35:36 -07:00
|
|
|
#include <algorithm>
|
2014-05-27 17:16:13 -07:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/common.h"
|
|
|
|
|
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
#include "core/hle/kernel/event.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 {
|
|
|
|
|
2015-01-31 16:56:59 -08:00
|
|
|
Event::Event() {}
|
|
|
|
Event::~Event() {}
|
|
|
|
|
2015-01-22 21:11:25 -08:00
|
|
|
ResultVal<SharedPtr<Event>> Event::Create(ResetType reset_type, std::string name) {
|
|
|
|
SharedPtr<Event> evt(new Event);
|
|
|
|
// TOOD(yuriks): Don't create Handle (see Thread::Create())
|
|
|
|
CASCADE_RESULT(auto unused, Kernel::g_handle_table.Create(evt));
|
2014-06-09 19:46:54 -07:00
|
|
|
|
2015-01-15 16:29:46 -08:00
|
|
|
evt->signaled = false;
|
2015-01-22 21:11:25 -08:00
|
|
|
evt->reset_type = evt->intitial_reset_type = reset_type;
|
|
|
|
evt->name = std::move(name);
|
2015-01-14 20:33:37 -08:00
|
|
|
|
2015-01-22 21:11:25 -08:00
|
|
|
return MakeResult<SharedPtr<Event>>(evt);
|
2014-05-27 17:16:13 -07:00
|
|
|
}
|
|
|
|
|
2015-01-22 21:11:25 -08:00
|
|
|
bool Event::ShouldWait() {
|
|
|
|
return !signaled;
|
|
|
|
}
|
2014-05-27 17:16:13 -07:00
|
|
|
|
2015-01-22 21:11:25 -08:00
|
|
|
void Event::Acquire() {
|
|
|
|
_assert_msg_(Kernel, !ShouldWait(), "object unavailable!");
|
2014-05-27 17:16:13 -07:00
|
|
|
|
2015-01-22 21:11:25 -08:00
|
|
|
// Release the event if it's not sticky...
|
|
|
|
if (reset_type != RESETTYPE_STICKY)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|