1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef META_INTERFACE_ILOCKABLE_H
17 #define META_INTERFACE_ILOCKABLE_H
18 
19 #include <cstdint>
20 
21 #include <core/plugin/intf_interface.h>
22 
23 #include <meta/base/interface_macros.h>
24 #include <meta/base/namespace.h>
25 #include <meta/base/shared_ptr.h>
26 #include <meta/base/types.h>
27 
28 META_BEGIN_NAMESPACE()
29 
30 /**
31  * @brief Support locking
32  */
33 META_REGISTER_INTERFACE(ILockable, "79ff7f69-93aa-43cb-b6f0-49ace40927ac")
34 class ILockable : public CORE_NS::IInterface {
35     META_INTERFACE(CORE_NS::IInterface, ILockable)
36 public:
37     /**
38      * @brief Unique lock, lock for writing
39      */
40     virtual void Lock() const = 0;
41     virtual void Unlock() const = 0;
42 
43     /**
44      *  @brief Shared lock, lock for reading. This gives the implementation possibility
45      *         to provide better granularity but might be implemented as unique lock as well.
46      */
47     virtual void LockShared() const = 0;
48     virtual void UnlockShared() const = 0;
49 };
50 
51 META_REGISTER_INTERFACE(IRecursivelyLockable, "77d7c7bb-2973-4477-acd8-86f7a21eff30")
52 /**
53  * @brief Recursive version of the lockable.
54  */
55 class IRecursivelyLockable : public ILockable {
56     META_INTERFACE(CORE_NS::IInterface, IRecursivelyLockable)
57 };
58 
59 enum class LockType { NO_LOCK = 0, UNIQUE_LOCK = 1, SHARED_LOCK = 2 };
60 
61 META_END_NAMESPACE()
62 
63 #endif
64