Edit

kc3-lang/angle/src/libANGLE/CLObject.h

Branch :

  • Show log

    Commit

  • Author : John Plate
    Date : 2021-06-17 09:29:29
    Hash : 44a5c913
    Message : CL: Make CL front end and back end thread-safe Add locking to all mutable variables of the CL objects in the front end and pass-through back end to make them thread-safe. This fixes a crash in a multi-threaded CTS test. Bug: angleproject:6015 Change-Id: I1d6471c851217639411c434c82acd32d14035291 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2967468 Commit-Queue: John Plate <jplate@google.com> Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>

  • src/libANGLE/CLObject.h
  • //
    // Copyright 2021 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    // CLObject.h: Defines the cl::Object class, which is the base class of all ANGLE CL objects.
    
    #ifndef LIBANGLE_CLOBJECT_H_
    #define LIBANGLE_CLOBJECT_H_
    
    #include "libANGLE/CLtypes.h"
    #include "libANGLE/renderer/CLtypes.h"
    
    #include <atomic>
    
    namespace cl
    {
    
    class Object
    {
      public:
        Object();
        virtual ~Object();
    
        cl_uint getRefCount() const noexcept { return mRefCount; }
    
        void retain() noexcept { ++mRefCount; }
    
        bool release()
        {
            if (mRefCount == 0u)
            {
                WARN() << "Unreferenced object without references";
                return true;
            }
            return --mRefCount == 0u;
        }
    
        template <typename T, typename... Args>
        static T *Create(cl_int &errorCode, Args &&... args)
        {
            T *object = new T(std::forward<Args>(args)..., errorCode);
            if (errorCode != CL_SUCCESS)
            {
                delete object;
                object = nullptr;
            }
            return object;
        }
    
      private:
        std::atomic<cl_uint> mRefCount;
    };
    
    }  // namespace cl
    
    #endif  // LIBANGLE_CLCONTEXT_H_