• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/types.h>
26 
27 META_BEGIN_NAMESPACE()
28 
29 /**
30  * @brief Support locking
31  */
32 META_REGISTER_INTERFACE(ILockable, "79ff7f69-93aa-43cb-b6f0-49ace40927ac")
33 class ILockable : public CORE_NS::IInterface {
34     META_INTERFACE(CORE_NS::IInterface, ILockable)
35 public:
36     /**
37      * @brief Unique lock, lock for writing
38      */
39     virtual void Lock() const = 0;
40     virtual void Unlock() const = 0;
41 
42     /**
43      *  @brief Shared lock, lock for reading. This gives the implementation possibility
44      *         to provide better granularity but might be implemented as unique lock as well.
45      */
46     virtual void LockShared() const = 0;
47     virtual void UnlockShared() const = 0;
48 };
49 
50 META_REGISTER_INTERFACE(IRecursivelyLockable, "77d7c7bb-2973-4477-acd8-86f7a21eff30")
51 /**
52  * @brief Recursive version of the lockable.
53  */
54 class IRecursivelyLockable : public ILockable {
55     META_INTERFACE(CORE_NS::IInterface, IRecursivelyLockable)
56 };
57 
58 enum class LockType { NO_LOCK = 0, UNIQUE_LOCK = 1, SHARED_LOCK = 2 };
59 
60 META_END_NAMESPACE()
61 
62 #endif
63