* @brief Create a Shared FuTeX (sftx) * * @param[in] key Pointer to shared futex key structure * @param[in] lwp Pointer to lightweight process structure * * @return Pointer to created futex on success, NULL on failure * * @note This function: * - Allocates memory for new futex * - Creates custom object with _sftx_destroy as destructor * - Adds futex to global table *
| 298 | * - Initializes futex members (mutex, waiting_thread list) |
| 299 | */ |
| 300 | static rt_futex_t _sftx_create(struct shared_futex_key *key, struct rt_lwp *lwp) |
| 301 | { |
| 302 | rt_futex_t futex = RT_NULL; |
| 303 | struct rt_object *obj = RT_NULL; |
| 304 | |
| 305 | if (lwp) |
| 306 | { |
| 307 | futex = (rt_futex_t)rt_calloc(1, sizeof(struct rt_futex)); |
| 308 | if (futex) |
| 309 | { |
| 310 | /* create a Shared FuTeX (sftx) */ |
| 311 | obj = rt_custom_object_create("sftx", (void *)futex, _sftx_destroy); |
| 312 | if (!obj) |
| 313 | { |
| 314 | rt_free(futex); |
| 315 | futex = RT_NULL; |
| 316 | } |
| 317 | else |
| 318 | { |
| 319 | if (futex_global_table_add(key, futex)) |
| 320 | { |
| 321 | rt_object_delete(obj); |
| 322 | rt_free(futex); |
| 323 | futex = RT_NULL; |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | futex->mutex = RT_NULL; |
| 328 | rt_list_init(&(futex->waiting_thread)); |
| 329 | futex->custom_obj = obj; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | return futex; |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * @brief Get or create a Shared FuTeX (sftx) for given user address |
no test coverage detected