Skip to content

Commit

Permalink
sys: newlib: remove _read_r() race
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Jun 1, 2015
1 parent be50f8b commit be4fc65
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sys/newlib/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,13 @@ int _open_r(struct _reent *r, const char *name, int mode)
int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count)
{
#ifndef MODULE_UART0
int res;
mutex_lock(&uart_rx_mutex);

unsigned state = disableIRQ();
count = count < rx_buf.avail ? count : rx_buf.avail;

return ringbuffer_get(&rx_buf, (char*)buffer, count);
res = ringbuffer_get(&rx_buf, (char*)buffer, count);
restoreIRQ(state);
return res;
#else
char *res = (char*)buffer;
res[0] = (char)uart0_readc();
Expand Down

0 comments on commit be4fc65

Please # to comment.