Two issues:
- is_condition_met() was missing proper code for The
K_POLL_TYPE_PIPE_DATA_AVAILABLE case
- z_handle_obj_poll_events() was misplaced in z_impl_k_pipe_write()
Note: I added support for the deprecated pipe implementation to
is_condition_met() but that is untested.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The compiler complains that:
```
zephyr/kernel/include/kernel_internal.h:121:29:
error: 'reader' may be used uninitialized [-Werror=maybe-uninitialized]
121 | thread->swap_retval = value;
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~
zephyr/kernel/pipe.c: In function 'copy_to_pending_readers':
zephyr/kernel/pipe.c:92:26: note: 'reader' was declared here
92 | struct k_thread *reader;
| ^~~~~~
```
The static analyzer fails to see through the `LOCK_SCHED_SPINLOCK`
construct that the `reader` pointer is always initialized.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Systems that enabled this option don't have their stacks in coherent
memory. Given our pipe_buf_spec is stored on the stack, and readers may
also have their destination buffer on their stack too, it is not worth
going to the trouble of supporting direct-to-readers copy with them.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
We are waking up threads but failed to let them run if they are
higher priority. Add missing calls to z_reschedule().
Also wake up all pending writers as we don't know how many there might
be. It is more efficient to wake them all when the ring buffer is full
before reading from it rather than waking them one by one whenever there is
more room in it.
Thanks to Peter Mitsis for noticing those issues.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
If there are pending readers, it is best to perform a single data copy
directly into their final destination buffer rather than doing one copy
into the ring buffer just to immediately copy the same data out of it.
Incidentally, this allows for supporting pipes with no ring buffer at all.
The pipe implementation being deprecated has a similar capability so better
have it here too.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Dispense with the call to sys_timepoint_expired() by leveraging
swap_retval to distinguish between notifications and timeouts when
z_pend_curr() returns.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Simplify the logic, avoid repeated conditionals, avoid superfluous
scheduler calls, make the code more efficient and easier to read.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit adds new test cases for the pipe API rework.
* basic.c: Sanity check for pipe operations.
* concurrency.c: Test pipe operations with multiple threads.
* stress.c: Test pipe operations under stress conditions.
And moves the old pipe test cases to the deprecated folder.
Signed-off-by: Måns Ansgariusson <Mansgariusson@gmail.com>
This commit adds polling support to the newly rewritten k_pipe interface.
Changes include:
* Removed ifdef CONFIG_POLL from kernel/poll.c to let both implementations
coexist.
* Added the needed datastructures to the new k_pipe struct.
* k_pipe_write(..) now notifies the poll subsystem that data is available.
Signed-off-by: Måns Ansgariusson <Mansgariusson@gmail.com>
The `k_pipe_*` API has been reworked to provide a more consistent and
intuitive interface. The new API aims to provide a simple to use byte
stream interface that is more in line with the POSIX pipe API.
The previous API has been deprecated and will be removed in a future
release.
Signed-off-by: Måns Ansgariusson <Mansgariusson@gmail.com>