mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-23 13:04:50 +00:00
haze: event_reactor, ptp_data_parser, async_usb_server, ptp_object_database, ptp_object_heap: style
This commit is contained in:
parent
95a5decd57
commit
9700475d87
7 changed files with 31 additions and 30 deletions
|
@ -43,10 +43,10 @@ namespace haze {
|
|||
template <typename... Args>
|
||||
Result WaitFor(s32 *out_arg_waiter, Args &&... arg_waiters) {
|
||||
const Waiter arg_waiter_array[] = { arg_waiters... };
|
||||
return this->WaitForImpl(out_arg_waiter, sizeof...(Args), arg_waiter_array);
|
||||
return this->WaitForImpl(out_arg_waiter, arg_waiter_array, sizeof...(Args));
|
||||
}
|
||||
private:
|
||||
Result WaitForImpl(s32 *out_arg_waiter, s32 num_arg_waiters, const Waiter *arg_waiters);
|
||||
Result WaitForImpl(s32 *out_arg_waiter, const Waiter *arg_waiters, s32 num_arg_waiters);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace haze {
|
|||
}
|
||||
|
||||
/* Write null terminator. */
|
||||
*out_string++ = 0;
|
||||
*out_string++ = '\x00';
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ namespace haze {
|
|||
R_THROW(haze::ResultNotConfigured());
|
||||
}
|
||||
|
||||
/* Select the appropriate endpoint and begin a transfer. */
|
||||
UsbSessionEndpoint ep = read ? UsbSessionEndpoint_Read : UsbSessionEndpoint_Write;
|
||||
R_TRY(s_usb_session.TransferAsync(ep, page, size, std::addressof(urb_id)));
|
||||
|
||||
|
|
|
@ -29,10 +29,10 @@ namespace haze {
|
|||
}
|
||||
|
||||
void EventReactor::RemoveConsumer(EventConsumer *consumer) {
|
||||
s32 input_index = 0, output_index = 0;
|
||||
s32 output_index = 0;
|
||||
|
||||
/* Remove the consumer. */
|
||||
for (; input_index < m_num_wait_objects; input_index++) {
|
||||
for (s32 input_index = 0; input_index < m_num_wait_objects; input_index++) {
|
||||
if (m_consumers[input_index] == consumer) {
|
||||
continue;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace haze {
|
|||
m_num_wait_objects = output_index;
|
||||
}
|
||||
|
||||
Result EventReactor::WaitForImpl(s32 *out_arg_waiter, s32 num_arg_waiters, const Waiter *arg_waiters) {
|
||||
Result EventReactor::WaitForImpl(s32 *out_arg_waiter, const Waiter *arg_waiters, s32 num_arg_waiters) {
|
||||
HAZE_ASSERT(m_num_wait_objects + num_arg_waiters <= MAX_WAIT_OBJECTS);
|
||||
|
||||
while (true) {
|
||||
|
@ -62,7 +62,7 @@ namespace haze {
|
|||
s32 idx;
|
||||
HAZE_R_ABORT_UNLESS(waitObjects(std::addressof(idx), m_waiters, m_num_wait_objects + num_arg_waiters, -1));
|
||||
|
||||
/* If this refers to a waiter in the argument list, return it. */
|
||||
/* If a waiter in the argument list was signaled, return it. */
|
||||
if (idx >= m_num_wait_objects) {
|
||||
*out_arg_waiter = idx - m_num_wait_objects;
|
||||
R_SUCCEED();
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include <haze.hpp>
|
||||
#include <haze/console_main_loop.hpp>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char **argv) {
|
||||
haze::PtpObjectHeap ptp_object_heap;
|
||||
|
||||
haze::EventReactor event_reactor;
|
||||
|
|
|
@ -38,36 +38,36 @@ namespace haze {
|
|||
}
|
||||
|
||||
Result PtpObjectDatabase::AddObjectId(const char *parent_name, const char *name, u32 *out_object_id, u32 parent_id, u32 desired_object_id) {
|
||||
ObjectNode *node = nullptr;
|
||||
|
||||
/* Calculate length of the name. */
|
||||
const size_t parent_name_len = std::strlen(parent_name);
|
||||
const size_t name_len = std::strlen(name) + 1;
|
||||
const size_t alloc_len = parent_name_len + 1 + name_len;
|
||||
|
||||
/* Allocate memory for the node. */
|
||||
node = reinterpret_cast<ObjectNode *>(m_object_heap->Allocate(sizeof(ObjectNode) + alloc_len));
|
||||
ObjectNode *const node = reinterpret_cast<ObjectNode *>(m_object_heap->Allocate(sizeof(ObjectNode) + alloc_len));
|
||||
R_UNLESS(node != nullptr, haze::ResultOutOfMemory());
|
||||
|
||||
/* Ensure we maintain a clean state on failure. */
|
||||
auto guard = SCOPE_GUARD { m_object_heap->Deallocate(node, sizeof(ObjectNode) + alloc_len); };
|
||||
{
|
||||
/* Ensure we maintain a clean state on failure. */
|
||||
auto guard = SCOPE_GUARD { m_object_heap->Deallocate(node, sizeof(ObjectNode) + alloc_len); };
|
||||
|
||||
/* Take ownership of the name. */
|
||||
std::strncpy(node->m_name, parent_name, parent_name_len + 1);
|
||||
node->m_name[parent_name_len] = '/';
|
||||
std::strncpy(node->m_name + parent_name_len + 1, name, name_len);
|
||||
/* Take ownership of the name. */
|
||||
std::strncpy(node->m_name, parent_name, parent_name_len + 1);
|
||||
node->m_name[parent_name_len] = '/';
|
||||
std::strncpy(node->m_name + parent_name_len + 1, name, name_len);
|
||||
|
||||
/* Check if an object with this name already exists. If it does, we can just return it here. */
|
||||
auto it = m_name_to_object_id.find_key(node->m_name);
|
||||
if (it != m_name_to_object_id.end()) {
|
||||
if (out_object_id) {
|
||||
*out_object_id = it->GetObjectId();
|
||||
/* Check if an object with this name already exists. If it does, we can just return it here. */
|
||||
auto it = m_name_to_object_id.find_key(node->m_name);
|
||||
if (it != m_name_to_object_id.end()) {
|
||||
if (out_object_id) {
|
||||
*out_object_id = it->GetObjectId();
|
||||
}
|
||||
R_SUCCEED();
|
||||
}
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
/* Persist the reference to the node. */
|
||||
guard.Cancel();
|
||||
/* Persist the reference to the node. */
|
||||
guard.Cancel();
|
||||
}
|
||||
|
||||
/* Insert node into trees. */
|
||||
node->m_parent_id = parent_id;
|
||||
|
|
|
@ -20,22 +20,22 @@ namespace haze {
|
|||
namespace {
|
||||
|
||||
/* Allow 20MiB for use by libnx. */
|
||||
static constexpr size_t LibnxReservedMem = 20_MB;
|
||||
static constexpr size_t LibnxReservedMemorySize = 20_MB;
|
||||
|
||||
}
|
||||
|
||||
void PtpObjectHeap::Initialize() {
|
||||
size_t mem_used = 0;
|
||||
|
||||
/* Skip re-initialization if we are currently initialized. */
|
||||
/* If we're already initialized, skip re-initialization. */
|
||||
if (m_heap_block_size != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Estimate how much memory we can reserve. */
|
||||
HAZE_R_ABORT_UNLESS(svcGetInfo(std::addressof(mem_used), InfoType_UsedMemorySize, CUR_PROCESS_HANDLE, 0));
|
||||
HAZE_ASSERT(mem_used > LibnxReservedMem);
|
||||
mem_used -= LibnxReservedMem;
|
||||
HAZE_ASSERT(mem_used > LibnxReservedMemorySize);
|
||||
mem_used -= LibnxReservedMemorySize;
|
||||
|
||||
/* Take the rest for ourselves. */
|
||||
m_heap_block_size = mem_used / NumHeapBlocks;
|
||||
|
|
Loading…
Add table
Reference in a new issue