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

Function sys_sem_create

components/lwp/lwp_syscall.c:1681–1714  ·  view source on GitHub ↗

* @brief Creates a semaphore. * * This system call creates a new semaphore with the specified `name` and initializes * its value. The semaphore is used for synchronizing access to shared resources in * concurrent programming. The semaphore's behavior is defined by the value (`value`) * and any flags (`flag`) that specify additional properties or settings. * * @param name The name of the sem

Source from the content-addressed store, hash-verified

1679 * @see sem_wait(), sem_post(), sem_destroy()
1680 */
1681rt_sem_t sys_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag)
1682{
1683 int len = 0;
1684 char *kname = RT_NULL;
1685
1686 len = lwp_user_strlen(name);
1687 if (len <= 0)
1688 {
1689 return RT_NULL;
1690 }
1691
1692 kname = (char *)kmem_get(len + 1);
1693 if (!kname)
1694 {
1695 return RT_NULL;
1696 }
1697
1698 if (lwp_get_from_user(kname, (void *)name, len + 1) != (len + 1))
1699 {
1700 kmem_put(kname);
1701 return RT_NULL;
1702 }
1703
1704 rt_sem_t sem = rt_sem_create(kname, value, flag);
1705 if (lwp_user_object_add(lwp_self(), (rt_object_t)sem) != 0)
1706 {
1707 rt_sem_delete(sem);
1708 sem = NULL;
1709 }
1710
1711 kmem_put(kname);
1712
1713 return sem;
1714}
1715
1716/**
1717 * @brief Deletes a semaphore and releases associated resources.

Callers

nothing calls this directly

Calls 8

lwp_user_strlenFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
kmem_putFunction · 0.85
rt_sem_createFunction · 0.85
lwp_user_object_addFunction · 0.85
lwp_selfFunction · 0.85
rt_sem_deleteFunction · 0.85

Tested by

no test coverage detected