From c6942f61370cfd7088ee47e6a6b2024f0f249491 Mon Sep 17 00:00:00 2001 From: Frank Benkert Date: Thu, 2 Nov 2017 08:53:14 -0600 Subject: [PATCH] drivers/serial/serial.c: Optimize wait time in tcdram() for buffer emptying According to the specification, the close function must wait until all data has been written before it closes the file (except O_NONBLOCK is set). The maximum waiting time for this is not specified. To be able to edit the file list of the process, the close function has to lock the file list semaphore. After that the close function of the serial driver is called. Waiting for the complete transmission of all data is done in the serial driver. This causes the semaphore to remain locked until all data has been sent. However, no other thread of the process can edit the file list for that time (open, close, dup2, etc.). This is not optimal in a multithreaded environment. Therefore, we have to keep the waiting time within the driver as short as possible. --- drivers/serial/serial.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index ecf21006a2c..8ec8350b8cb 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -88,8 +88,8 @@ /* Timing */ -#define HALF_SECOND_MSEC 500 -#define HALF_SECOND_USEC 500000L +#define POLL_DELAY_MSEC 1 +#define POLL_DELAY_USEC 1000 /************************************************************************************ * Private Types @@ -471,9 +471,9 @@ static int uart_tcdrain(FAR uart_dev_t *dev) while (!uart_txempty(dev)) { #ifndef CONFIG_DISABLE_SIGNALS - nxsig_usleep(HALF_SECOND_USEC); + nxsig_usleep(POLL_DELAY_USEC); #else - up_mdelay(HALF_SECOND_MSEC); + up_mdelay(POLL_DELAY_MSEC); #endif } }