Repository: skyline-emu/skyline
File: app/src/main/cpp/skyline/services/nvdrv/devices/nvhost_ctrl.h (C/C++)

Code before:
        constexpr u32 NvHostEventCount{64}; //!< The maximum number of nvhost events
    }

    namespace service::nvdrv::device {
        /**
         * @brief Events are used to expose fences to the userspace, they can be waited on using an IOCTL or be converted into a native HOS KEvent object that can be waited on just like any other KEvent on the guest
         */
        class NvHostEvent {
          private:
            u64 waiterId{};

            void Signal();

          public:
            enum class State {
                Available = 0,
                Waiting = 1,
                Cancelling = 2,
                Signalling = 3,
                Signalled = 4,
                Cancelled = 5,
            };

            NvHostEvent(const DeviceState &state);

            State state{State::Available};
            Fence fence{}; //!< The fence that is attached to this event
            std::shared_ptr<type::KEvent> event{}; //!< Returned by 'QueryEvent'

            /**
             * @brief Stops any wait requests on an event and immediately signals it
             */
            void Cancel(const std::shared_ptr<gpu::GPU> &gpuState);

            /**
             * @brief Asynchronously waits on an event using the given fence
             */
            void Wait(const std::shared_ptr<gpu::GPU> &gpuState, const Fence &fence);
        };

        /**
         * @brief NvHostCtrl (/dev/nvhost-ctrl) is used for GPU synchronization
         * @url https://switchbrew.org/wiki/NV_services#.2Fdev.2Fnvhost-ctrl
         */
        class NvHostCtrl : public NvDevice {
          private:
            /**
             * @brief Metadata about an event, it's used by QueryEvent and EventWait
             */
            union EventValue {
                u32 val;

Review comment (suggestion):
We generally use `mutex` rather than `mtx`, I'll make this change global but you should add it here. A comment regarding what the mutex helps protect would be nice as well.

Code after:
        constexpr u32 NvHostEventCount{64}; //!< The maximum number of nvhost events
    }

    namespace service::nvdrv::device {
        /**
         * @brief Syncpoint Events are used to expose fences to the userspace, they can be waited on using an IOCTL or be converted into a native HOS KEvent object that can be waited on just like any other KEvent on the guest
         */
        class SyncpointEvent {
          private:
            u64 waiterId{};

            void Signal();

          public:
            enum class State {
                Available = 0,
                Waiting = 1,
                Cancelling = 2,
                Signalling = 3,
                Signalled = 4,
                Cancelled = 5,
            };

            SyncpointEvent(const DeviceState &state);

            std::recursive_mutex mutex; //!< Protects access to the entire event
            State state{State::Available};
            Fence fence{}; //!< The fence that is associated with this syncpoint event
            std::shared_ptr<type::KEvent> event{}; //!< Returned by 'QueryEvent'

            /**
             * @brief Removes any wait requests on a syncpoint event and resets its state
             */
            void Cancel(const std::shared_ptr<gpu::GPU> &gpuState);

            /**
             * @brief Asynchronously waits on a syncpoint event using the given fence
             */
            void Wait(const std::shared_ptr<gpu::GPU> &gpuState, const Fence &fence);
        };

        /**
         * @brief NvHostCtrl (/dev/nvhost-ctrl) is used for NvHost management and synchronisation
         * @url https://switchbrew.org/wiki/NV_services#.2Fdev.2Fnvhost-ctrl
         */
        class NvHostCtrl : public NvDevice {
          private:
            std::mutex syncpointEventMutex;
            std::array<std::shared_ptr<SyncpointEvent>, constant::NvHostEventCount> syncpointEvents{};

            /**