• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2021 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_SYS_PTHREADTYPES_H
32 #define	_ADAPT_SYS_PTHREADTYPES_H
33 
34 #define pthread_t __pthread_t_discard
35 #define pthread_attr_t __pthread_attr_t_discard
36 #define pthread_mutex_t __pthread_mutex_t_discard
37 #define pthread_mutexattr_t __pthread_mutexattr_t_discard
38 #define pthread_cond_t __pthread_cond_t_discard
39 #define pthread_condattr_t __pthread_condattr_t_discard
40 #define pthread_once_t __pthread_once_t_discard
41 #define pthread_barrierattr_t __pthread_barrierattr_t_discard
42 #define pthread_spinlock_t __pthread_spinlock_t_discard
43 
44 #include_next <sys/_pthreadtypes.h>
45 
46 #undef pthread_t
47 #undef pthread_attr_t
48 #undef pthread_mutex_t
49 #undef pthread_mutexattr_t
50 #undef pthread_cond_t
51 #undef pthread_condattr_t
52 #undef pthread_once_t
53 #undef pthread_barrierattr_t
54 #undef pthread_spinlock_t
55 #undef _PTHREAD_MUTEX_INITIALIZER
56 #undef _PTHREAD_COND_INITIALIZER
57 #undef _PTHREAD_ONCE_INIT
58 
59 #undef PTHREAD_STACK_MIN
60 #undef PTHREAD_MUTEX_DEFAULT
61 
62 #include "los_config.h"
63 #define PTHREAD_STACK_MIN LOSCFG_BASE_CORE_TSK_MIN_STACK_SIZE
64 
65 typedef unsigned long pthread_t;            /* identify a thread */
66 
67 typedef struct {
68     unsigned int detachstate;
69     unsigned int schedpolicy;
70     struct sched_param schedparam;
71     unsigned int inheritsched;
72     unsigned int scope;
73     unsigned int stackaddr_set;
74     void *stackaddr;
75     unsigned int stacksize_set;
76     size_t stacksize;
77 } pthread_attr_t;
78 
79 #include "los_list.h"
80 typedef struct { unsigned type; } pthread_mutexattr_t;
81 typedef struct { unsigned int magic; unsigned int handle; pthread_mutexattr_t stAttr;} pthread_mutex_t;
82 
83 #define _MUX_MAGIC 0xEBCFDEA0
84 #define _MUX_INVALID_HANDLE 0xEEEEEEEF
85 #define PTHREAD_MUTEX_DEFAULT 0
86 
87 #define PTHREAD_MUTEXATTR_INITIALIZER { PTHREAD_MUTEX_RECURSIVE }
88 #define _PTHREAD_MUTEX_INITIALIZER  { _MUX_MAGIC, _MUX_INVALID_HANDLE, PTHREAD_MUTEXATTR_INITIALIZER }
89 
90 #ifdef _GNU_SOURCE
91 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { _MUX_MAGIC, _MUX_INVALID_HANDLE, PTHREAD_MUTEXATTR_INITIALIZER }
92 #endif
93 
94 #include "los_event.h"
95 
96 typedef struct pthread_cond {
97   volatile int count;      /**< The number of tasks blocked by condition */
98   EVENT_CB_S event;        /**< Event object*/
99   pthread_mutex_t* mutex;  /**< Mutex locker for condition variable protection */
100   volatile int value;      /**< Condition variable state value*/
101   int clock;
102 } pthread_cond_t;
103 
104 #define _PTHREAD_COND_INITIALIZER   { 0 }
105 
106 typedef struct { int clock; } pthread_condattr_t;
107 
108 typedef __uint32_t pthread_key_t;        /* thread-specific data keys */
109 
110 typedef int pthread_once_t;
111 
112 #define _PTHREAD_ONCE_INIT  { 0 }
113 
114 typedef struct { unsigned __attr; } pthread_barrierattr_t;
115 
116 typedef int pthread_spinlock_t;
117 
118 #endif /* !_ADAPT_SYS_PTHREADTYPES_H */
119