]> git.seodisparate.com - EN605.617.81.FA21_StephenSeo_DitheringProject/commitdiff
Tweaks to OpenCLContext/OpenCLHandle defs
authorStephen Seo <seo.disparate@gmail.com>
Mon, 15 Nov 2021 13:10:45 +0000 (22:10 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 15 Nov 2021 13:10:45 +0000 (22:10 +0900)
src/opencl_handle.cc
src/opencl_handle.h

index d8303c210cee2c78d3cb5dac31a5337e96a7c523..830fc88935c7b642c894bc966a8aadbe5a503a7c 100644 (file)
@@ -1,12 +1,12 @@
 #include "opencl_handle.h"
 
-std::unique_ptr<OpenCLContext> 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<OpenCLContext>(new OpenCLContext());
index c0584c65f19ca9626b8493cc97e35db24e5cb505..43460d4c65c788dae30188511425294d6f645888 100644 (file)
@@ -3,32 +3,37 @@
 
 #include <memory>
 
-class OpenCLHandle {
+class OpenCLContext {
  public:
-  typedef std::shared_ptr<OpenCLHandle> Ptr;
-  typedef std::weak_ptr<OpenCLHandle> WeakPtr;
+  typedef std::shared_ptr<OpenCLContext> Ptr;
+  typedef std::weak_ptr<OpenCLContext> WeakPtr;
 
-  ~OpenCLHandle();
+  class OpenCLHandle {
+   public:
+    typedef std::shared_ptr<OpenCLHandle> Ptr;
+    typedef std::weak_ptr<OpenCLHandle> WeakPtr;
 
-  // no copy
-  OpenCLHandle(const OpenCLHandle &other) = delete;
-  OpenCLHandle &operator=(const OpenCLHandle &other) = delete;
+    ~OpenCLHandle();
 
-  // allow move
-  OpenCLHandle(OpenCLHandle &&other) = default;
-  OpenCLHandle &operator=(OpenCLHandle &&other) = default;
+    // no copy
+    OpenCLHandle(const OpenCLHandle &other) = delete;
+    OpenCLHandle &operator=(const OpenCLHandle &other) = delete;
 
-  // TODO add functions here that allow creating/deleting/using kernel function
-  // programs
+    // allow move
+    OpenCLHandle(OpenCLHandle &&other) = default;
+    OpenCLHandle &operator=(OpenCLHandle &&other) = default;
 
- private:
-  friend class OpenCLContext;
+    // TODO add functions here that allow creating/deleting/using kernel
+    // function programs
 
-  OpenCLHandle();
-};
+   private:
+    friend class OpenCLContext;
+
+    OpenCLHandle();
+
+    OpenCLContext::WeakPtr opencl_ptr_;
+  };
 
-class OpenCLContext {
- public:
   ~OpenCLContext();
 
   // no copy
@@ -42,11 +47,9 @@ class OpenCLContext {
   OpenCLHandle::Ptr GetHandle();
 
  private:
-  friend class OpenCLHandle;
-
   OpenCLContext();
 
-  static std::unique_ptr<OpenCLContext> instance_;
+  static Ptr instance_;
   OpenCLHandle::WeakPtr weak_handle_;
 
   static void CheckRefCount();