/Zephyr-latest/kernel/ |
D | mutex.c | 8 * @file @brief mutex kernel services 10 * This module contains routines for handling mutex locking and unlocking. 14 * priority thread waiting on the mutex. 16 * Each mutex that contributes to priority inheritance must be released in the 17 * reverse order in which it was acquired. Furthermore each subsequent mutex 22 * priority level, the second mutex M2 must be acquired by thread A after 23 * thread A's priority level was bumped due to owning the first mutex M1. 24 * When releasing the mutex, thread A must release M2 before it releases M1. 55 int z_impl_k_mutex_init(struct k_mutex *mutex) in z_impl_k_mutex_init() argument 57 mutex->owner = NULL; in z_impl_k_mutex_init() [all …]
|
/Zephyr-latest/include/zephyr/sys/ |
D | mutex.h | 37 * @defgroup user_mutex_apis User mode mutex APIs 45 * The mutex can be accessed outside the module where it is defined using: 51 * @param name Name of the mutex. 57 * @brief Initialize a mutex. 59 * This routine initializes a mutex object, prior to its first use. 61 * Upon completion, the mutex is available and does not have an owner. 64 * and the mutex was not created with SYS_MUTEX_DEFINE(). 66 * @param mutex Address of the mutex. 68 static inline void sys_mutex_init(struct sys_mutex *mutex) in sys_mutex_init() argument 70 ARG_UNUSED(mutex); in sys_mutex_init() [all …]
|
/Zephyr-latest/tests/posix/common/src/ |
D | mutex.c | 15 static pthread_mutex_t mutex; variable 24 rc = pthread_mutex_trylock(&mutex); in normal_mutex_entry() 32 TC_PRINT("mutex lock is taken\n"); in normal_mutex_entry() 33 zassert_false(pthread_mutex_unlock(&mutex), "mutex unlock is failed"); in normal_mutex_entry() 39 zassert_false(pthread_mutex_lock(&mutex), "mutex is not taken"); in recursive_mutex_entry() 40 zassert_false(pthread_mutex_lock(&mutex), "mutex is not taken 2nd time"); in recursive_mutex_entry() 41 TC_PRINT("recursive mutex lock is taken\n"); in recursive_mutex_entry() 42 zassert_false(pthread_mutex_unlock(&mutex), "mutex is not unlocked"); in recursive_mutex_entry() 43 zassert_false(pthread_mutex_unlock(&mutex), "mutex is not unlocked"); in recursive_mutex_entry() 58 zassert_ok(pthread_mutexattr_settype(&mut_attr, type), "setting mutex type is failed"); in test_mutex_common() [all …]
|
/Zephyr-latest/subsys/portability/cmsis_rtos_v2/ |
D | mutex.c | 22 * @brief Create and Initialize a Mutex object. 26 struct cv2_mutex *mutex; in osMutexNew() local 42 if (k_mem_slab_alloc(&cv2_mutex_slab, (void **)&mutex, K_MSEC(100)) == 0) { in osMutexNew() 43 memset(mutex, 0, sizeof(struct cv2_mutex)); in osMutexNew() 48 k_mutex_init(&mutex->z_mutex); in osMutexNew() 49 mutex->state = attr->attr_bits; in osMutexNew() 52 strncpy(mutex->name, init_mutex_attrs.name, in osMutexNew() 53 sizeof(mutex->name) - 1); in osMutexNew() 55 strncpy(mutex->name, attr->name, sizeof(mutex->name) - 1); in osMutexNew() 58 return (osMutexId_t)mutex; in osMutexNew() [all …]
|
/Zephyr-latest/doc/kernel/services/synchronization/ |
D | mutexes.rst | 6 A :dfn:`mutex` is a kernel object that implements a traditional 7 reentrant mutex. A mutex allows multiple threads to safely share 18 Any number of mutexes can be defined (limited only by available RAM). Each mutex 21 A mutex has the following key properties: 23 * A **lock count** that indicates the number of times the mutex has been locked 24 by the thread that has locked it. A count of zero indicates that the mutex 27 * An **owning thread** that identifies the thread that has locked the mutex, 30 A mutex must be initialized before it can be used. This sets its lock count 34 to access it by **locking** the associated mutex. If the mutex is already locked 35 by another thread, the requesting thread may choose to wait for the mutex [all …]
|
/Zephyr-latest/samples/kernel/condition_variables/condvar/ |
D | README.rst | 11 multithreaded application. Condition variables are used with a mutex 41 inc_count: thread 2, count = 1, unlocking mutex 42 inc_count: thread 3, count = 2, unlocking mutex 43 inc_count: thread 2, count = 3, unlocking mutex 44 inc_count: thread 3, count = 4, unlocking mutex 45 inc_count: thread 2, count = 5, unlocking mutex 46 inc_count: thread 3, count = 6, unlocking mutex 47 inc_count: thread 2, count = 7, unlocking mutex 48 inc_count: thread 3, count = 8, unlocking mutex 49 inc_count: thread 2, count = 9, unlocking mutex [all …]
|
/Zephyr-latest/subsys/portability/cmsis_rtos_v1/ |
D | cmsis_mutex.c | 15 * @brief Create and Initialize a Mutex object. 19 struct k_mutex *mutex; in osMutexCreate() local 29 if (k_mem_slab_alloc(&cmsis_mutex_slab, (void **)&mutex, K_MSEC(100)) == 0) { in osMutexCreate() 30 (void)memset(mutex, 0, sizeof(struct k_mutex)); in osMutexCreate() 35 k_mutex_init(mutex); in osMutexCreate() 37 return (osMutexId)mutex; in osMutexCreate() 41 * @brief Wait until a Mutex becomes available. 45 struct k_mutex *mutex = (struct k_mutex *) mutex_id; in osMutexWait() local 57 status = k_mutex_lock(mutex, K_FOREVER); in osMutexWait() 59 status = k_mutex_lock(mutex, K_NO_WAIT); in osMutexWait() [all …]
|
/Zephyr-latest/lib/os/ |
D | mutex.c | 8 #include <zephyr/sys/mutex.h> 12 static struct k_mutex *get_k_mutex(struct sys_mutex *mutex) in get_k_mutex() argument 16 obj = k_object_find(mutex); in get_k_mutex() 21 return obj->data.mutex; in get_k_mutex() 33 int z_impl_z_sys_mutex_kernel_lock(struct sys_mutex *mutex, k_timeout_t timeout) in z_impl_z_sys_mutex_kernel_lock() argument 35 struct k_mutex *kernel_mutex = get_k_mutex(mutex); in z_impl_z_sys_mutex_kernel_lock() 44 static inline int z_vrfy_z_sys_mutex_kernel_lock(struct sys_mutex *mutex, in z_vrfy_z_sys_mutex_kernel_lock() argument 47 if (check_sys_mutex_addr(mutex)) { in z_vrfy_z_sys_mutex_kernel_lock() 51 return z_impl_z_sys_mutex_kernel_lock(mutex, timeout); in z_vrfy_z_sys_mutex_kernel_lock() 55 int z_impl_z_sys_mutex_kernel_unlock(struct sys_mutex *mutex) in z_impl_z_sys_mutex_kernel_unlock() argument [all …]
|
/Zephyr-latest/modules/fatfs/ |
D | zfs_ffsystem.c | 32 /* Table of Zephyr mutex. One for each volume and an extra one for the ff system. 37 /* Create a Mutex 38 * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) 39 * Returns 1: Succeeded or 0: Could not create the mutex 46 /* Delete a Mutex 47 * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) 56 * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) 65 * Mutex ID vol: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES)
|
/Zephyr-latest/tests/subsys/portability/cmsis_rtos_v1/src/ |
D | mutex.c | 26 zassert_true(status == osOK, "Mutex delete fail"); in cleanup_max_mutex() 35 /* Try mutex creation for more than maximum count */ in test_max_mutex() 40 "Mutex creation pass unexpectedly after max count"); in test_max_mutex() 44 "Multiple mutex creation failed before max count"); in test_max_mutex() 54 /* Try deleting invalid mutex object */ in ZTEST() 57 "Invalid Mutex deleted unexpectedly!"); in ZTEST() 62 /* Try to release mutex without obtaining it */ in ZTEST() 64 zassert_true(status == osErrorResource, "Mutex released unexpectedly!"); in ZTEST() 67 zassert_true(status == osOK, "Mutex wait failure"); in ZTEST() 69 /* Try to acquire an already acquired mutex */ in ZTEST() [all …]
|
/Zephyr-latest/tests/subsys/portability/cmsis_rtos_v2/src/ |
D | mutex.c | 30 zassert_true(status == osOK, "Mutex delete fail"); in cleanup_max_mutex() 39 /* Try mutex creation for more than maximum count */ in test_max_mutex() 44 "Mutex creation pass unexpectedly after max count"); in test_max_mutex() 48 "Multiple mutex creation failed before max count"); in test_max_mutex() 60 /* Try deleting invalid mutex object */ in ZTEST() 63 "Invalid Mutex deleted unexpectedly!"); in ZTEST() 69 zassert_str_equal(mutex_attr.name, name, "Error getting Mutex name"); in ZTEST() 71 /* Try to release mutex without obtaining it */ in ZTEST() 73 zassert_true(status == osErrorResource, "Mutex released unexpectedly!"); in ZTEST() 75 /* Try figuring out the owner for a Mutex which has not been in ZTEST() [all …]
|
/Zephyr-latest/tests/kernel/mutex/sys_mutex/src/ |
D | thread_competition.c | 11 #include <zephyr/sys/mutex.h> 25 SYS_MUTEX_DEFINE(mutex); 28 /* The order of threads getting mutex is judged by index 42 /* Keep mutex for a while */ in low_prio_wait_for_mutex() 57 /* Keep mutex for a while */ in high_prio_t1_wait_for_mutex() 72 /* Keep mutex for a while */ in high_prio_t2_wait_for_mutex() 79 * @brief Test multi-threads to take mutex. 85 * 1. Any number of threads may wait on a mutex locked by others 87 * 2. When the mutex is released, it is took by the highest priority 99 sys_mutex_lock(&mutex, K_NO_WAIT); in ZTEST() [all …]
|
D | thread_12.c | 1 /* thread_12.c - helper file for testing kernel mutex APIs */ 11 * @brief mutex test helper 13 * This module defines a thread that is used in recursive mutex locking tests. 14 * It helps ensure that a private mutex can be referenced in a file other than 20 #include <zephyr/sys/mutex.h> 40 /* Wait for private mutex to be released */ in thread_12() 45 TC_ERROR("Failed to obtain private mutex\n"); in thread_12() 49 /* Wait a bit, then release the mutex */ in thread_12()
|
/Zephyr-latest/lib/libc/common/source/thrd/ |
D | mtx.c | 13 int mtx_init(mtx_t *mutex, int type) in mtx_init() argument 36 switch (pthread_mutex_init(mutex, attrp)) { in mtx_init() 52 void mtx_destroy(mtx_t *mutex) in mtx_destroy() argument 54 (void)pthread_mutex_destroy(mutex); in mtx_destroy() 57 int mtx_lock(mtx_t *mutex) in mtx_lock() argument 59 switch (pthread_mutex_lock(mutex)) { in mtx_lock() 67 int mtx_timedlock(mtx_t *restrict mutex, const struct timespec *restrict time_point) in mtx_timedlock() argument 69 switch (pthread_mutex_timedlock(mutex, time_point)) { in mtx_timedlock() 79 int mtx_trylock(mtx_t *mutex) in mtx_trylock() argument 81 switch (pthread_mutex_trylock(mutex)) { in mtx_trylock() [all …]
|
/Zephyr-latest/tests/lib/c_lib/thrd/src/ |
D | mtx.c | 22 static mtx_t mutex; variable 28 zassert_not_equal(thrd_success, mtx_init(&mutex, FORTY_TWO)); in ZTEST() 39 zassert_equal(thrd_success, mtx_init(&mutex, type)); in ZTEST() 40 mtx_destroy(&mutex); in ZTEST() 53 zassert_equal(thrd_success, mtx_init(&mutex, mtx_plain)); in ZTEST() 54 mtx_destroy(&mutex); in ZTEST() 65 /* test plain mutex */ in ZTEST() 69 zassert_equal(thrd_success, mtx_init(&mutex, type)); in ZTEST() 70 zassert_equal(thrd_success, mtx_lock(&mutex)); in ZTEST() 74 zassert_not_equal(thrd_success, mtx_lock((&mutex))); in ZTEST() [all …]
|
/Zephyr-latest/modules/thrift/src/thrift/concurrency/ |
D | Mutex.cpp | 9 #include <thrift/concurrency/Mutex.h> 18 class Mutex::impl 25 Mutex::Mutex() in Mutex() function in apache::thrift::concurrency::Mutex 27 impl_ = std::make_shared<Mutex::impl>(); in Mutex() 30 void Mutex::lock() const in lock() 37 bool Mutex::trylock() const in trylock() 42 bool Mutex::timedlock(int64_t milliseconds) const in timedlock() 56 void Mutex::unlock() const in unlock() 61 void *Mutex::getUnderlyingImpl() const in getUnderlyingImpl()
|
/Zephyr-latest/tests/kernel/mutex/mutex_api/src/ |
D | test_mutex_apis.c | 84 /**TESTPOINT: test k_mutex_init mutex*/ in tmutex_test_lock_timeout() 118 /* t1 will get mutex first */ in tThread_T1_priority_inheritance() 145 /* wait for t2 timeout to get mutex*/ in tThread_T1_priority_inheritance() 153 /* wait for t2 timeout to get mutex*/ in tThread_T1_priority_inheritance() 189 /* This thread will hold mutex for 600 ms, then release it */ in tThread_lock_with_time_period() 201 /* Wait for mutex to be released */ in tThread_waiter() 213 /**TESTPOINT: test k_mutex_init mutex*/ in ZTEST_USER() 218 /**TESTPOINT: test K_MUTEX_DEFINE mutex*/ in ZTEST_USER() 225 /**TESTPOINT: test k_mutex_init mutex*/ in ZTEST_USER() 228 /**TESTPOINT: test K_MUTEX_DEFINE mutex*/ in ZTEST_USER() [all …]
|
/Zephyr-latest/modules/lvgl/ |
D | lvgl_zephyr_osal.c | 49 lv_result_t lv_mutex_init(lv_mutex_t *mutex) in lv_mutex_init() argument 51 k_mutex_init(mutex); in lv_mutex_init() 55 lv_result_t lv_mutex_lock(lv_mutex_t *mutex) in lv_mutex_lock() argument 59 ret = k_mutex_lock(mutex, K_FOREVER); in lv_mutex_lock() 61 LOG_ERR("Failed to lock mutex: %d", ret); in lv_mutex_lock() 68 lv_result_t lv_mutex_lock_isr(lv_mutex_t *mutex) in lv_mutex_lock_isr() argument 72 ret = k_mutex_lock(mutex, K_NO_WAIT); in lv_mutex_lock_isr() 74 LOG_ERR("Failed to lock mutex: %d", ret); in lv_mutex_lock_isr() 81 lv_result_t lv_mutex_unlock(lv_mutex_t *mutex) in lv_mutex_unlock() argument 85 ret = k_mutex_unlock(mutex); in lv_mutex_unlock() [all …]
|
/Zephyr-latest/tests/benchmarks/latency_measure/src/ |
D | mutex_lock_unlock.c | 9 * @file measure time for mutex lock and unlock 11 * This file contains the test that measures mutex lock and unlock times 12 * in the kernel. There is no contention on the mutex being tested. 36 /* Recursively lock take the mutex */ in start_lock_unlock() 48 /* Recursively unlock the mutex */ in start_lock_unlock() 67 * @brief Test for the multiple mutex lock/unlock time 69 * The routine performs multiple mutex locks and then multiple mutex 98 "mutex.lock.immediate.recursive.%s", in mutex_lock_unlock() 101 "%-40s - Lock a mutex", tag); in mutex_lock_unlock() 108 "mutex.unlock.immediate.recursive.%s", in mutex_lock_unlock() [all …]
|
/Zephyr-latest/lib/posix/options/ |
D | mutex.c | 26 * Default mutex attrs. 59 /* if the provided mutex does not claim to be initialized, its invalid */ in get_posix_mutex() 61 LOG_DBG("Mutex is uninitialized (%x)", mu); in get_posix_mutex() 67 LOG_DBG("Mutex is invalid (%x)", mu); in get_posix_mutex() 72 /* The mutex claims to be initialized but is actually not */ in get_posix_mutex() 73 LOG_DBG("Mutex claims to be initialized (%x)", mu); in get_posix_mutex() 124 LOG_DBG("Locking mutex %p with timeout %llx", m, timeout.ticks); in acquire_mutex() 141 LOG_DBG("Timeout locking mutex %p", m); in acquire_mutex() 146 LOG_DBG("Attempt to relock non-recursive mutex %p", m); in acquire_mutex() 154 LOG_DBG("Mutex %p locked recursively too many times", m); in acquire_mutex() [all …]
|
/Zephyr-latest/tests/kernel/mutex/sys_mutex/ |
D | testcase.yaml | 2 kernel.mutex.system: 9 - mutex 10 kernel.mutex.system.nouser: 13 - mutex
|
/Zephyr-latest/subsys/net/lib/mqtt/ |
D | mqtt_os.h | 12 * @details Memory management, mutex, logging and wall clock are the needed 23 #include <zephyr/sys/mutex.h> 33 /**@brief Initialize the mutex for the module, if any. 39 sys_mutex_init(&client->internal.mutex); in mqtt_mutex_init() 42 /**@brief Acquire lock on the module specific mutex, if any. 45 * of the mutex succeeds. 49 int ret = sys_mutex_lock(&client->internal.mutex, K_FOREVER); in mqtt_mutex_lock() 55 /**@brief Release the lock on the module specific mutex, if any. 59 int ret = sys_mutex_unlock(&client->internal.mutex); in mqtt_mutex_unlock()
|
/Zephyr-latest/samples/arch/smp/pktqueue/src/ |
D | pktqueue.c | 11 struct k_mutex *mutex) in phdr_desc_enqueue() argument 14 k_mutex_lock(mutex, K_FOREVER); in phdr_desc_enqueue() 26 k_mutex_unlock(mutex); in phdr_desc_enqueue() 31 struct k_mutex *mutex) in phdr_desc_dequeue() argument 35 k_mutex_lock(mutex, K_FOREVER); in phdr_desc_dequeue() 43 k_mutex_unlock(mutex); in phdr_desc_dequeue()
|
/Zephyr-latest/lib/libc/arcmwdt/ |
D | threading.c | 13 #include <zephyr/sys/mutex.h> 56 void _mwmutex_lock(_lock_t mutex) in _mwmutex_lock() argument 58 __ASSERT_NO_MSG(mutex != NULL); in _mwmutex_lock() 59 k_mutex_lock((struct k_mutex *)mutex, K_FOREVER); in _mwmutex_lock() 62 void _mwmutex_unlock(_lock_t mutex) in _mwmutex_unlock() argument 64 __ASSERT_NO_MSG(mutex != NULL); in _mwmutex_unlock() 65 k_mutex_unlock((struct k_mutex *)mutex); in _mwmutex_unlock()
|
/Zephyr-latest/subsys/usb/host/ |
D | usbh_api.c | 18 k_mutex_lock(&uhs_ctx->mutex, K_FOREVER); in usbh_init() 35 k_mutex_unlock(&uhs_ctx->mutex); in usbh_init() 43 k_mutex_lock(&uhs_ctx->mutex, K_FOREVER); in usbh_enable() 64 k_mutex_unlock(&uhs_ctx->mutex); in usbh_enable() 77 k_mutex_lock(&uhs_ctx->mutex, K_FOREVER); in usbh_disable() 84 k_mutex_unlock(&uhs_ctx->mutex); in usbh_disable() 93 k_mutex_lock(&uhs_ctx->mutex, K_FOREVER); in usbh_shutdown() 100 k_mutex_unlock(&uhs_ctx->mutex); in usbh_shutdown()
|