From 23d4877db88a9a6ba9a59a2335410cfd38867d76 Mon Sep 17 00:00:00 2001 From: batt Date: Fri, 17 Nov 2006 18:15:55 +0000 Subject: [PATCH] Avoid race conditions. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@729 38d2e660-2303-0410-9eaa-f027e97ec537 --- drv/ser.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drv/ser.c b/drv/ser.c index 0d5d7ec2..598ea885 100755 --- a/drv/ser.c +++ b/drv/ser.c @@ -28,6 +28,9 @@ /*#* *#* $Log$ + *#* Revision 1.33 2006/11/17 18:15:55 batt + *#* Avoid race conditions. + *#* *#* Revision 1.32 2006/11/17 17:03:58 batt *#* Implement ser_setstatus and ser_getstatus as functions to avoid race conditions. *#* @@ -196,7 +199,7 @@ int ser_putchar(int c, struct Serial *port) #if CONFIG_SER_TXTIMEOUT != -1 if (timer_clock() - start_time >= port->txtimeout) { - port->status |= SERRF_TXTIMEOUT; + ATOMIC(port->status |= SERRF_TXTIMEOUT); return EOF; } #endif /* CONFIG_SER_TXTIMEOUT */ @@ -240,19 +243,19 @@ int ser_getchar(struct Serial *port) #if CONFIG_SER_RXTIMEOUT != -1 if (timer_clock() - start_time >= port->rxtimeout) { - port->status |= SERRF_RXTIMEOUT; + ATOMIC(port->status |= SERRF_RXTIMEOUT); return EOF; } #endif /* CONFIG_SER_RXTIMEOUT */ } - while (fifo_isempty_locked(&port->rxfifo) && (port->status & SERRF_RX) == 0); + while (fifo_isempty_locked(&port->rxfifo) && (ser_getstatus(port) & SERRF_RX) == 0); } /* * Get a byte from the FIFO (avoiding sign-extension), * re-enable RTS, then return result. */ - if (port->status & SERRF_RX) + if (ser_getstatus(port) & SERRF_RX) return EOF; return (int)(unsigned char)fifo_pop_locked(&port->rxfifo); } -- 2.25.1