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

Function sys_mutex_create

components/lwp/lwp_syscall.c:1823–1860  ·  view source on GitHub ↗

* @brief Creates a mutex. * * This system call creates a new mutex with the specified `name` and initializes it * with the given `flag`. The mutex is used for synchronizing access to shared resources * between tasks. Mutexes are typically used to ensure that only one task can access * a critical section of code or a resource at a time. The `flag` parameter allows * for setting certain proper

Source from the content-addressed store, hash-verified

1821 * @see sys_mutex_delete(), sys_mutex_lock(), sys_mutex_unlock()
1822 */
1823rt_mutex_t sys_mutex_create(const char *name, rt_uint8_t flag)
1824{
1825 int len = 0;
1826 char *kname = RT_NULL;
1827 rt_mutex_t mutex = RT_NULL;
1828
1829 len = lwp_user_strlen(name);
1830 if (len <= 0)
1831 {
1832 return RT_NULL;
1833 }
1834
1835 kname = (char *)kmem_get(len + 1);
1836 if (!kname)
1837 {
1838 return RT_NULL;
1839 }
1840
1841 if (lwp_get_from_user(kname, (void *)name, len + 1) != (len + 1))
1842 {
1843 kmem_put(kname);
1844 return RT_NULL;
1845 }
1846
1847 mutex = rt_mutex_create(kname, flag);
1848 if(mutex == RT_NULL)
1849 return RT_NULL;
1850
1851 if (lwp_user_object_add(lwp_self(), (rt_object_t)mutex) != 0)
1852 {
1853 rt_mutex_delete(mutex);
1854 mutex = RT_NULL;
1855 }
1856
1857 kmem_put(kname);
1858
1859 return mutex;
1860}
1861
1862/**
1863 * @brief Deletes a mutex 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_mutex_createFunction · 0.85
lwp_user_object_addFunction · 0.85
lwp_selfFunction · 0.85
rt_mutex_deleteFunction · 0.85

Tested by

no test coverage detected