os: refactor/rewrite entire namespace.

This commit is contained in:
Michael Scire 2020-04-08 02:21:35 -07:00
parent 6193283f03
commit 065485b971
181 changed files with 5353 additions and 1929 deletions

View file

@ -33,12 +33,6 @@ namespace ams::lmem::impl {
new (&out->list_node) util::IntrusiveListNode;
new (&out->child_list) decltype(out->child_list);
/* Only initialize mutex if option requires it. */
if (option & CreateOption_ThreadSafe) {
static_assert(std::is_trivially_destructible<os::Mutex>::value);
new (&out->mutex) os::Mutex;
}
/* Set fields. */
out->magic = magic;
out->heap_start = start;

View file

@ -30,13 +30,13 @@ namespace ams::lmem::impl {
public:
explicit ScopedHeapLock(HeapHandle h) : handle(h) {
if (this->handle->option & CreateOption_ThreadSafe) {
this->handle->mutex.Lock();
os::LockMutex(std::addressof(this->handle->mutex));
}
}
~ScopedHeapLock() {
if (this->handle->option & CreateOption_ThreadSafe) {
this->handle->mutex.Unlock();
os::UnlockMutex(std::addressof(this->handle->mutex));
}
}
};

View file

@ -19,10 +19,17 @@
namespace ams::lmem {
HeapHandle CreateExpHeap(void *address, size_t size, u32 option) {
return impl::CreateExpHeap(address, size, option);
HeapHandle handle = impl::CreateExpHeap(address, size, option);
if (option & CreateOption_ThreadSafe) {
os::InitializeMutex(std::addressof(handle->mutex), false, 0);
}
return handle;
}
void DestroyExpHeap(HeapHandle handle) {
if (handle->option & CreateOption_ThreadSafe) {
os::FinalizeMutex(std::addressof(handle->mutex));
}
impl::DestroyExpHeap(handle);
}

View file

@ -19,18 +19,33 @@
namespace ams::lmem {
HeapHandle CreateUnitHeap(void *address, size_t size, size_t unit_size, u32 option) {
return impl::CreateUnitHeap(address, size, unit_size, DefaultAlignment, static_cast<u16>(option), InfoPlacement_Head, nullptr);
HeapHandle handle = impl::CreateUnitHeap(address, size, unit_size, DefaultAlignment, static_cast<u16>(option), InfoPlacement_Head, nullptr);
if (option & CreateOption_ThreadSafe) {
os::InitializeMutex(std::addressof(handle->mutex), false, 0);
}
return handle;
}
HeapHandle CreateUnitHeap(void *address, size_t size, size_t unit_size, u32 option, s32 alignment, InfoPlacement info_placement) {
return impl::CreateUnitHeap(address, size, unit_size, alignment, static_cast<u16>(option), info_placement, nullptr);
HeapHandle handle = impl::CreateUnitHeap(address, size, unit_size, alignment, static_cast<u16>(option), info_placement, nullptr);
if (option & CreateOption_ThreadSafe) {
os::InitializeMutex(std::addressof(handle->mutex), false, 0);
}
return handle;
}
HeapHandle CreateUnitHeap(void *address, size_t size, size_t unit_size, u32 option, s32 alignment, HeapCommonHead *heap_head) {
return impl::CreateUnitHeap(address, size, unit_size, alignment, static_cast<u16>(option), InfoPlacement_Head, heap_head);
HeapHandle handle = impl::CreateUnitHeap(address, size, unit_size, alignment, static_cast<u16>(option), InfoPlacement_Head, heap_head);
if (option & CreateOption_ThreadSafe) {
os::InitializeMutex(std::addressof(handle->mutex), false, 0);
}
return handle;
}
void DestroyUnitHeap(HeapHandle handle) {
if (handle->option & CreateOption_ThreadSafe) {
os::FinalizeMutex(std::addressof(handle->mutex));
}
impl::DestroyUnitHeap(handle);
}