MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pthread_cond_init

Function pthread_cond_init

components/libc/posix/pthreads/pthread_cond.c:99–134  ·  view source on GitHub ↗

* @brief Initializes a condition variable. * * This function initializes the condition variable pointed to by `cond` with the attributes * specified by `attr`. If `attr` is NULL, the condition variable is initialized with the * default attributes. * * @param cond A pointer to the condition variable to be initialized. * Must point to valid memory. * @param attr A pointer to the

Source from the content-addressed store, hash-verified

97 * @see pthread_cond_destroy, pthread_cond_wait, pthread_cond_signal, pthread_cond_broadcast
98 */
99int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
100{
101 rt_err_t result;
102 char cond_name[RT_NAME_MAX];
103 static rt_uint16_t cond_num = 0;
104
105 /* parameter check */
106 if (cond == RT_NULL)
107 return EINVAL;
108 if ((attr != RT_NULL) && (*attr != PTHREAD_PROCESS_PRIVATE))
109 return EINVAL;
110
111 rt_snprintf(cond_name, sizeof(cond_name), "cond%02d", cond_num++);
112
113 /* use default value */
114 if (attr == RT_NULL)
115 {
116 cond->attr = PTHREAD_PROCESS_PRIVATE;
117 }
118 else
119 {
120 cond->attr = *attr;
121 }
122
123 result = rt_sem_init(&cond->sem, cond_name, 0, RT_IPC_FLAG_FIFO);
124 if (result != RT_EOK)
125 {
126 return EINVAL;
127 }
128
129 /* detach the object from system object container */
130 rt_object_detach(&(cond->sem.parent.parent));
131 cond->sem.parent.parent.type = RT_Object_Class_Semaphore;
132
133 return 0;
134}
135RTM_EXPORT(pthread_cond_init);
136
137/**

Callers 9

pthread_barrier_initFunction · 0.85
pthread_cond_broadcastFunction · 0.85
pthread_cond_signalFunction · 0.85
_pthread_cond_timedwaitFunction · 0.85
pthread_rwlock_initFunction · 0.85
rt_hw_sdl_startFunction · 0.85
test_threadFunction · 0.85
libc_ex7Function · 0.85
initFunction · 0.85

Calls 3

rt_snprintfFunction · 0.85
rt_sem_initFunction · 0.85
rt_object_detachFunction · 0.85

Tested by 1

test_threadFunction · 0.68