diff --git a/drivers/pipe_common.c b/drivers/pipe_common.c index 82a822374d6612f5bad613c1e8067425b6fb4c22..174778d6d0119ee61137c554c1728401edfabb28 100644 --- a/drivers/pipe_common.c +++ b/drivers/pipe_common.c @@ -51,6 +51,9 @@ #include <debug.h> #include <nuttx/fs.h> +#if CONFIG_DEBUG +# include <nuttx/arch.h> +#endif #include "pipe_common.h" @@ -417,6 +420,20 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t } #endif + /* At present, this method cannot be called from interrupt handlers. That is + * because it calls sem_wait (via pipecommon_semtake below) and sem_wait cannot + * be called from interrupt level. This actually happens fairly commonly + * IF dbg() is called from interrupt handlers and stdout is being redirected + * via a pipe. In that case, the debug output will try to go out the pipe + * (interrupt handlers should use the lldbg() APIs). + * + * On the other hand, it would be very valuable to be able to feed the pipe + * from an interrupt handler! TODO: Consider disabling interrupts instead + * of taking semaphores so that pipes can be written from interupt handlers + */ + + DEBUGASSERT(up_interrupt_context() == FALSE) + /* Make sure that we have exclusive access to the device structure */ if (sem_wait(&dev->d_bfsem) < 0)