freemyipod r867 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r866‎ | r867 | r868 >
Date:00:00, 1 July 2012
Author:user890104
Status:new
Tags:
Comment:
emCORE: fix a mutex not being unlocked when reading from a console
Modified paths:
  • /emcore/trunk/console.c (modified) (history)

Diff [purge]

Index: emcore/trunk/console.c
@@ -52,6 +52,13 @@
5353 #endif
5454 }
5555
 56+void console_set_speed(unsigned int consoles, unsigned int cps)
 57+{
 58+#ifdef HAVE_UART
 59+ if (consoles & 4) uart_set_baud(cps * 10);
 60+#endif
 61+}
 62+
5663 void cputc_internal(unsigned int consoles, char string) ICODE_ATTR;
5764 void cputc_internal(unsigned int consoles, char string)
5865 {
@@ -254,17 +261,23 @@
255262 leave_critical_section(mode);
256263 }
257264
 265+static inline int cread_unlock_return(unsigned int rc)
 266+{
 267+ mutex_unlock(&console_readmutex);
 268+ return rc;
 269+}
 270+
258271 int cgetc(unsigned int consoles, int timeout)
259272 {
260273 int result;
261274 mutex_lock(&console_readmutex, TIMEOUT_BLOCK);
262275 #ifdef HAVE_USB
263 - if ((consoles & 2) && (result = dbgconsole_getc(timeout)) != -1) return result;
 276+ if ((consoles & 2) && (result = dbgconsole_getc(timeout)) != -1) return cread_unlock_return(result);
264277 #endif
265278 #ifdef HAVE_UART
266 - if ((consoles & 4) && (result = uart_getc(timeout)) != -1) return result;
 279+ if ((consoles & 4) && (result = uart_getc(timeout)) != -1) return cread_unlock_return(result);
267280 #endif
268 - mutex_unlock(&console_readmutex);
 281+ return cread_unlock_return(-1);
269282 }
270283
271284 int cread(unsigned int consoles, char* buffer, size_t length, int timeout)
@@ -272,12 +285,12 @@
273286 int result;
274287 mutex_lock(&console_readmutex, TIMEOUT_BLOCK);
275288 #ifdef HAVE_USB
276 - if ((consoles & 2) && (result = dbgconsole_read(buffer, length, timeout))) return result;
 289+ if ((consoles & 2) && (result = dbgconsole_read(buffer, length, timeout))) return cread_unlock_return(result);
277290 #endif
278291 #ifdef HAVE_UART
279 - if ((consoles & 4) && (result = uart_read(buffer, length, timeout))) return result;
 292+ if ((consoles & 4) && (result = uart_read(buffer, length, timeout))) return cread_unlock_return(result);
280293 #endif
281 - mutex_unlock(&console_readmutex);
 294+ return cread_unlock_return(-1);
282295 }
283296
284297 void creada(unsigned int consoles, char* buffer, size_t length, int timeout)