Lines Matching +full:lock +full:- +full:mode
6 * SPDX-License-Identifier: Apache-2.0
23 struct k_spinlock lock; member
37 return (efd->flags & ZVFS_EFD_IN_USE) != 0; in zvfs_eventfd_is_in_use()
42 return (efd->flags & ZVFS_EFD_SEMAPHORE) != 0; in zvfs_eventfd_is_semaphore()
47 return (efd->flags & ZVFS_EFD_NONBLOCK) == 0; in zvfs_eventfd_is_blocking()
55 if (pfd->events & ZSOCK_POLLIN) { in zvfs_eventfd_poll_prepare()
58 return -1; in zvfs_eventfd_poll_prepare()
61 (*pev)->obj = &efd->read_sig; in zvfs_eventfd_poll_prepare()
62 (*pev)->type = K_POLL_TYPE_SIGNAL; in zvfs_eventfd_poll_prepare()
63 (*pev)->mode = K_POLL_MODE_NOTIFY_ONLY; in zvfs_eventfd_poll_prepare()
64 (*pev)->state = K_POLL_STATE_NOT_READY; in zvfs_eventfd_poll_prepare()
68 if (pfd->events & ZSOCK_POLLOUT) { in zvfs_eventfd_poll_prepare()
71 return -1; in zvfs_eventfd_poll_prepare()
74 (*pev)->obj = &efd->write_sig; in zvfs_eventfd_poll_prepare()
75 (*pev)->type = K_POLL_TYPE_SIGNAL; in zvfs_eventfd_poll_prepare()
76 (*pev)->mode = K_POLL_MODE_NOTIFY_ONLY; in zvfs_eventfd_poll_prepare()
77 (*pev)->state = K_POLL_STATE_NOT_READY; in zvfs_eventfd_poll_prepare()
88 if (pfd->events & ZSOCK_POLLIN) { in zvfs_eventfd_poll_update()
89 pfd->revents |= ZSOCK_POLLIN * (efd->cnt > 0); in zvfs_eventfd_poll_update()
93 if (pfd->events & ZSOCK_POLLOUT) { in zvfs_eventfd_poll_update()
94 pfd->revents |= ZSOCK_POLLOUT * (efd->cnt < UINT64_MAX - 1); in zvfs_eventfd_poll_update()
105 return -EBADF; in zvfs_eventfd_read_locked()
108 if (efd->cnt == 0) { in zvfs_eventfd_read_locked()
110 return -EAGAIN; in zvfs_eventfd_read_locked()
116 --efd->cnt; in zvfs_eventfd_read_locked()
118 *value = efd->cnt; in zvfs_eventfd_read_locked()
119 efd->cnt = 0; in zvfs_eventfd_read_locked()
122 if (efd->cnt == 0) { in zvfs_eventfd_read_locked()
123 k_poll_signal_reset(&efd->read_sig); in zvfs_eventfd_read_locked()
126 k_poll_signal_raise(&efd->write_sig, 0); in zvfs_eventfd_read_locked()
137 return -EBADF; in zvfs_eventfd_write_locked()
142 return -EINVAL; in zvfs_eventfd_write_locked()
145 if (u64_add_overflow(efd->cnt, *value, &result) || result == UINT64_MAX) { in zvfs_eventfd_write_locked()
147 return -EAGAIN; in zvfs_eventfd_write_locked()
151 efd->cnt = result; in zvfs_eventfd_write_locked()
153 if (efd->cnt == (UINT64_MAX - 1)) { in zvfs_eventfd_write_locked()
154 k_poll_signal_reset(&efd->write_sig); in zvfs_eventfd_write_locked()
157 k_poll_signal_raise(&efd->read_sig, 0); in zvfs_eventfd_write_locked()
177 struct k_mutex *lock = NULL; in zvfs_eventfd_close_op() local
184 return -1; in zvfs_eventfd_close_op()
187 err = (int)zvfs_get_obj_lock_and_cond(obj, &zvfs_eventfd_fd_vtable, &lock, &cond); in zvfs_eventfd_close_op()
189 __ASSERT_NO_MSG(lock != NULL); in zvfs_eventfd_close_op()
192 err = k_mutex_lock(lock, K_FOREVER); in zvfs_eventfd_close_op()
195 key = k_spin_lock(&efd->lock); in zvfs_eventfd_close_op()
199 ret = -1; in zvfs_eventfd_close_op()
203 err = sys_bitarray_free(&efds_bitarray, 1, (struct zvfs_eventfd *)obj - efds); in zvfs_eventfd_close_op()
206 efd->flags = 0; in zvfs_eventfd_close_op()
207 efd->cnt = 0; in zvfs_eventfd_close_op()
212 k_spin_unlock(&efd->lock, key); in zvfs_eventfd_close_op()
216 err = k_mutex_unlock(lock); in zvfs_eventfd_close_op()
229 key = k_spin_lock(&efd->lock); in zvfs_eventfd_ioctl_op()
233 ret = -1; in zvfs_eventfd_ioctl_op()
239 ret = efd->flags & ZVFS_EFD_FLAGS_SET; in zvfs_eventfd_ioctl_op()
249 ret = -1; in zvfs_eventfd_ioctl_op()
251 int prev_flags = efd->flags & ~ZVFS_EFD_FLAGS_SET; in zvfs_eventfd_ioctl_op()
253 efd->flags = flags | prev_flags; in zvfs_eventfd_ioctl_op()
282 ret = -1; in zvfs_eventfd_ioctl_op()
287 k_spin_unlock(&efd->lock, key); in zvfs_eventfd_ioctl_op()
307 struct k_mutex *lock = NULL; in zvfs_eventfd_rw_op() local
312 return -1; in zvfs_eventfd_rw_op()
317 return -1; in zvfs_eventfd_rw_op()
320 key = k_spin_lock(&efd->lock); in zvfs_eventfd_rw_op()
324 * Handle the non-blocking case entirely within this scope in zvfs_eventfd_rw_op()
328 errno = -ret; in zvfs_eventfd_rw_op()
329 ret = -1; in zvfs_eventfd_rw_op()
345 ret = -1; in zvfs_eventfd_rw_op()
349 err = (int)zvfs_get_obj_lock_and_cond(obj, &zvfs_eventfd_fd_vtable, &lock, &cond); in zvfs_eventfd_rw_op()
351 __ASSERT_NO_MSG(lock != NULL); in zvfs_eventfd_rw_op()
355 k_spin_unlock(&efd->lock, key); in zvfs_eventfd_rw_op()
356 err = k_mutex_lock(lock, K_FOREVER); in zvfs_eventfd_rw_op()
361 key = k_spin_lock(&efd->lock); in zvfs_eventfd_rw_op()
365 case -EAGAIN: in zvfs_eventfd_rw_op()
366 /* not an error in blocking mode. break and try again */ in zvfs_eventfd_rw_op()
375 errno = -ret; in zvfs_eventfd_rw_op()
376 ret = -1; in zvfs_eventfd_rw_op()
381 k_spin_unlock(&efd->lock, key); in zvfs_eventfd_rw_op()
384 err = k_condvar_wait(cond, lock, K_FOREVER); in zvfs_eventfd_rw_op()
389 k_spin_unlock(&efd->lock, key); in zvfs_eventfd_rw_op()
393 err = k_mutex_unlock(lock); in zvfs_eventfd_rw_op()
398 k_spin_unlock(&efd->lock, key); in zvfs_eventfd_rw_op()
405 * Public-facing API
416 return -1; in zvfs_eventfd()
421 return -1; in zvfs_eventfd()
429 return -1; in zvfs_eventfd()
432 efd->flags = ZVFS_EFD_IN_USE | flags; in zvfs_eventfd()
433 efd->cnt = initval; in zvfs_eventfd()
435 k_poll_signal_init(&efd->write_sig); in zvfs_eventfd()
436 k_poll_signal_init(&efd->read_sig); in zvfs_eventfd()
439 k_poll_signal_raise(&efd->read_sig, 0); in zvfs_eventfd()
442 k_poll_signal_raise(&efd->write_sig, 0); in zvfs_eventfd()
456 return -1; in zvfs_eventfd_read()
460 __ASSERT_NO_MSG(ret == -1 || ret == sizeof(zvfs_eventfd_t)); in zvfs_eventfd_read()
462 return -1; in zvfs_eventfd_read()
475 return -1; in zvfs_eventfd_write()
479 __ASSERT_NO_MSG(ret == -1 || ret == sizeof(zvfs_eventfd_t)); in zvfs_eventfd_write()
481 return -1; in zvfs_eventfd_write()