os: implement waitable management.

This implements waitable management for Events (and
implements Events). It also refactors PM to use new
Event/Waitable semantics, and also adds STS_ASSERT
as a macro for asserting a boolean expression. The
rest of stratosphere has been refactored to use
STS_ASSERT whenever possible.
This commit is contained in:
Michael Scire
2019-09-27 18:04:58 -07:00
committed by SciresM
parent e07011be32
commit 609a302e16
108 changed files with 2752 additions and 1223 deletions

View File

@@ -14,14 +14,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "impl/os_waitable_object_list.hpp"
namespace sts::os {
MessageQueue::MessageQueue(std::unique_ptr<uintptr_t[]> buf, size_t c): buffer(std::move(buf)), capacity(c) {
new (GetPointer(this->waitable_object_list_storage)) impl::WaitableObjectList();
}
MessageQueue::~MessageQueue() {
GetReference(this->waitable_object_list_storage).~WaitableObjectList();
}
void MessageQueue::SendInternal(uintptr_t data) {
/* Ensure we don't corrupt the queue, but this should never happen. */
if (this->count >= this->capacity) {
std::abort();
}
STS_ASSERT(this->count < this->capacity);
/* Write data to tail of queue. */
this->buffer[(this->count++ + this->offset) % this->capacity] = data;
@@ -29,9 +36,7 @@ namespace sts::os {
void MessageQueue::SendNextInternal(uintptr_t data) {
/* Ensure we don't corrupt the queue, but this should never happen. */
if (this->count >= this->capacity) {
std::abort();
}
STS_ASSERT(this->count < this->capacity);
/* Write data to head of queue. */
this->offset = (this->offset + this->capacity - 1) % this->capacity;
@@ -41,9 +46,7 @@ namespace sts::os {
uintptr_t MessageQueue::ReceiveInternal() {
/* Ensure we don't corrupt the queue, but this should never happen. */
if (this->count == 0) {
std::abort();
}
STS_ASSERT(this->count > 0);
uintptr_t data = this->buffer[this->offset];
this->offset = (this->offset + 1) % this->capacity;
@@ -53,9 +56,7 @@ namespace sts::os {
uintptr_t MessageQueue::PeekInternal() {
/* Ensure we don't corrupt the queue, but this should never happen. */
if (this->count == 0) {
std::abort();
}
STS_ASSERT(this->count > 0);
return this->buffer[this->offset];
}