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

Function _pftx_create_locked

components/lwp/lwp_futex.c:141–204  ·  view source on GitHub ↗

* @brief Creates and initializes a private futex * * @param[in] uaddr Pointer to the user-space address used as futex key * @param[in] lwp Pointer to the lightweight process structure * * @return rt_futex_t Returns pointer to created futex on success, NULL on failure * * @note This function allocates memory, creates a custom object, * adds it to the lwp user object tree, and initiali

Source from the content-addressed store, hash-verified

139 * The created futex will be automatically destroyed when the lwp is freed.
140 */
141static rt_futex_t _pftx_create_locked(int *uaddr, struct rt_lwp *lwp)
142{
143 rt_futex_t futex = RT_NULL;
144 struct rt_object *obj = RT_NULL;
145
146 /**
147 * Brief: Create a futex under current lwp
148 *
149 * Note: Critical Section
150 * - lwp (READ; share with thread)
151 */
152 if (lwp)
153 {
154 futex = (rt_futex_t)rt_malloc(sizeof(struct rt_futex));
155 if (futex)
156 {
157 /* Create a Private FuTeX (pftx) */
158 obj = rt_custom_object_create("pftx", (void *)futex,
159 _pftx_destroy_locked);
160 if (!obj)
161 {
162 rt_free(futex);
163 futex = RT_NULL;
164 }
165 else
166 {
167 /**
168 * Brief: Add futex to user object tree for resource recycling
169 *
170 * Note: Critical Section
171 * - lwp user object tree (RW; protected by API)
172 * - futex (if the adding is successful, others can find the
173 * unready futex. However, only the lwp_free will do this,
174 * and this is protected by the ref taken by the lwp thread
175 * that the lwp_free will never execute at the same time)
176 */
177 if (lwp_user_object_add(lwp, obj))
178 {
179 /* this will call a _pftx_destroy_locked, but that's okay */
180 rt_object_delete(obj);
181 rt_free(futex);
182 futex = RT_NULL;
183 }
184 else
185 {
186 futex->node.avl_key = (avl_key_t)uaddr;
187 futex->node.data = &lwp->address_search_head;
188 futex->custom_obj = obj;
189 futex->mutex = RT_NULL;
190 rt_list_init(&(futex->waiting_thread));
191
192 /**
193 * Brief: Insert into futex head
194 *
195 * Note: Critical Section
196 * - lwp address_search_head (RW; protected by caller)
197 */
198 lwp_avl_insert(&futex->node, &lwp->address_search_head);

Callers 1

_pftx_getFunction · 0.85

Calls 7

rt_mallocFunction · 0.85
rt_custom_object_createFunction · 0.85
rt_freeFunction · 0.85
lwp_user_object_addFunction · 0.85
rt_object_deleteFunction · 0.85
rt_list_initFunction · 0.85
lwp_avl_insertFunction · 0.85

Tested by

no test coverage detected