• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 SOFTBUS_ADAPTER_THREAD_H
17 #define SOFTBUS_ADAPTER_THREAD_H
18 
19 #include <stdint.h>
20 #include "softbus_adapter_timer.h"
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 #define TASK_NAME_MAX_LEN (16)
29 typedef enum {
30     SOFTBUS_SCHED_OTHER,
31     SOFTBUS_SCHED_RR
32 } SoftBusSched;
33 
34 typedef enum {
35     SOFTBUS_THREAD_JOINABLE,
36     SOFTBUS_THREAD_DETACH
37 }SoftBusDetachState;
38 
39 typedef enum {
40     SOFTBUS_PRIORITY_LOWEST,
41     SOFTBUS_PRIORITY_LOW,
42     SOFTBUS_PRIORITY_DEFAULT,
43     SOFTBUS_PRIORITY_HIGH,
44     SOFTBUS_PRIORITY_HIGHEST
45 } SoftBusThreadPriority;
46 
47 
48 typedef struct {
49     const char *taskName;
50     int32_t policy;
51     int32_t detachState;
52     uint64_t stackSize;
53     SoftBusThreadPriority prior;
54 } SoftBusThreadAttr;
55 
56 typedef enum {
57     SOFTBUS_MUTEX_NORMAL,
58     SOFTBUS_MUTEX_RECURSIVE
59 } SoftBusMutexType;
60 
61 typedef struct {
62     SoftBusMutexType type;
63 } SoftBusMutexAttr;
64 
65 typedef uintptr_t SoftBusThread;
66 typedef uintptr_t SoftBusMutex;
67 typedef uintptr_t SoftBusCond;
68 /* mutex */
69 int32_t SoftBusMutexAttrInit(SoftBusMutexAttr *mutexAttr);
70 int32_t SoftBusMutexInit(SoftBusMutex *mutex, SoftBusMutexAttr *mutexAttr);
71 int32_t SoftBusMutexLock(SoftBusMutex *mutex);
72 int32_t SoftBusMutexUnlock(SoftBusMutex *mutex);
73 int32_t SoftBusMutexDestroy(SoftBusMutex *mutex);
74 
75 /* pthread */
76 int32_t SoftBusThreadAttrInit(SoftBusThreadAttr *threadAttr);
77 int32_t SoftBusThreadCreate(SoftBusThread *thread, SoftBusThreadAttr *threadAttr, void *(*threadEntry)(void *),
78     void *arg);
79 int32_t SoftBusThreadJoin(SoftBusThread thread, void **value);
80 int32_t SoftBusThreadSetName(SoftBusThread thread, const char *name);
81 SoftBusThread SoftBusThreadGetSelf(void);
82 
83 /* cond */
84 int32_t SoftBusCondInit(SoftBusCond *cond);
85 int32_t SoftBusCondSignal(SoftBusCond *cond);
86 int32_t SoftBusCondBroadcast(SoftBusCond *cond);
87 int32_t SoftBusCondWait(SoftBusCond *cond, SoftBusMutex *mutex, SoftBusSysTime *time);
88 int32_t SoftBusCondDestroy(SoftBusCond *cond);
89 
90 #ifdef __cplusplus
91 #if __cplusplus
92 }
93 #endif /* __cplusplus */
94 #endif /* __cplusplus */
95 
96 #endif
97