• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // CLObject.h: Defines the cl::Object class, which is the base class of all ANGLE CL objects.
7 
8 #ifndef LIBANGLE_CLOBJECT_H_
9 #define LIBANGLE_CLOBJECT_H_
10 
11 #include "libANGLE/CLtypes.h"
12 #include "libANGLE/renderer/CLtypes.h"
13 
14 #include <atomic>
15 
16 namespace cl
17 {
18 
19 class Object
20 {
21   public:
22     Object();
23     virtual ~Object();
24 
getRefCount()25     cl_uint getRefCount() const noexcept { return mRefCount; }
26 
retain()27     void retain() noexcept { ++mRefCount; }
28 
release()29     bool release()
30     {
31         if (mRefCount == 0u)
32         {
33             WARN() << "Unreferenced object without references";
34             return true;
35         }
36         return --mRefCount == 0u;
37     }
38 
39     template <typename T, typename... Args>
Create(cl_int & errorCode,Args &&...args)40     static T *Create(cl_int &errorCode, Args &&... args)
41     {
42         T *object = new T(std::forward<Args>(args)..., errorCode);
43         if (errorCode != CL_SUCCESS)
44         {
45             delete object;
46             object = nullptr;
47         }
48         return object;
49     }
50 
51   private:
52     std::atomic<cl_uint> mRefCount;
53 };
54 
55 }  // namespace cl
56 
57 #endif  // LIBANGLE_CLCONTEXT_H_
58