From: batt Date: Fri, 17 Nov 2006 18:15:55 +0000 (+0000) Subject: Avoid race conditions. X-Git-Tag: 1.0.0~512 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=23d4877db88a9a6ba9a59a2335410cfd38867d76;p=bertos.git Avoid race conditions. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@729 38d2e660-2303-0410-9eaa-f027e97ec537 --- 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); }