Lines Matching refs:pipe

30 static int pipe_get_internal(k_spinlock_key_t key, struct k_pipe *pipe,
39 void k_pipe_init(struct k_pipe *pipe, unsigned char *buffer, size_t size) in k_pipe_init() argument
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()
49 SYS_PORT_TRACING_OBJ_INIT(k_pipe, pipe); in k_pipe_init()
51 pipe->flags = 0; in k_pipe_init()
54 sys_dlist_init(&pipe->poll_events); in k_pipe_init()
56 z_object_init(pipe); in k_pipe_init()
59 k_obj_core_init_and_link(K_OBJ_CORE(pipe), &obj_type_pipe); in k_pipe_init()
63 int z_impl_k_pipe_alloc_init(struct k_pipe *pipe, size_t size) in z_impl_k_pipe_alloc_init() argument
68 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_pipe, alloc_init, pipe); in z_impl_k_pipe_alloc_init()
73 k_pipe_init(pipe, buffer, size); in z_impl_k_pipe_alloc_init()
74 pipe->flags = K_PIPE_FLAG_ALLOC; in z_impl_k_pipe_alloc_init()
80 k_pipe_init(pipe, NULL, 0U); in z_impl_k_pipe_alloc_init()
84 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, alloc_init, pipe, ret); in z_impl_k_pipe_alloc_init()
90 static inline int z_vrfy_k_pipe_alloc_init(struct k_pipe *pipe, size_t size) in z_vrfy_k_pipe_alloc_init() argument
92 Z_OOPS(Z_SYSCALL_OBJ_NEVER_INIT(pipe, K_OBJ_PIPE)); in z_vrfy_k_pipe_alloc_init()
94 return z_impl_k_pipe_alloc_init(pipe, size); in z_vrfy_k_pipe_alloc_init()
99 static inline void handle_poll_events(struct k_pipe *pipe) in handle_poll_events() argument
102 z_handle_obj_poll_events(&pipe->poll_events, K_POLL_STATE_PIPE_DATA_AVAILABLE); in handle_poll_events()
104 ARG_UNUSED(pipe); in handle_poll_events()
108 void z_impl_k_pipe_flush(struct k_pipe *pipe) in z_impl_k_pipe_flush() argument
112 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_pipe, flush, pipe); in z_impl_k_pipe_flush()
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()
119 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, flush, pipe); in z_impl_k_pipe_flush()
123 void z_vrfy_k_pipe_flush(struct k_pipe *pipe) in z_vrfy_k_pipe_flush() argument
125 Z_OOPS(Z_SYSCALL_OBJ(pipe, K_OBJ_PIPE)); in z_vrfy_k_pipe_flush()
127 z_impl_k_pipe_flush(pipe); in z_vrfy_k_pipe_flush()
132 void z_impl_k_pipe_buffer_flush(struct k_pipe *pipe) in z_impl_k_pipe_buffer_flush() argument
136 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_pipe, buffer_flush, pipe); in z_impl_k_pipe_buffer_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()
147 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, buffer_flush, pipe); in z_impl_k_pipe_buffer_flush()
151 void z_vrfy_k_pipe_buffer_flush(struct k_pipe *pipe) in z_vrfy_k_pipe_buffer_flush() argument
153 Z_OOPS(Z_SYSCALL_OBJ(pipe, K_OBJ_PIPE)); in z_vrfy_k_pipe_buffer_flush()
155 z_impl_k_pipe_buffer_flush(pipe); in z_vrfy_k_pipe_buffer_flush()
159 int k_pipe_cleanup(struct k_pipe *pipe) in k_pipe_cleanup() argument
161 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_pipe, cleanup, pipe); in k_pipe_cleanup()
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()
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()
192 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, cleanup, pipe, 0U); in k_pipe_cleanup()
326 static size_t pipe_write(struct k_pipe *pipe, sys_dlist_t *src_list, in pipe_write() argument
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()
380 int z_impl_k_pipe_put(struct k_pipe *pipe, void *data, size_t bytes_to_write, in z_impl_k_pipe_put() argument
395 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_pipe, put, pipe, timeout); in z_impl_k_pipe_put()
398 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, put, pipe, timeout, 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()
435 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, put, pipe, in z_impl_k_pipe_put()
453 *bytes_written = pipe_write(pipe, &src_list, in z_impl_k_pipe_put()
461 if ((pipe->bytes_used != 0U) && (*bytes_written != 0U)) { in z_impl_k_pipe_put()
462 handle_poll_events(pipe); 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()
482 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, put, pipe, timeout, 0); in z_impl_k_pipe_put()
489 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_pipe, put, pipe, timeout); 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()
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()
510 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, put, pipe, timeout, ret); in z_impl_k_pipe_put()
516 int z_vrfy_k_pipe_put(struct k_pipe *pipe, void *data, size_t bytes_to_write, in z_vrfy_k_pipe_put() argument
520 Z_OOPS(Z_SYSCALL_OBJ(pipe, K_OBJ_PIPE)); in z_vrfy_k_pipe_put()
524 return z_impl_k_pipe_put((struct k_pipe *)pipe, (void *)data, in z_vrfy_k_pipe_put()
531 static int pipe_get_internal(k_spinlock_key_t key, struct k_pipe *pipe, in pipe_get_internal() argument
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()
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()
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()
648 (void) pipe_write(pipe, &src_list, 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()
675 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_pipe, get, pipe, timeout); in pipe_get_internal()
679 z_sched_wait(&pipe->lock, key, &pipe->wait_q.readers, timeout, NULL); 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()
699 int z_impl_k_pipe_get(struct k_pipe *pipe, void *data, size_t bytes_to_read, in z_impl_k_pipe_get() argument
705 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_pipe, get, pipe, timeout); in z_impl_k_pipe_get()
708 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, get, pipe, in z_impl_k_pipe_get()
714 k_spinlock_key_t key = k_spin_lock(&pipe->lock); in z_impl_k_pipe_get()
716 int ret = pipe_get_internal(key, pipe, data, bytes_to_read, bytes_read, in z_impl_k_pipe_get()
719 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_pipe, get, pipe, timeout, ret); in z_impl_k_pipe_get()
725 int z_vrfy_k_pipe_get(struct k_pipe *pipe, void *data, size_t bytes_to_read, in z_vrfy_k_pipe_get() argument
728 Z_OOPS(Z_SYSCALL_OBJ(pipe, K_OBJ_PIPE)); in z_vrfy_k_pipe_get()
732 return z_impl_k_pipe_get((struct k_pipe *)pipe, (void *)data, in z_vrfy_k_pipe_get()
739 size_t z_impl_k_pipe_read_avail(struct k_pipe *pipe) in z_impl_k_pipe_read_avail() argument
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()
767 size_t z_vrfy_k_pipe_read_avail(struct k_pipe *pipe) in z_vrfy_k_pipe_read_avail() argument
769 Z_OOPS(Z_SYSCALL_OBJ(pipe, K_OBJ_PIPE)); in z_vrfy_k_pipe_read_avail()
771 return z_impl_k_pipe_read_avail(pipe); in z_vrfy_k_pipe_read_avail()
776 size_t z_impl_k_pipe_write_avail(struct k_pipe *pipe) in z_impl_k_pipe_write_avail() argument
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()
804 size_t z_vrfy_k_pipe_write_avail(struct k_pipe *pipe) in z_vrfy_k_pipe_write_avail() argument
806 Z_OOPS(Z_SYSCALL_OBJ(pipe, K_OBJ_PIPE)); in z_vrfy_k_pipe_write_avail()
808 return z_impl_k_pipe_write_avail(pipe); in z_vrfy_k_pipe_write_avail()
823 STRUCT_SECTION_FOREACH(k_pipe, pipe) { in init_pipe_obj_core_list()
824 k_obj_core_init_and_link(K_OBJ_CORE(pipe), &obj_type_pipe); in init_pipe_obj_core_list()