os: implement LightMessageQueue

This commit is contained in:
Michael Scire 2021-09-29 12:55:52 -07:00
parent cf5f431058
commit b8a1ebd11a
5 changed files with 518 additions and 1 deletions

View file

@ -45,6 +45,6 @@
#include <stratosphere/os/os_thread.hpp>
#include <stratosphere/os/os_message_queue.hpp>
#include <stratosphere/os/os_light_event.hpp>
//#include <stratosphere/os/os_light_message_queue.hpp>
#include <stratosphere/os/os_light_message_queue.hpp>
//#include <stratosphere/os/os_light_semaphore.hpp>
#include <stratosphere/os/os_waitable.hpp>

View file

@ -0,0 +1,100 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere/os/os_light_message_queue_types.hpp>
#include <stratosphere/os/os_light_message_queue_api.hpp>
namespace ams::os {
class LightMessageQueue {
NON_COPYABLE(LightMessageQueue);
NON_MOVEABLE(LightMessageQueue);
private:
LightMessageQueueType m_mq;
public:
explicit LightMessageQueue(uintptr_t *buf, size_t count) {
InitializeLightMessageQueue(std::addressof(m_mq), buf, count);
}
~LightMessageQueue() { FinalizeLightMessageQueue(std::addressof(m_mq)); }
/* Sending (FIFO functionality) */
void Send(uintptr_t data) {
return SendLightMessageQueue(std::addressof(m_mq), data);
}
bool TrySend(uintptr_t data) {
return TrySendLightMessageQueue(std::addressof(m_mq), data);
}
bool TimedSend(uintptr_t data, TimeSpan timeout) {
return TimedSendLightMessageQueue(std::addressof(m_mq), data, timeout);
}
/* Jamming (LIFO functionality) */
void Jam(uintptr_t data) {
return JamLightMessageQueue(std::addressof(m_mq), data);
}
bool TryJam(uintptr_t data) {
return TryJamLightMessageQueue(std::addressof(m_mq), data);
}
bool TimedJam(uintptr_t data, TimeSpan timeout) {
return TimedJamLightMessageQueue(std::addressof(m_mq), data, timeout);
}
/* Receive functionality */
void Receive(uintptr_t *out) {
return ReceiveLightMessageQueue(out, std::addressof(m_mq));
}
bool TryReceive(uintptr_t *out) {
return TryReceiveLightMessageQueue(out, std::addressof(m_mq));
}
bool TimedReceive(uintptr_t *out, TimeSpan timeout) {
return TimedReceiveLightMessageQueue(out, std::addressof(m_mq), timeout);
}
/* Peek functionality */
void Peek(uintptr_t *out) const {
return PeekLightMessageQueue(out, std::addressof(m_mq));
}
bool TryPeek(uintptr_t *out) const {
return TryPeekLightMessageQueue(out, std::addressof(m_mq));
}
bool TimedPeek(uintptr_t *out, TimeSpan timeout) const {
return TimedPeekLightMessageQueue(out, std::addressof(m_mq), timeout);
}
operator LightMessageQueueType &() {
return m_mq;
}
operator const LightMessageQueueType &() const {
return m_mq;
}
LightMessageQueueType *GetBase() {
return std::addressof(m_mq);
}
};
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
namespace ams::os {
struct LightMessageQueueType;
void InitializeLightMessageQueue(LightMessageQueueType *mq, uintptr_t *buffer, size_t count);
void FinalizeLightMessageQueue(LightMessageQueueType *mq);
/* Sending (FIFO functionality) */
void SendLightMessageQueue(LightMessageQueueType *mq, uintptr_t data);
bool TrySendLightMessageQueue(LightMessageQueueType *mq, uintptr_t data);
bool TimedSendLightMessageQueue(LightMessageQueueType *mq, uintptr_t data, TimeSpan timeout);
/* Jamming (LIFO functionality) */
void JamLightMessageQueue(LightMessageQueueType *mq, uintptr_t data);
bool TryJamLightMessageQueue(LightMessageQueueType *mq, uintptr_t data);
bool TimedJamLightMessageQueue(LightMessageQueueType *mq, uintptr_t data, TimeSpan timeout);
/* Receive functionality */
void ReceiveLightMessageQueue(uintptr_t *out, LightMessageQueueType *mq);
bool TryReceiveLightMessageQueue(uintptr_t *out, LightMessageQueueType *mq);
bool TimedReceiveLightMessageQueue(uintptr_t *out, LightMessageQueueType *mq, TimeSpan timeout);
/* Peek functionality */
void PeekLightMessageQueue(uintptr_t *out, const LightMessageQueueType *mq);
bool TryPeekLightMessageQueue(uintptr_t *out, const LightMessageQueueType *mq);
bool TimedPeekLightMessageQueue(uintptr_t *out, const LightMessageQueueType *mq, TimeSpan timeout);
}

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
#include <stratosphere/os/impl/os_internal_busy_mutex.hpp>
#include <stratosphere/os/impl/os_internal_light_event.hpp>
namespace ams::os {
namespace impl {
using LightMessageQueueMutex = InternalBusyMutex;
using LightMessageQueueMutexStorage = InternalBusyMutexStorage;
}
struct LightMessageQueueType {
enum State {
State_NotInitialized = 0,
State_Initialized = 1,
};
uintptr_t *buffer;
s32 capacity;
s32 count;
s32 offset;
u8 state;
mutable impl::LightMessageQueueMutexStorage mutex_queue;
mutable impl::InternalLightEventStorage ev_not_full;
mutable impl::InternalLightEventStorage ev_not_empty;
};
static_assert(std::is_trivial<LightMessageQueueType>::value);
}