Lines Matching +full:has +full:- +full:lock

4  * SPDX-License-Identifier: Apache-2.0
41 pipe->buffer = buffer; in k_pipe_init()
42 pipe->size = size; in k_pipe_init()
43 pipe->bytes_used = 0U; in k_pipe_init()
44 pipe->read_index = 0U; in k_pipe_init()
45 pipe->write_index = 0U; in k_pipe_init()
46 pipe->lock = (struct k_spinlock){}; in k_pipe_init()
47 z_waitq_init(&pipe->wait_q.writers); in k_pipe_init()
48 z_waitq_init(&pipe->wait_q.readers); in k_pipe_init()
51 pipe->flags = 0; in k_pipe_init()
54 sys_dlist_init(&pipe->poll_events); in k_pipe_init()
74 pipe->flags = K_PIPE_FLAG_ALLOC; in z_impl_k_pipe_alloc_init()
77 ret = -ENOMEM; in z_impl_k_pipe_alloc_init()
102 z_handle_obj_poll_events(&pipe->poll_events, K_POLL_STATE_PIPE_DATA_AVAILABLE); in handle_poll_events()
114 k_spinlock_key_t key = k_spin_lock(&pipe->lock); in z_impl_k_pipe_flush()
116 (void) pipe_get_internal(key, pipe, NULL, (size_t) -1, &bytes_read, 0U, in z_impl_k_pipe_flush()
138 k_spinlock_key_t key = k_spin_lock(&pipe->lock); in z_impl_k_pipe_buffer_flush()
140 if (pipe->buffer != NULL) { in z_impl_k_pipe_buffer_flush()
141 (void) pipe_get_internal(key, pipe, NULL, pipe->size, in z_impl_k_pipe_buffer_flush()
144 k_spin_unlock(&pipe->lock, key); in z_impl_k_pipe_buffer_flush()
163 k_spinlock_key_t key = k_spin_lock(&pipe->lock); in k_pipe_cleanup()
165 CHECKIF((z_waitq_head(&pipe->wait_q.readers) != NULL) || in k_pipe_cleanup()
166 (z_waitq_head(&pipe->wait_q.writers) != NULL)) { in k_pipe_cleanup()
167 k_spin_unlock(&pipe->lock, key); in k_pipe_cleanup()
169 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, cleanup, pipe, -EAGAIN); in k_pipe_cleanup()
171 return -EAGAIN; in k_pipe_cleanup()
174 if ((pipe->flags & K_PIPE_FLAG_ALLOC) != 0U) { in k_pipe_cleanup()
175 k_free(pipe->buffer); in k_pipe_cleanup()
176 pipe->buffer = NULL; in k_pipe_cleanup()
183 pipe->size = 0U; in k_pipe_cleanup()
184 pipe->bytes_used = 0U; in k_pipe_cleanup()
185 pipe->read_index = 0U; in k_pipe_cleanup()
186 pipe->write_index = 0U; in k_pipe_cleanup()
187 pipe->flags &= ~K_PIPE_FLAG_ALLOC; in k_pipe_cleanup()
190 k_spin_unlock(&pipe->lock, key); in k_pipe_cleanup()
225 struct _pipe_desc *desc = (struct _pipe_desc *)thread->base.swap_data; in pipe_walk_op()
227 sys_dlist_append(walk_data->list, &desc->node); in pipe_walk_op()
229 walk_data->bytes_available += desc->bytes_to_xfer; in pipe_walk_op()
231 if (walk_data->bytes_available >= walk_data->bytes_requested) { in pipe_walk_op()
281 desc[0].bytes_to_xfer = end - start; in pipe_buffer_list_populate()
282 return end - start; in pipe_buffer_list_populate()
285 desc[0].bytes_to_xfer = size - start; in pipe_buffer_list_populate()
293 return size - start + end; in pipe_buffer_list_populate()
301 * < Minimum -EIO* -EAGAIN
303 * * The "-EIO No Wait" case was already checked after the list of pipe
311 if ((bytes_requested - bytes_remaining) >= min_xfer) { in pipe_return_code()
319 return -EAGAIN; in pipe_return_code()
338 bytes_copied = pipe_xfer(dest->buffer, dest->bytes_to_xfer, in pipe_write()
339 src->buffer, src->bytes_to_xfer); in pipe_write()
343 dest->buffer += bytes_copied; in pipe_write()
344 dest->bytes_to_xfer -= bytes_copied; in pipe_write()
346 src->buffer += bytes_copied; in pipe_write()
347 src->bytes_to_xfer -= bytes_copied; in pipe_write()
349 if (dest->thread == NULL) { in pipe_write()
353 pipe->bytes_used += bytes_copied; in pipe_write()
354 pipe->write_index += bytes_copied; in pipe_write()
355 if (pipe->write_index >= pipe->size) { in pipe_write()
356 pipe->write_index -= pipe->size; in pipe_write()
358 } else if (dest->bytes_to_xfer == 0U) { in pipe_write()
360 /* The thread's read request has been satisfied. */ in pipe_write()
362 z_unpend_thread(dest->thread); in pipe_write()
363 z_ready_thread(dest->thread); in pipe_write()
368 if (src->bytes_to_xfer == 0U) { in pipe_write()
372 if (dest->bytes_to_xfer == 0U) { in pipe_write()
399 -EINVAL); in z_impl_k_pipe_put()
401 return -EINVAL; in z_impl_k_pipe_put()
407 k_spinlock_key_t key = k_spin_lock(&pipe->lock); in z_impl_k_pipe_put()
415 &pipe->wait_q.readers, in z_impl_k_pipe_put()
418 if (pipe->bytes_used != pipe->size) { in z_impl_k_pipe_put()
421 pipe->buffer, in z_impl_k_pipe_put()
422 pipe->size, in z_impl_k_pipe_put()
423 pipe->write_index, in z_impl_k_pipe_put()
424 pipe->read_index); in z_impl_k_pipe_put()
432 k_spin_unlock(&pipe->lock, key); in z_impl_k_pipe_put()
436 timeout, -EIO); in z_impl_k_pipe_put()
438 return -EIO; in z_impl_k_pipe_put()
446 src_desc = k_is_in_isr() ? &isr_desc : &arch_current_thread()->pipe_desc; in z_impl_k_pipe_put()
448 src_desc->buffer = (unsigned char *)data; in z_impl_k_pipe_put()
449 src_desc->bytes_to_xfer = bytes_to_write; in z_impl_k_pipe_put()
450 src_desc->thread = arch_current_thread(); in z_impl_k_pipe_put()
451 sys_dlist_append(&src_list, &src_desc->node); in z_impl_k_pipe_put()
457 * Only handle poll events if the pipe has had some bytes written and in z_impl_k_pipe_put()
461 if ((pipe->bytes_used != 0U) && (*bytes_written != 0U)) { in z_impl_k_pipe_put()
474 /* The minimum amount of data has been copied */ in z_impl_k_pipe_put()
477 z_reschedule(&pipe->lock, key); in z_impl_k_pipe_put()
479 k_spin_unlock(&pipe->lock, key); in z_impl_k_pipe_put()
487 /* The minimum amount of data has not been copied. Block. */ in z_impl_k_pipe_put()
491 arch_current_thread()->base.swap_data = src_desc; in z_impl_k_pipe_put()
493 z_sched_wait(&pipe->lock, key, &pipe->wait_q.writers, timeout, NULL); in z_impl_k_pipe_put()
497 * the data has finished copying. The following spin lock/unlock pair in z_impl_k_pipe_put()
502 key = k_spin_lock(&pipe->lock); in z_impl_k_pipe_put()
503 k_spin_unlock(&pipe->lock, key); in z_impl_k_pipe_put()
505 *bytes_written = bytes_to_write - src_desc->bytes_to_xfer; in z_impl_k_pipe_put()
507 int ret = pipe_return_code(min_xfer, src_desc->bytes_to_xfer, in z_impl_k_pipe_put()
555 if (pipe->bytes_used != 0) { in pipe_get_internal()
558 pipe->buffer, in pipe_get_internal()
559 pipe->size, in pipe_get_internal()
560 pipe->read_index, in pipe_get_internal()
561 pipe->write_index); in pipe_get_internal()
565 &pipe->wait_q.writers, in pipe_get_internal()
573 k_spin_unlock(&pipe->lock, key); in pipe_get_internal()
576 return -EIO; in pipe_get_internal()
584 dest_desc = k_is_in_isr() ? &isr_desc : &arch_current_thread()->pipe_desc; in pipe_get_internal()
586 dest_desc->buffer = data; in pipe_get_internal()
587 dest_desc->bytes_to_xfer = bytes_to_read; in pipe_get_internal()
588 dest_desc->thread = arch_current_thread(); in pipe_get_internal()
592 bytes_copied = pipe_xfer(dest_desc->buffer, in pipe_get_internal()
593 dest_desc->bytes_to_xfer, in pipe_get_internal()
594 src_desc->buffer, in pipe_get_internal()
595 src_desc->bytes_to_xfer); in pipe_get_internal()
599 src_desc->buffer += bytes_copied; in pipe_get_internal()
600 src_desc->bytes_to_xfer -= bytes_copied; in pipe_get_internal()
602 if (dest_desc->buffer != NULL) { in pipe_get_internal()
603 dest_desc->buffer += bytes_copied; in pipe_get_internal()
605 dest_desc->bytes_to_xfer -= bytes_copied; in pipe_get_internal()
607 if (src_desc->thread == NULL) { in pipe_get_internal()
611 pipe->bytes_used -= bytes_copied; in pipe_get_internal()
612 pipe->read_index += bytes_copied; in pipe_get_internal()
613 if (pipe->read_index >= pipe->size) { in pipe_get_internal()
614 pipe->read_index -= pipe->size; in pipe_get_internal()
616 } else if (src_desc->bytes_to_xfer == 0U) { in pipe_get_internal()
618 /* The thread's write request has been satisfied. */ in pipe_get_internal()
620 z_unpend_thread(src_desc->thread); in pipe_get_internal()
621 z_ready_thread(src_desc->thread); in pipe_get_internal()
628 if (pipe->bytes_used != pipe->size) { in pipe_get_internal()
640 &pipe->wait_q.writers, in pipe_get_internal()
641 pipe->size - pipe->bytes_used); in pipe_get_internal()
644 pipe->buffer, pipe->size, in pipe_get_internal()
645 pipe->write_index, in pipe_get_internal()
646 pipe->read_index); in pipe_get_internal()
661 /* The minimum amount of data has been copied */ in pipe_get_internal()
665 z_reschedule(&pipe->lock, key); in pipe_get_internal()
667 k_spin_unlock(&pipe->lock, key); in pipe_get_internal()
673 /* The minimum amount of data has not been copied. Block. */ in pipe_get_internal()
677 arch_current_thread()->base.swap_data = dest_desc; in pipe_get_internal()
679 z_sched_wait(&pipe->lock, key, &pipe->wait_q.readers, timeout, NULL); in pipe_get_internal()
683 * the data has finished copying. The following spin lock/unlock pair in pipe_get_internal()
688 key = k_spin_lock(&pipe->lock); in pipe_get_internal()
689 k_spin_unlock(&pipe->lock, key); in pipe_get_internal()
691 *bytes_read = bytes_to_read - dest_desc->bytes_to_xfer; in pipe_get_internal()
693 int ret = pipe_return_code(min_xfer, dest_desc->bytes_to_xfer, in pipe_get_internal()
709 timeout, -EINVAL); in z_impl_k_pipe_get()
711 return -EINVAL; in z_impl_k_pipe_get()
714 k_spinlock_key_t key = k_spin_lock(&pipe->lock); in z_impl_k_pipe_get()
745 if ((pipe->buffer == NULL) || (pipe->size == 0U)) { in z_impl_k_pipe_read_avail()
750 key = k_spin_lock(&pipe->lock); in z_impl_k_pipe_read_avail()
752 if (pipe->read_index == pipe->write_index) { in z_impl_k_pipe_read_avail()
753 res = pipe->bytes_used; in z_impl_k_pipe_read_avail()
754 } else if (pipe->read_index < pipe->write_index) { in z_impl_k_pipe_read_avail()
755 res = pipe->write_index - pipe->read_index; in z_impl_k_pipe_read_avail()
757 res = pipe->size - (pipe->read_index - pipe->write_index); in z_impl_k_pipe_read_avail()
760 k_spin_unlock(&pipe->lock, key); in z_impl_k_pipe_read_avail()
782 if ((pipe->buffer == NULL) || (pipe->size == 0U)) { in z_impl_k_pipe_write_avail()
787 key = k_spin_lock(&pipe->lock); in z_impl_k_pipe_write_avail()
789 if (pipe->write_index == pipe->read_index) { in z_impl_k_pipe_write_avail()
790 res = pipe->size - pipe->bytes_used; in z_impl_k_pipe_write_avail()
791 } else if (pipe->write_index < pipe->read_index) { in z_impl_k_pipe_write_avail()
792 res = pipe->read_index - pipe->write_index; in z_impl_k_pipe_write_avail()
794 res = pipe->size - (pipe->write_index - pipe->read_index); in z_impl_k_pipe_write_avail()
797 k_spin_unlock(&pipe->lock, key); in z_impl_k_pipe_write_avail()