Lines Matching +full:key +full:- +full:int
5 * SPDX-License-Identifier: Apache-2.0
29 /* Single subsystem lock. Locking per-event would be better on highly
40 static int signal_poller(struct k_poll_event *event, uint32_t state);
41 static int signal_triggered_work(struct k_poll_event *event, uint32_t status);
44 int mode, void *obj) in k_poll_event_init()
51 event->poller = NULL; in k_poll_event_init()
52 /* event->tag is left uninitialized: the user will set it if needed */ in k_poll_event_init()
53 event->type = type; in k_poll_event_init()
54 event->state = K_POLL_STATE_NOT_READY; in k_poll_event_init()
55 event->mode = mode; in k_poll_event_init()
56 event->unused = 0U; in k_poll_event_init()
57 event->obj = obj; in k_poll_event_init()
65 switch (event->type) { in is_condition_met()
67 if (k_sem_count_get(event->sem) > 0U) { in is_condition_met()
73 if (!k_queue_is_empty(event->queue)) { in is_condition_met()
79 if (event->signal->signaled != 0U) { in is_condition_met()
85 if (event->msgq->used_msgs > 0) { in is_condition_met()
92 if (k_pipe_read_avail(event->pipe)) { in is_condition_met()
100 __ASSERT(false, "invalid event type (0x%x)\n", event->type); in is_condition_met()
119 (z_sched_prio_cmp(poller_thread(pending->poller), in add_event()
121 sys_dlist_append(events, &event->_node); in add_event()
127 poller_thread(pending->poller)) > 0) { in add_event()
128 sys_dlist_insert(&pending->_node, &event->_node); in add_event()
133 sys_dlist_append(events, &event->_node); in add_event()
140 switch (event->type) { in register_event()
142 __ASSERT(event->sem != NULL, "invalid semaphore\n"); in register_event()
143 add_event(&event->sem->poll_events, event, poller); in register_event()
146 __ASSERT(event->queue != NULL, "invalid queue\n"); in register_event()
147 add_event(&event->queue->poll_events, event, poller); in register_event()
150 __ASSERT(event->signal != NULL, "invalid poll signal\n"); in register_event()
151 add_event(&event->signal->poll_events, event, poller); in register_event()
154 __ASSERT(event->msgq != NULL, "invalid message queue\n"); in register_event()
155 add_event(&event->msgq->poll_events, event, poller); in register_event()
159 __ASSERT(event->pipe != NULL, "invalid pipe\n"); in register_event()
160 add_event(&event->pipe->poll_events, event, poller); in register_event()
171 event->poller = poller; in register_event()
179 event->poller = NULL; in clear_event_registration()
181 switch (event->type) { in clear_event_registration()
183 __ASSERT(event->sem != NULL, "invalid semaphore\n"); in clear_event_registration()
187 __ASSERT(event->queue != NULL, "invalid queue\n"); in clear_event_registration()
191 __ASSERT(event->signal != NULL, "invalid poll signal\n"); in clear_event_registration()
195 __ASSERT(event->msgq != NULL, "invalid message queue\n"); in clear_event_registration()
200 __ASSERT(event->pipe != NULL, "invalid pipe\n"); in clear_event_registration()
211 if (remove_event && sys_dnode_is_linked(&event->_node)) { in clear_event_registration()
212 sys_dlist_remove(&event->_node); in clear_event_registration()
218 int num_events, in clear_event_registrations()
219 k_spinlock_key_t key) in clear_event_registrations() argument
221 while (num_events--) { in clear_event_registrations()
223 k_spin_unlock(&lock, key); in clear_event_registrations()
224 key = k_spin_lock(&lock); in clear_event_registrations()
230 event->poller = NULL; in set_event_ready()
231 event->state |= state; in set_event_ready()
234 static inline int register_events(struct k_poll_event *events, in register_events()
235 int num_events, in register_events()
239 int events_registered = 0; in register_events()
241 for (int ii = 0; ii < num_events; ii++) { in register_events()
242 k_spinlock_key_t key; in register_events() local
245 key = k_spin_lock(&lock); in register_events()
248 poller->is_polling = false; in register_events()
249 } else if (!just_check && poller->is_polling) { in register_events()
254 * catching non-polling events, or is marked for just check, in register_events()
259 k_spin_unlock(&lock, key); in register_events()
265 static int signal_poller(struct k_poll_event *event, uint32_t state) in signal_poller()
267 struct k_thread *thread = poller_thread(event->poller); in signal_poller()
277 state == K_POLL_STATE_CANCELLED ? -EINTR : 0); in signal_poller()
288 int z_impl_k_poll(struct k_poll_event *events, int num_events, in z_impl_k_poll()
291 int events_registered; in z_impl_k_poll()
292 k_spinlock_key_t key; in z_impl_k_poll() local
293 struct z_poller *poller = &arch_current_thread()->poller; in z_impl_k_poll()
295 poller->is_polling = true; in z_impl_k_poll()
296 poller->mode = MODE_POLL; in z_impl_k_poll()
307 key = k_spin_lock(&lock); in z_impl_k_poll()
314 if (!poller->is_polling) { in z_impl_k_poll()
315 clear_event_registrations(events, events_registered, key); in z_impl_k_poll()
316 k_spin_unlock(&lock, key); in z_impl_k_poll()
323 poller->is_polling = false; in z_impl_k_poll()
326 k_spin_unlock(&lock, key); in z_impl_k_poll()
328 SYS_PORT_TRACING_FUNC_EXIT(k_poll_api, poll, events, -EAGAIN); in z_impl_k_poll()
330 return -EAGAIN; in z_impl_k_poll()
335 int swap_rc = z_pend_curr(&lock, key, &wait_q, timeout); in z_impl_k_poll()
342 * we've already know the return code (-EAGAIN), and even if they are in z_impl_k_poll()
346 key = k_spin_lock(&lock); in z_impl_k_poll()
347 clear_event_registrations(events, events_registered, key); in z_impl_k_poll()
348 k_spin_unlock(&lock, key); in z_impl_k_poll()
356 static inline int z_vrfy_k_poll(struct k_poll_event *events, in z_vrfy_k_poll()
357 int num_events, k_timeout_t timeout) in z_vrfy_k_poll()
359 int ret; in z_vrfy_k_poll()
360 k_spinlock_key_t key; in z_vrfy_k_poll() local
365 * allocated kernel-side buffer. in z_vrfy_k_poll()
368 ret = -EINVAL; in z_vrfy_k_poll()
375 ret = -EINVAL; in z_vrfy_k_poll()
380 ret = -ENOMEM; in z_vrfy_k_poll()
384 key = k_spin_lock(&lock); in z_vrfy_k_poll()
386 k_spin_unlock(&lock, key); in z_vrfy_k_poll()
390 k_spin_unlock(&lock, key); in z_vrfy_k_poll()
393 for (int i = 0; i < num_events; i++) { in z_vrfy_k_poll()
396 if (K_SYSCALL_VERIFY(e->mode == K_POLL_MODE_NOTIFY_ONLY)) { in z_vrfy_k_poll()
397 ret = -EINVAL; in z_vrfy_k_poll()
401 switch (e->type) { in z_vrfy_k_poll()
405 K_OOPS(K_SYSCALL_OBJ(e->signal, K_OBJ_POLL_SIGNAL)); in z_vrfy_k_poll()
408 K_OOPS(K_SYSCALL_OBJ(e->sem, K_OBJ_SEM)); in z_vrfy_k_poll()
411 K_OOPS(K_SYSCALL_OBJ(e->queue, K_OBJ_QUEUE)); in z_vrfy_k_poll()
414 K_OOPS(K_SYSCALL_OBJ(e->msgq, K_OBJ_MSGQ)); in z_vrfy_k_poll()
418 K_OOPS(K_SYSCALL_OBJ(e->pipe, K_OBJ_PIPE)); in z_vrfy_k_poll()
422 ret = -EINVAL; in z_vrfy_k_poll()
441 static int signal_poll_event(struct k_poll_event *event, uint32_t state) in signal_poll_event()
443 struct z_poller *poller = event->poller; in signal_poll_event()
444 int retcode = 0; in signal_poll_event()
447 if (poller->mode == MODE_POLL) { in signal_poll_event()
449 } else if (poller->mode == MODE_TRIGGERED) { in signal_poll_event()
456 poller->is_polling = false; in signal_poll_event()
470 k_spinlock_key_t key = k_spin_lock(&lock); in z_handle_obj_poll_events() local
477 k_spin_unlock(&lock, key); in z_handle_obj_poll_events()
482 sys_dlist_init(&sig->poll_events); in z_impl_k_poll_signal_init()
483 sig->signaled = 0U; in z_impl_k_poll_signal_init()
484 /* signal->result is left uninitialized */ in z_impl_k_poll_signal_init()
501 sig->signaled = 0U; in z_impl_k_poll_signal_reset()
507 unsigned int *signaled, int *result) in z_impl_k_poll_signal_check()
509 *signaled = sig->signaled; in z_impl_k_poll_signal_check()
510 *result = sig->result; in z_impl_k_poll_signal_check()
517 unsigned int *signaled, int *result) in z_vrfy_k_poll_signal_check()
520 K_OOPS(K_SYSCALL_MEMORY_WRITE(signaled, sizeof(unsigned int))); in z_vrfy_k_poll_signal_check()
521 K_OOPS(K_SYSCALL_MEMORY_WRITE(result, sizeof(int))); in z_vrfy_k_poll_signal_check()
527 int z_impl_k_poll_signal_raise(struct k_poll_signal *sig, int result) in z_impl_k_poll_signal_raise()
529 k_spinlock_key_t key = k_spin_lock(&lock); in z_impl_k_poll_signal_raise() local
532 sig->result = result; in z_impl_k_poll_signal_raise()
533 sig->signaled = 1U; in z_impl_k_poll_signal_raise()
535 poll_event = (struct k_poll_event *)sys_dlist_get(&sig->poll_events); in z_impl_k_poll_signal_raise()
537 k_spin_unlock(&lock, key); in z_impl_k_poll_signal_raise()
544 int rc = signal_poll_event(poll_event, K_POLL_STATE_SIGNALED); in z_impl_k_poll_signal_raise()
548 z_reschedule(&lock, key); in z_impl_k_poll_signal_raise()
553 static inline int z_vrfy_k_poll_signal_raise(struct k_poll_signal *sig, in z_vrfy_k_poll_signal_raise()
554 int result) in z_vrfy_k_poll_signal_raise()
579 if (twork->poller.mode != MODE_NONE) { in triggered_work_handler()
580 k_spinlock_key_t key; in triggered_work_handler() local
582 key = k_spin_lock(&lock); in triggered_work_handler()
583 clear_event_registrations(twork->events, in triggered_work_handler()
584 twork->num_events, key); in triggered_work_handler()
585 k_spin_unlock(&lock, key); in triggered_work_handler()
589 twork->workq = NULL; in triggered_work_handler()
590 twork->real_handler(work); in triggered_work_handler()
598 twork->poller.is_polling = false; in triggered_work_expiration_handler()
599 twork->poll_result = -EAGAIN; in triggered_work_expiration_handler()
600 k_work_submit_to_queue(twork->workq, &twork->work); in triggered_work_expiration_handler()
603 extern int z_work_submit_to_queue(struct k_work_q *queue,
606 static int signal_triggered_work(struct k_poll_event *event, uint32_t status) in signal_triggered_work()
608 struct z_poller *poller = event->poller; in signal_triggered_work()
612 if (poller->is_polling && twork->workq != NULL) { in signal_triggered_work()
613 struct k_work_q *work_q = twork->workq; in signal_triggered_work()
615 z_abort_timeout(&twork->timeout); in signal_triggered_work()
616 twork->poll_result = 0; in signal_triggered_work()
617 z_work_submit_to_queue(work_q, &twork->work); in signal_triggered_work()
623 static int triggered_work_cancel(struct k_work_poll *work, in triggered_work_cancel()
624 k_spinlock_key_t key) in triggered_work_cancel() argument
627 if (work->poller.is_polling && work->poller.mode != MODE_NONE) { in triggered_work_cancel()
629 z_abort_timeout(&work->timeout); in triggered_work_cancel()
635 work->poller.mode = MODE_NONE; in triggered_work_cancel()
638 clear_event_registrations(work->events, work->num_events, key); in triggered_work_cancel()
639 work->workq = NULL; in triggered_work_cancel()
650 return -EINVAL; in triggered_work_cancel()
659 k_work_init(&work->work, triggered_work_handler); in k_work_poll_init()
660 work->real_handler = handler; in k_work_poll_init()
661 z_init_timeout(&work->timeout); in k_work_poll_init()
666 int k_work_poll_submit_to_queue(struct k_work_q *work_q, in k_work_poll_submit_to_queue()
669 int num_events, in k_work_poll_submit_to_queue()
672 int events_registered; in k_work_poll_submit_to_queue()
673 k_spinlock_key_t key; in k_work_poll_submit_to_queue() local
683 key = k_spin_lock(&lock); in k_work_poll_submit_to_queue()
684 if (work->workq != NULL) { in k_work_poll_submit_to_queue()
685 if (work->workq == work_q) { in k_work_poll_submit_to_queue()
686 int retval; in k_work_poll_submit_to_queue()
688 retval = triggered_work_cancel(work, key); in k_work_poll_submit_to_queue()
690 k_spin_unlock(&lock, key); in k_work_poll_submit_to_queue()
698 k_spin_unlock(&lock, key); in k_work_poll_submit_to_queue()
701 work, timeout, -EADDRINUSE); in k_work_poll_submit_to_queue()
703 return -EADDRINUSE; in k_work_poll_submit_to_queue()
708 work->poller.is_polling = true; in k_work_poll_submit_to_queue()
709 work->workq = work_q; in k_work_poll_submit_to_queue()
710 work->poller.mode = MODE_NONE; in k_work_poll_submit_to_queue()
711 k_spin_unlock(&lock, key); in k_work_poll_submit_to_queue()
714 work->events = events; in k_work_poll_submit_to_queue()
715 work->num_events = num_events; in k_work_poll_submit_to_queue()
718 work->poll_result = -EINPROGRESS; in k_work_poll_submit_to_queue()
722 &work->poller, false); in k_work_poll_submit_to_queue()
724 key = k_spin_lock(&lock); in k_work_poll_submit_to_queue()
725 if (work->poller.is_polling && !K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { in k_work_poll_submit_to_queue()
735 z_add_timeout(&work->timeout, in k_work_poll_submit_to_queue()
741 work->poller.mode = MODE_TRIGGERED; in k_work_poll_submit_to_queue()
742 k_spin_unlock(&lock, key); in k_work_poll_submit_to_queue()
760 if (work->poller.is_polling) { in k_work_poll_submit_to_queue()
761 work->poller.is_polling = false; in k_work_poll_submit_to_queue()
762 work->poll_result = -EAGAIN; in k_work_poll_submit_to_queue()
764 work->poll_result = 0; in k_work_poll_submit_to_queue()
768 clear_event_registrations(events, events_registered, key); in k_work_poll_submit_to_queue()
769 k_spin_unlock(&lock, key); in k_work_poll_submit_to_queue()
772 k_work_submit_to_queue(work_q, &work->work); in k_work_poll_submit_to_queue()
779 int k_work_poll_submit(struct k_work_poll *work, in k_work_poll_submit()
781 int num_events, in k_work_poll_submit()
786 int ret = k_work_poll_submit_to_queue(&k_sys_work_q, work, in k_work_poll_submit()
794 int k_work_poll_cancel(struct k_work_poll *work) in k_work_poll_cancel()
796 k_spinlock_key_t key; in k_work_poll_cancel() local
797 int retval; in k_work_poll_cancel()
802 if (work == NULL || work->workq == NULL) { in k_work_poll_cancel()
803 SYS_PORT_TRACING_FUNC_EXIT(k_work_poll, cancel, work, -EINVAL); in k_work_poll_cancel()
805 return -EINVAL; in k_work_poll_cancel()
808 key = k_spin_lock(&lock); in k_work_poll_cancel()
809 retval = triggered_work_cancel(work, key); in k_work_poll_cancel()
810 k_spin_unlock(&lock, key); in k_work_poll_cancel()