From b794cace6e8178d8d015801edcb372932e6e2676 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Mon, 15 Nov 2021 22:10:45 +0900 Subject: [PATCH] Tweaks to OpenCLContext/OpenCLHandle defs --- src/opencl_handle.cc | 8 +++---- src/opencl_handle.h | 57 +++++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/opencl_handle.cc b/src/opencl_handle.cc index d8303c2..830fc88 100644 --- a/src/opencl_handle.cc +++ b/src/opencl_handle.cc @@ -1,12 +1,12 @@ #include "opencl_handle.h" -std::unique_ptr OpenCLContext::instance_ = {}; +OpenCLContext::Ptr OpenCLContext::instance_ = {}; -OpenCLHandle::OpenCLHandle() { +OpenCLContext::OpenCLHandle::OpenCLHandle() { // TODO } -OpenCLHandle::~OpenCLHandle() { OpenCLContext::CheckRefCount(); } +OpenCLContext::OpenCLHandle::~OpenCLHandle() { OpenCLContext::CheckRefCount(); } OpenCLContext::OpenCLContext() { // TODO @@ -16,7 +16,7 @@ OpenCLContext::~OpenCLContext() { // TODO } -OpenCLHandle::Ptr OpenCLContext::GetHandle() { +OpenCLContext::OpenCLHandle::Ptr OpenCLContext::GetHandle() { if (!instance_) { // cannot use make_unique due to private constructor instance_ = std::unique_ptr(new OpenCLContext()); diff --git a/src/opencl_handle.h b/src/opencl_handle.h index c0584c6..43460d4 100644 --- a/src/opencl_handle.h +++ b/src/opencl_handle.h @@ -3,32 +3,37 @@ #include -class OpenCLHandle { - public: - typedef std::shared_ptr Ptr; - typedef std::weak_ptr WeakPtr; - - ~OpenCLHandle(); - - // no copy - OpenCLHandle(const OpenCLHandle &other) = delete; - OpenCLHandle &operator=(const OpenCLHandle &other) = delete; - - // allow move - OpenCLHandle(OpenCLHandle &&other) = default; - OpenCLHandle &operator=(OpenCLHandle &&other) = default; - - // TODO add functions here that allow creating/deleting/using kernel function - // programs - - private: - friend class OpenCLContext; - - OpenCLHandle(); -}; - class OpenCLContext { public: + typedef std::shared_ptr Ptr; + typedef std::weak_ptr WeakPtr; + + class OpenCLHandle { + public: + typedef std::shared_ptr Ptr; + typedef std::weak_ptr WeakPtr; + + ~OpenCLHandle(); + + // no copy + OpenCLHandle(const OpenCLHandle &other) = delete; + OpenCLHandle &operator=(const OpenCLHandle &other) = delete; + + // allow move + OpenCLHandle(OpenCLHandle &&other) = default; + OpenCLHandle &operator=(OpenCLHandle &&other) = default; + + // TODO add functions here that allow creating/deleting/using kernel + // function programs + + private: + friend class OpenCLContext; + + OpenCLHandle(); + + OpenCLContext::WeakPtr opencl_ptr_; + }; + ~OpenCLContext(); // no copy @@ -42,11 +47,9 @@ class OpenCLContext { OpenCLHandle::Ptr GetHandle(); private: - friend class OpenCLHandle; - OpenCLContext(); - static std::unique_ptr instance_; + static Ptr instance_; OpenCLHandle::WeakPtr weak_handle_; static void CheckRefCount();