• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _ADAPT_PTHREAD_H
32 #define _ADAPT_PTHREAD_H
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include "los_mux_pri.h"
38 
39 #ifndef POSIX_MUTEX_DEFAULT_INHERIT
40 #define POSIX_MUTEX_DEFAULT_INHERIT 1
41 #endif
42 
43 typedef LosMuxAttr pthread_mutexattr_t;
44 
45 typedef LosMux pthread_mutex_t;
46 #define pthread_mutex OsMux
47 
48 typedef struct pthread_cond {
49     volatile int count;      /**< The number of tasks blocked by condition */
50     EVENT_CB_S event;        /**< Event object*/
51     pthread_mutex_t* mutex;  /**< Mutex locker for condition variable protection */
52     volatile int value;      /**< Condition variable state value*/
53 } pthread_cond_t;
54 
55 #define pthread_exit __pthread_exit_discard
56 #include_next <pthread.h>
57 #undef pthread_exit
58 #undef PTHREAD_MUTEX_INITIALIZER
59 
60 void pthread_exit(void *retVal);
61 
62 #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
63 #define PTHREAD_PRIO_NONE    LOS_MUX_PRIO_NONE
64 #define PTHREAD_PRIO_INHERIT LOS_MUX_PRIO_INHERIT
65 #define PTHREAD_PRIO_PROTECT LOS_MUX_PRIO_PROTECT
66 
67 #if defined POSIX_MUTEX_DEFAULT_INHERIT
68 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
69     { OS_MUX_MAGIC, { PTHREAD_PRIO_INHERIT, OS_TASK_PRIORITY_LOWEST, PTHREAD_MUTEX_RECURSIVE_NP, 0 }, \
70      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
71      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
72      (VOID *)NULL, 0 }
73 
74 #define PTHREAD_MUTEX_INITIALIZER \
75     { OS_MUX_MAGIC, { PTHREAD_PRIO_INHERIT, OS_TASK_PRIORITY_LOWEST, 0, 0 }, \
76      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
77      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
78      (VOID *)NULL, 0 }
79 #elif defined POSIX_MUTEX_DEFAULT_PROTECT
80 
81 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
82     { OS_MUX_MAGIC, { PTHREAD_PRIO_PROTECT, OS_TASK_PRIORITY_LOWEST, PTHREAD_MUTEX_RECURSIVE_NP, 0 }, \
83      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
84      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
85      (VOID *)NULL, 0 }
86 
87 #define PTHREAD_MUTEX_INITIALIZER \
88     { OS_MUX_MAGIC, { PTHREAD_PRIO_PROTECT, OS_TASK_PRIORITY_LOWEST, 0, 0 },  \
89      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
90      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
91      (VOID *)NULL, 0 }
92 #else
93 
94 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
95     { OS_MUX_MAGIC, { PTHREAD_PRIO_NONE, OS_TASK_PRIORITY_LOWEST, PTHREAD_MUTEX_RECURSIVE_NP, 0 }, \
96      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
97      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
98      (VOID *)NULL, 0 }
99 
100 #define PTHREAD_MUTEX_INITIALIZER \
101     { OS_MUX_MAGIC, { PTHREAD_PRIO_NONE, OS_TASK_PRIORITY_LOWEST, 0, 0 }, \
102      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
103      { (struct LOS_DL_LIST *)NULL, (struct LOS_DL_LIST *)NULL }, \
104      (VOID *)NULL, 0 }
105 #endif
106 
107 int pthread_attr_setaffinity_np(pthread_attr_t *, size_t, const cpu_set_t *);
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 #endif
113