Lines Matching +full:has +full:- +full:lock
2 * Copyright (c) 2010-2016 Wind River Systems, Inc.
4 * SPDX-License-Identifier: Apache-2.0
32 /* We use a system-wide lock to synchronize semaphores, which has
33 * unfortunate performance impact vs. using a per-object lock
34 * (semaphores are *very* widely used). But per-object locks require
35 * significant extra RAM. A properly spin-aware semaphore
39 static struct k_spinlock lock; variable
52 SYS_PORT_TRACING_OBJ_FUNC(k_sem, init, sem, -EINVAL); in z_impl_k_sem_init()
54 return -EINVAL; in z_impl_k_sem_init()
57 sem->count = initial_count; in z_impl_k_sem_init()
58 sem->limit = limit; in z_impl_k_sem_init()
62 z_waitq_init(&sem->wait_q); in z_impl_k_sem_init()
64 sys_dlist_init(&sem->poll_events); in z_impl_k_sem_init()
88 z_handle_obj_poll_events(&sem->poll_events, K_POLL_STATE_SEM_AVAILABLE); in handle_poll_events()
98 k_spinlock_key_t key = k_spin_lock(&lock); in z_impl_k_sem_give()
104 thread = z_unpend_first_thread(&sem->wait_q); in z_impl_k_sem_give()
110 sem->count += (sem->count != sem->limit) ? 1U : 0U; in z_impl_k_sem_give()
115 z_reschedule(&lock, key); in z_impl_k_sem_give()
117 k_spin_unlock(&lock, key); in z_impl_k_sem_give()
139 k_spinlock_key_t key = k_spin_lock(&lock); in z_impl_k_sem_take()
143 if (likely(sem->count > 0U)) { in z_impl_k_sem_take()
144 sem->count--; in z_impl_k_sem_take()
145 k_spin_unlock(&lock, key); in z_impl_k_sem_take()
151 k_spin_unlock(&lock, key); in z_impl_k_sem_take()
152 ret = -EBUSY; in z_impl_k_sem_take()
158 ret = z_pend_curr(&lock, key, &sem->wait_q, timeout); in z_impl_k_sem_take()
169 k_spinlock_key_t key = k_spin_lock(&lock); in z_impl_k_sem_reset()
172 thread = z_unpend_first_thread(&sem->wait_q); in z_impl_k_sem_reset()
176 arch_thread_return_value_set(thread, -EAGAIN); in z_impl_k_sem_reset()
179 sem->count = 0; in z_impl_k_sem_reset()
185 z_reschedule(&lock, key); in z_impl_k_sem_reset()