]> git.seodisparate.com - EN605.617.81.FA21_StephenSeo_DitheringProject/commitdiff
Minor fixes to opencl_handle
authorStephen Seo <seo.disparate@gmail.com>
Thu, 18 Nov 2021 05:05:25 +0000 (14:05 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 18 Nov 2021 05:05:25 +0000 (14:05 +0900)
src/opencl_handle.cc
src/opencl_handle.h

index 9cfff815587b313d08428ff9e65b4f82ded88ffd..c2a444302d54ddc23cc7a10464381a3ad1fd4499 100644 (file)
@@ -11,7 +11,7 @@ OpenCLContext::OpenCLHandle::OpenCLHandle()
 
 OpenCLContext::OpenCLHandle::~OpenCLHandle() {
   CleanupAllKernels();
-  OpenCLContext::CheckRefCount();
+  OpenCLContext::CleanupInstance();
 }
 
 bool OpenCLContext::OpenCLHandle::IsValid() const {
@@ -650,13 +650,9 @@ OpenCLContext::OpenCLHandle::Ptr OpenCLContext::GetHandle() {
   return strong_handle;
 }
 
-void OpenCLContext::CheckRefCount() {
-  if (instance_) {
-    if (instance_->weak_handle_.use_count() <= 1) {
-      // Last shared_ptr is destructing, cleanup context by calling destructor
-      instance_.reset();
-    }
-  }
+void OpenCLContext::CleanupInstance() {
+  // OpenCLHandle is destructing, cleanup context by calling destructor
+  instance_.reset();
 }
 
 bool OpenCLContext::IsValid() const { return context_ && queue_; }
index 8b955aa8a1483ad14b2d5742237641c22b10ac99..6a22c1efbcbcc07e624fbe19b33b2d201a2a5787 100644 (file)
@@ -22,6 +22,14 @@ class OpenCLContext {
   typedef std::shared_ptr<OpenCLContext> Ptr;
   typedef std::weak_ptr<OpenCLContext> WeakPtr;
 
+  /*!
+   * \brief A simplified handle to OpenCL
+   *
+   * This class can only be obtained by a call to OpenCLContext::GetHandle()
+   *
+   * OpenCL is automatically cleaned up when all shared ptrs of OpenCLHandle are
+   * destructed
+   */
   class OpenCLHandle {
    public:
     typedef std::shared_ptr<OpenCLHandle> Ptr;
@@ -33,9 +41,9 @@ class OpenCLContext {
     OpenCLHandle(const OpenCLHandle &other) = delete;
     OpenCLHandle &operator=(const OpenCLHandle &other) = delete;
 
-    // allow move
-    OpenCLHandle(OpenCLHandle &&other) = default;
-    OpenCLHandle &operator=(OpenCLHandle &&other) = default;
+    // no move
+    OpenCLHandle(OpenCLHandle &&other) = delete;
+    OpenCLHandle &operator=(OpenCLHandle &&other) = delete;
 
     bool IsValid() const;
 
@@ -206,6 +214,7 @@ class OpenCLContext {
   OpenCLContext(OpenCLContext &&other) = delete;
   OpenCLContext &operator=(OpenCLContext &&other) = delete;
 
+  /// Returns a OpenCLHandle wrapped in a std::shared_ptr
   OpenCLHandle::Ptr GetHandle();
 
  private:
@@ -218,7 +227,7 @@ class OpenCLContext {
   cl_command_queue queue_;
   cl_device_id device_id_;
 
-  static void CheckRefCount();
+  static void CleanupInstance();
 
   bool IsValid() const;
 };