Skip to content

Commit

Permalink
Use semantic wrapping where appropriate for class initialiser lists
Browse files Browse the repository at this point in the history
  • Loading branch information
bylaws authored and PixelyIon committed Nov 10, 2021
1 parent 6b33268 commit ef10d3d
Show file tree
Hide file tree
Showing 27 changed files with 155 additions and 37 deletions.
5 changes: 4 additions & 1 deletion app/src/main/cpp/skyline/audio/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include "track.h"

namespace skyline::audio {
AudioTrack::AudioTrack(u8 channelCount, u32 sampleRate, std::function<void()> releaseCallback) : channelCount(channelCount), sampleRate(sampleRate), releaseCallback(std::move(releaseCallback)) {
AudioTrack::AudioTrack(u8 channelCount, u32 sampleRate, std::function<void()> releaseCallback)
: channelCount(channelCount),
sampleRate(sampleRate),
releaseCallback(std::move(releaseCallback)) {
if (sampleRate != constant::SampleRate)
throw exception("Unsupported audio sample rate: {}", sampleRate);

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/cpp/skyline/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "kernel/types/KProcess.h"

namespace skyline {
Logger::Logger(const std::string &path, LogLevel configLevel) : configLevel(configLevel), start(util::GetTimeNs() / constant::NsInMillisecond) {
Logger::Logger(const std::string &path, LogLevel configLevel)
: configLevel(configLevel),
start(util::GetTimeNs() / constant::NsInMillisecond) {
logFile.open(path, std::ios::trunc);
UpdateTag();
Write(LogLevel::Info, "Logging started");
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/cpp/skyline/gpu/command_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include "command_scheduler.h"

namespace skyline::gpu {
CommandScheduler::CommandBufferSlot::CommandBufferSlot(vk::raii::Device &device, vk::CommandBuffer commandBuffer, vk::raii::CommandPool &pool) : device(device), commandBuffer(device, commandBuffer, pool), fence(device, vk::FenceCreateInfo{}), cycle(std::make_shared<FenceCycle>(device, *fence)) {}
CommandScheduler::CommandBufferSlot::CommandBufferSlot(vk::raii::Device &device, vk::CommandBuffer commandBuffer, vk::raii::CommandPool &pool)
: device(device),
commandBuffer(device, commandBuffer, pool),
fence(device, vk::FenceCreateInfo{}),
cycle(std::make_shared<FenceCycle>(device, *fence)) {}

bool CommandScheduler::CommandBufferSlot::AllocateIfFree(CommandScheduler::CommandBufferSlot &slot) {
if (!slot.active.test_and_set(std::memory_order_acq_rel)) {
Expand Down
28 changes: 23 additions & 5 deletions app/src/main/cpp/skyline/gpu/memory_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ namespace skyline::gpu::memory {
VmaAllocation vmaAllocation;
vk::Buffer vkBuffer;

constexpr StagingBuffer(u8 *pointer, size_t size, VmaAllocator vmaAllocator, vk::Buffer vkBuffer, VmaAllocation vmaAllocation) : vmaAllocator(vmaAllocator), vkBuffer(vkBuffer), vmaAllocation(vmaAllocation), span(pointer, size) {}
constexpr StagingBuffer(u8 *pointer, size_t size, VmaAllocator vmaAllocator, vk::Buffer vkBuffer, VmaAllocation vmaAllocation)
: vmaAllocator(vmaAllocator),
vkBuffer(vkBuffer),
vmaAllocation(vmaAllocation),
span(pointer, size) {}

StagingBuffer(const StagingBuffer &) = delete;

constexpr StagingBuffer(StagingBuffer &&other) : vmaAllocator(std::exchange(other.vmaAllocator, nullptr)), vmaAllocation(std::exchange(other.vmaAllocation, nullptr)), vkBuffer(std::exchange(other.vkBuffer, {})) {}
constexpr StagingBuffer(StagingBuffer &&other)
: vmaAllocator(std::exchange(other.vmaAllocator, nullptr)),
vmaAllocation(std::exchange(other.vmaAllocation, nullptr)),
vkBuffer(std::exchange(other.vkBuffer, {})) {}

StagingBuffer &operator=(const StagingBuffer &) = delete;

Expand All @@ -42,13 +49,24 @@ namespace skyline::gpu::memory {
VmaAllocation vmaAllocation;
vk::Image vkImage;

constexpr Image(VmaAllocator vmaAllocator, vk::Image vkImage, VmaAllocation vmaAllocation) : vmaAllocator(vmaAllocator), vkImage(vkImage), vmaAllocation(vmaAllocation) {}
constexpr Image(VmaAllocator vmaAllocator, vk::Image vkImage, VmaAllocation vmaAllocation)
: vmaAllocator(vmaAllocator),
vkImage(vkImage),
vmaAllocation(vmaAllocation) {}

constexpr Image(u8 *pointer, VmaAllocator vmaAllocator, vk::Image vkImage, VmaAllocation vmaAllocation) : pointer(pointer), vmaAllocator(vmaAllocator), vkImage(vkImage), vmaAllocation(vmaAllocation) {}
constexpr Image(u8 *pointer, VmaAllocator vmaAllocator, vk::Image vkImage, VmaAllocation vmaAllocation)
: pointer(pointer),
vmaAllocator(vmaAllocator),
vkImage(vkImage),
vmaAllocation(vmaAllocation) {}

Image(const Image &) = delete;

constexpr Image(Image &&other) : pointer(std::exchange(other.pointer, nullptr)), vmaAllocator(std::exchange(other.vmaAllocator, nullptr)), vmaAllocation(std::exchange(other.vmaAllocation, nullptr)), vkImage(std::exchange(other.vkImage, {})) {}
constexpr Image(Image &&other)
: pointer(std::exchange(other.pointer, nullptr)),
vmaAllocator(std::exchange(other.vmaAllocator, nullptr)),
vmaAllocation(std::exchange(other.vmaAllocation, nullptr)),
vkImage(std::exchange(other.vkImage, {})) {}

Image &operator=(const Image &) = delete;

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/cpp/skyline/gpu/presentation_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ extern jfloat AverageFrametimeDeviationMs;
namespace skyline::gpu {
using namespace service::hosbinder;

PresentationEngine::PresentationEngine(const DeviceState &state, GPU &gpu) : state(state), gpu(gpu), acquireFence(gpu.vkDevice, vk::FenceCreateInfo{}), presentationTrack(static_cast<u64>(trace::TrackIds::Presentation), perfetto::ProcessTrack::Current()), choreographerThread(&PresentationEngine::ChoreographerThread, this), vsyncEvent(std::make_shared<kernel::type::KEvent>(state, true)) {
PresentationEngine::PresentationEngine(const DeviceState &state, GPU &gpu)
: state(state),
gpu(gpu),
acquireFence(gpu.vkDevice, vk::FenceCreateInfo{}),
presentationTrack(static_cast<u64>(trace::TrackIds::Presentation), perfetto::ProcessTrack::Current()),
choreographerThread(&PresentationEngine::ChoreographerThread, this),
vsyncEvent(std::make_shared<kernel::type::KEvent>(state, true)) {
auto desc{presentationTrack.Serialize()};
desc.set_name("Presentation");
perfetto::TrackEvent::SetTrackDescriptor(presentationTrack, desc);
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/cpp/skyline/gpu/texture_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ namespace skyline::gpu {
GuestTexture::Mappings::iterator iterator; //!< An iterator to the mapping in the texture's GuestTexture corresponding to this mapping

template<typename... Args>
TextureMapping(std::shared_ptr<Texture> texture, GuestTexture::Mappings::iterator iterator, Args &&... args) : span<u8>(std::forward<Args>(args)...), texture(std::move(texture)), iterator(iterator) {}
TextureMapping(std::shared_ptr<Texture> texture, GuestTexture::Mappings::iterator iterator, Args &&... args)
: span<u8>(std::forward<Args>(args)...),
texture(std::move(texture)),
iterator(iterator) {}
};

GPU &gpu;
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/cpp/skyline/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ namespace skyline::input {
NpadManager npad;
TouchManager touch;

Input(const DeviceState &state) : state(state), kHid(std::make_shared<kernel::type::KSharedMemory>(state, sizeof(HidSharedMemory))), hid(reinterpret_cast<HidSharedMemory *>(kHid->host.ptr)), npad(state, hid), touch(state, hid) {}
Input(const DeviceState &state)
: state(state),
kHid(std::make_shared<kernel::type::KSharedMemory>(state, sizeof(HidSharedMemory))),
hid(reinterpret_cast<HidSharedMemory *>(kHid->host.ptr)),
npad(state, hid),
touch(state, hid) {}
};
}
6 changes: 5 additions & 1 deletion app/src/main/cpp/skyline/input/npad_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#include "npad.h"

namespace skyline::input {
NpadDevice::NpadDevice(NpadManager &manager, NpadSection &section, NpadId id) : manager(manager), section(section), id(id), updateEvent(std::make_shared<kernel::type::KEvent>(manager.state, false)) {}
NpadDevice::NpadDevice(NpadManager &manager, NpadSection &section, NpadId id)
: manager(manager),
section(section),
id(id),
updateEvent(std::make_shared<kernel::type::KEvent>(manager.state, false)) {}

void NpadDevice::Connect(NpadControllerType newType) {
if (type == newType) {
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/cpp/skyline/jvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ namespace skyline {

thread_local inline JniEnvironment env;

JvmManager::JvmManager(JNIEnv *environ, jobject instance) : instance(environ->NewGlobalRef(instance)), instanceClass(reinterpret_cast<jclass>(environ->NewGlobalRef(environ->GetObjectClass(instance)))), initializeControllersId(environ->GetMethodID(instanceClass, "initializeControllers", "()V")), vibrateDeviceId(environ->GetMethodID(instanceClass, "vibrateDevice", "(I[J[I)V")), clearVibrationDeviceId(environ->GetMethodID(instanceClass, "clearVibrationDevice", "(I)V")), getVersionCodeId(environ->GetMethodID(instanceClass, "getVersionCode", "()I")) {
JvmManager::JvmManager(JNIEnv *environ, jobject instance)
: instance(environ->NewGlobalRef(instance)),
instanceClass(reinterpret_cast<jclass>(environ->NewGlobalRef(environ->GetObjectClass(instance)))),
initializeControllersId(environ->GetMethodID(instanceClass, "initializeControllers", "()V")),
vibrateDeviceId(environ->GetMethodID(instanceClass, "vibrateDevice", "(I[J[I)V")),
clearVibrationDeviceId(environ->GetMethodID(instanceClass, "clearVibrationDevice", "(I)V")),
getVersionCodeId(environ->GetMethodID(instanceClass, "getVersionCode", "()I")) {
env.Initialize(environ);
}

Expand Down
7 changes: 6 additions & 1 deletion app/src/main/cpp/skyline/kernel/types/KPrivateMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#include "KProcess.h"

namespace skyline::kernel::type {
KPrivateMemory::KPrivateMemory(const DeviceState &state, u8 *ptr, size_t size, memory::Permission permission, memory::MemoryState memState) : ptr(ptr), size(size), permission(permission), memoryState(memState), KMemory(state, KType::KPrivateMemory) {
KPrivateMemory::KPrivateMemory(const DeviceState &state, u8 *ptr, size_t size, memory::Permission permission, memory::MemoryState memState)
: ptr(ptr),
size(size),
permission(permission),
memoryState(memState),
KMemory(state, KType::KPrivateMemory) {
if (!state.process->memory.base.IsInside(ptr) || !state.process->memory.base.IsInside(ptr + size))
throw exception("KPrivateMemory allocation isn't inside guest address space: 0x{:X} - 0x{:X}", ptr, ptr + size);
if (!util::IsPageAligned(ptr) || !util::IsPageAligned(size))
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/cpp/skyline/kernel/types/KSharedMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "KProcess.h"

namespace skyline::kernel::type {
KSharedMemory::KSharedMemory(const DeviceState &state, size_t size, memory::MemoryState memState, KType type) : memoryState(memState), KMemory(state, type) {
KSharedMemory::KSharedMemory(const DeviceState &state, size_t size, memory::MemoryState memState, KType type)
: memoryState(memState),
KMemory(state, type) {
fd = ASharedMemory_create("KSharedMemory", size);
if (fd < 0)
throw exception("An error occurred while creating shared memory: {}", fd);
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/cpp/skyline/kernel/types/KThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@
#include "KThread.h"

namespace skyline::kernel::type {
KThread::KThread(const DeviceState &state, KHandle handle, KProcess *parent, size_t id, void *entry, u64 argument, void *stackTop, i8 priority, u8 idealCore) : handle(handle), parent(parent), id(id), entry(entry), entryArgument(argument), stackTop(stackTop), priority(priority), basePriority(priority), idealCore(idealCore), coreId(idealCore), KSyncObject(state, KType::KThread) {
KThread::KThread(const DeviceState &state, KHandle handle, KProcess *parent, size_t id, void *entry, u64 argument, void *stackTop, i8 priority, u8 idealCore)
: handle(handle),
parent(parent),
id(id),
entry(entry),
entryArgument(argument),
stackTop(stackTop),
priority(priority),
basePriority(priority),
idealCore(idealCore),
coreId(idealCore),
KSyncObject(state, KType::KThread) {
affinityMask.set(coreId);
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/cpp/skyline/kernel/types/KTransferMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace skyline::kernel::type {
/**
* @note 'ptr' needs to be in guest-reserved address space
*/
KTransferMemory(const DeviceState &state, u8 *ptr, size_t size, memory::Permission permission, memory::MemoryState memState = memory::states::TransferMemory) : KSharedMemory(state, size, memState, KType::KTransferMemory) {
KTransferMemory(const DeviceState &state, u8 *ptr, size_t size, memory::Permission permission, memory::MemoryState memState = memory::states::TransferMemory)
: KSharedMemory(state, size, memState, KType::KTransferMemory) {
std::memcpy(host.ptr, ptr, size);
Map(ptr, size, permission);
}
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/cpp/skyline/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ namespace skyline::kernel {
std::string appFilesPath,
std::string deviceTimeZone,
language::SystemLanguage systemLanguage,
std::shared_ptr<vfs::FileSystem> assetFileSystem
) : state(this, jvmManager, settings, logger),
appFilesPath(std::move(appFilesPath)),
deviceTimeZone(std::move(deviceTimeZone)),
assetFileSystem(std::move(assetFileSystem)),
serviceManager(state),
systemLanguage(systemLanguage) {}
std::shared_ptr<vfs::FileSystem> assetFileSystem)
: state(this, jvmManager, settings, logger),
appFilesPath(std::move(appFilesPath)),
deviceTimeZone(std::move(deviceTimeZone)),
assetFileSystem(std::move(assetFileSystem)),
serviceManager(state),
systemLanguage(systemLanguage) {}

void OS::Execute(int romFd, loader::RomFormat romType) {
auto romFile{std::make_shared<vfs::OsBacking>(romFd)};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include "ISelfController.h"

namespace skyline::service::am {
ISelfController::ISelfController(const DeviceState &state, ServiceManager &manager) : libraryAppletLaunchableEvent(std::make_shared<type::KEvent>(state, false)), accumulatedSuspendedTickChangedEvent(std::make_shared<type::KEvent>(state, false)), hosbinder(manager.CreateOrGetService<hosbinder::IHOSBinderDriver>("dispdrv")), BaseService(state, manager) {}
ISelfController::ISelfController(const DeviceState &state, ServiceManager &manager)
: libraryAppletLaunchableEvent(std::make_shared<type::KEvent>(state, false)),
accumulatedSuspendedTickChangedEvent(std::make_shared<type::KEvent>(state, false)),
hosbinder(manager.CreateOrGetService<hosbinder::IHOSBinderDriver>("dispdrv")),
BaseService(state, manager) {}

Result ISelfController::Exit(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
throw nce::NCE::ExitException(true);
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/cpp/skyline/services/audio/IAudioOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include "IAudioOut.h"

namespace skyline::service::audio {
IAudioOut::IAudioOut(const DeviceState &state, ServiceManager &manager, u8 channelCount, u32 sampleRate) : sampleRate(sampleRate), channelCount(channelCount), releaseEvent(std::make_shared<type::KEvent>(state, false)), BaseService(state, manager) {
IAudioOut::IAudioOut(const DeviceState &state, ServiceManager &manager, u8 channelCount, u32 sampleRate)
: sampleRate(sampleRate),
channelCount(channelCount),
releaseEvent(std::make_shared<type::KEvent>(state, false)),
BaseService(state, manager) {
track = state.audio->OpenTrack(channelCount, constant::SampleRate, [this]() { releaseEvent->Signal(); });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "INotificationService.h"

namespace skyline::service::friends {
INotificationService::INotificationService(const DeviceState &state, ServiceManager &manager) : notificationEvent(std::make_shared<type::KEvent>(state, false)), BaseService(state, manager) {}
INotificationService::INotificationService(const DeviceState &state, ServiceManager &manager)
: notificationEvent(std::make_shared<type::KEvent>(state, false)),
BaseService(state, manager) {}

Result INotificationService::GetEvent(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
KHandle handle{state.process->InsertItem(notificationEvent)};
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/cpp/skyline/services/fssrv/IFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "IFile.h"

namespace skyline::service::fssrv {
IFile::IFile(std::shared_ptr<vfs::Backing> backing, const DeviceState &state, ServiceManager &manager) : backing(std::move(backing)), BaseService(state, manager) {}
IFile::IFile(std::shared_ptr<vfs::Backing> backing, const DeviceState &state, ServiceManager &manager)
: BaseService(state, manager),
backing(std::move(backing)) {}

Result IFile::Read(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto readOption{request.Pop<u32>()};
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/cpp/skyline/services/glue/IStaticService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include "IStaticService.h"

namespace skyline::service::glue {
IStaticService::IStaticService(const DeviceState &state, ServiceManager &manager, std::shared_ptr<timesrv::IStaticService> core, timesrv::core::TimeServiceObject &timesrvCore, timesrv::StaticServicePermissions permissions) : BaseService(state, manager), core(std::move(core)), timesrvCore(timesrvCore), permissions(permissions) {}
IStaticService::IStaticService(const DeviceState &state, ServiceManager &manager, std::shared_ptr<timesrv::IStaticService> core, timesrv::core::TimeServiceObject &timesrvCore, timesrv::StaticServicePermissions permissions)
: BaseService(state, manager),
core(std::move(core)),
timesrvCore(timesrvCore),
permissions(permissions) {}

Result IStaticService::GetStandardUserSystemClock(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
return core->GetStandardUserSystemClock(session, request, response);
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/cpp/skyline/services/glue/ITimeZoneService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
#include "ITimeZoneService.h"

namespace skyline::service::glue {
ITimeZoneService::ITimeZoneService(const DeviceState &state, ServiceManager &manager, std::shared_ptr<timesrv::ITimeZoneService> core, timesrv::core::TimeServiceObject &timesrvCore, bool writeable) : BaseService(state, manager), core(std::move(core)), timesrvCore(timesrvCore), locationNameUpdateEvent(std::make_shared<kernel::type::KEvent>(state, false)), writeable(writeable) {}
ITimeZoneService::ITimeZoneService(const DeviceState &state, ServiceManager &manager, std::shared_ptr<timesrv::ITimeZoneService> core, timesrv::core::TimeServiceObject &timesrvCore, bool writeable)
: BaseService(state, manager),
core(std::move(core)),
timesrvCore(timesrvCore),
locationNameUpdateEvent(std::make_shared<kernel::type::KEvent>(state, false)),
writeable(writeable) {}

Result ITimeZoneService::GetDeviceLocationName(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
return core->GetDeviceLocationName(session, request, response);
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/cpp/skyline/services/nifm/IRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include "IRequest.h"

namespace skyline::service::nifm {
IRequest::IRequest(const DeviceState &state, ServiceManager &manager) : event0(std::make_shared<type::KEvent>(state, false)), event1(std::make_shared<type::KEvent>(state, false)), BaseService(state, manager) {}
IRequest::IRequest(const DeviceState &state, ServiceManager &manager)
: event0(std::make_shared<type::KEvent>(state, false)),
event1(std::make_shared<type::KEvent>(state, false)),
BaseService(state, manager) {}

Result IRequest::GetRequestState(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
constexpr u32 Unsubmitted{1}; //!< The request has not been submitted
Expand Down
Loading

0 comments on commit ef10d3d

Please sign in to comment.