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_THREADING_PRIMITIVE_API_H
17 #define META_INTERFACE_THREADING_PRIMITIVE_API_H
18 
19 #include <stdint.h>
20 
21 #include <core/namespace.h>
22 
23 CORE_BEGIN_NAMESPACE()
24 
25 enum class MutexType {
26     NORMAL,
27     // RECURSIVE,
28     // SHARED
29 };
30 
31 struct alignas(8) MutexHandle { // 8 alignment size
32     union {
33         void* ptr = nullptr;
34         char storage[40];
35     };
36 };
37 
38 using CreateMutexType = void (*)(MutexType, MutexHandle&);
39 using DestroyMutexType = void (*)(MutexHandle&);
40 using LockMutexType = bool (*)(MutexHandle&);
41 using UnlockMutexType = bool (*)(MutexHandle&);
42 
43 using NativeThreadHandle = uint64_t;
44 using GetThreadIdType = NativeThreadHandle (*)();
45 
46 struct SyncApi {
47     struct MutexApi {
48         CreateMutexType create = nullptr;
49         DestroyMutexType destroy = nullptr;
50         LockMutexType lock = nullptr;
51         UnlockMutexType unlock = nullptr;
52     } mutex;
53 
54     GetThreadIdType getThreadId = nullptr;
55 };
56 
57 CORE_END_NAMESPACE()
58 
59 #endif