gpio: implement more of server library for boot sysmodule client usage

This commit is contained in:
Michael Scire 2020-10-31 03:22:01 -07:00 committed by SciresM
parent e1b5d81d65
commit bd3ab76fd2
26 changed files with 1162 additions and 24 deletions

View file

@ -62,6 +62,40 @@ namespace ams::sf {
return std::make_shared<typename Interface::ImplSharedPointer<Impl>>(std::make_shared<Impl>(std::forward<Arguments>(args)...));
}
template<typename Interface, typename Impl>
class ServiceObjectAllocator {
public:
using value_type = typename Interface::ImplHolder<Impl>;
private:
MemoryResource * const memory_resource;
public:
constexpr ServiceObjectAllocator(MemoryResource *mr) : memory_resource(mr) { /* ... */ }
value_type *allocate(size_t n) const {
void *mem = this->memory_resource->Allocate(n * sizeof(value_type), alignof(value_type));
AMS_ABORT_UNLESS(mem != nullptr);
return mem;
}
void deallocate(void *p, size_t n) const {
this->memory_resource->Deallocate(p, n * sizeof(value_type), alignof(value_type));
}
inline bool operator==(const ServiceObjectAllocator &rhs) const {
return this->memory_resource->is_equal(*rhs->memory_resource);
}
inline bool operator!=(const ServiceObjectAllocator &rhs) const {
return !(*this == rhs);
}
};
template<typename Interface, typename Impl, typename Allocator, typename... Arguments>
requires std::constructible_from<Impl, Arguments...>
constexpr ALWAYS_INLINE std::shared_ptr<typename Interface::ImplHolder<Impl>> AllocateShared(const Allocator &allocator, Arguments &&... args) {
return std::allocate_shared<typename Interface::ImplHolder<Impl>>(allocator, std::forward<Arguments>(args)...);
}
template<typename Interface, typename Impl>
constexpr ALWAYS_INLINE std::shared_ptr<typename Interface::ImplPointer<Impl>> GetSharedPointerTo(Impl *impl) {
return std::make_shared<typename Interface::ImplPointer<Impl>>(impl);
@ -72,4 +106,4 @@ namespace ams::sf {
return GetSharedPointerTo<Interface, Impl>(std::addressof(impl));
}
}
}