kernel: fix runtime initialization of k_pipe object

Runtime initialization failed to reset the lock field, causing
problems when the pipe object is located on a stack and passed by
reference to other code.  Lacking an API for initializing a spinlock
by itself use the idiom from _K_PIPE_INITIALIZER().

To simplify maintainability the initialization order is changed
slightly to match the structure field declaration order.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2020-04-20 10:52:25 -05:00 committed by Ioannis Glaropoulos
commit aea9d35c4e

View file

@ -135,10 +135,11 @@ void k_pipe_init(struct k_pipe *pipe, unsigned char *buffer, size_t size)
pipe->bytes_used = 0; pipe->bytes_used = 0;
pipe->read_index = 0; pipe->read_index = 0;
pipe->write_index = 0; pipe->write_index = 0;
pipe->flags = 0; pipe->lock = (struct k_spinlock){};
z_waitq_init(&pipe->wait_q.writers); z_waitq_init(&pipe->wait_q.writers);
z_waitq_init(&pipe->wait_q.readers); z_waitq_init(&pipe->wait_q.readers);
SYS_TRACING_OBJ_INIT(k_pipe, pipe); SYS_TRACING_OBJ_INIT(k_pipe, pipe);
pipe->flags = 0;
z_object_init(pipe); z_object_init(pipe);
} }