* @brief Creates a mailbox for inter-thread or inter-process communication. * * This system call creates a mailbox object with the specified name and size. * The mailbox is used to exchange messages between threads or tasks in a * synchronized manner. The mailbox can be used to send and receive messages * of a specified size. * * @param[in] name A string representing the name of the mailbox
| 2320 | * @see sys_mb_delete(), sys_mb_send(), sys_mb_recv() |
| 2321 | */ |
| 2322 | rt_mailbox_t sys_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) |
| 2323 | { |
| 2324 | int len = 0; |
| 2325 | rt_mailbox_t mb = RT_NULL; |
| 2326 | char *kname = RT_NULL; |
| 2327 | |
| 2328 | len = lwp_user_strlen(name); |
| 2329 | if (len <= 0) |
| 2330 | { |
| 2331 | return RT_NULL; |
| 2332 | } |
| 2333 | |
| 2334 | kname = (char *)kmem_get(len + 1); |
| 2335 | if (!kname) |
| 2336 | { |
| 2337 | return RT_NULL; |
| 2338 | } |
| 2339 | |
| 2340 | if (lwp_get_from_user(kname, (void *)name, len + 1) != (len + 1)) |
| 2341 | { |
| 2342 | kmem_put(kname); |
| 2343 | return RT_NULL; |
| 2344 | } |
| 2345 | |
| 2346 | mb = rt_mb_create(kname, size, flag); |
| 2347 | if (lwp_user_object_add(lwp_self(), (rt_object_t)mb) != 0) |
| 2348 | { |
| 2349 | rt_mb_delete(mb); |
| 2350 | mb = NULL; |
| 2351 | } |
| 2352 | |
| 2353 | kmem_put(kname); |
| 2354 | |
| 2355 | return mb; |
| 2356 | } |
| 2357 | |
| 2358 | /** |
| 2359 | * @brief Deletes a mailbox object. |
nothing calls this directly
no test coverage detected