From f5492a1ebbbbfb106067ab5c97d75748ab3d2d8f Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 13 Sep 2009 22:32:01 +0000 Subject: [PATCH] Add assert to prevent write() method from being by interrupt handlers git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2048 42af7a65-404d-4744-a932-0658087f49c3 --- drivers/pipe_common.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/pipe_common.c b/drivers/pipe_common.c index 82a822374d..174778d6d0 100644 --- a/drivers/pipe_common.c +++ b/drivers/pipe_common.c @@ -51,6 +51,9 @@ #include #include +#if CONFIG_DEBUG +# include +#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)