Not all targets support stdio. There I replaced stdio output with log output (and streamlined the source).

This commit is contained in:
oliverschmidt 2008-05-26 09:12:22 +00:00
parent 03462fabd6
commit 8248685dcf
1 changed files with 7 additions and 19 deletions

View File

@ -30,7 +30,7 @@
* *
* Author: Oliver Schmidt <ol.sc@web.de> * Author: Oliver Schmidt <ol.sc@web.de>
* *
* $Id: multi-threading.c,v 1.3 2007/08/10 10:33:28 oliverschmidt Exp $ * $Id: multi-threading.c,v 1.4 2008/05/26 09:12:22 oliverschmidt Exp $
*/ */
/** /**
@ -41,28 +41,16 @@
* Oliver Schmidt <ol.sc@web.de> * Oliver Schmidt <ol.sc@web.de>
*/ */
#ifdef __CYGWIN__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* The Contiki Multi-threading library is on Windows implemented using /* The Contiki Multi-threading library is on Windows implemented using
* Win32 fibers. The Cygwin C-library implements Thread-Local-Storage * Win32 fibers. The Cygwin C-library implements Thread-Local-Storage
* in a way that is incompatible with fibers. Therefore most Cygwin * in a way that is incompatible with fibers. Therefore most Cygwin
* C-library functions don't work when called from a Contiki thread. * C-library functions don't work when called from a Contiki thread. */
*
* So the sample application calls the Win32 function wsprintf instead
* of the Cygwin function sprintf from its Contiki threads. */
#define sprintf wsprintf
#endif /* __CYGWIN__ */
#include <stdio.h>
#include "contiki.h" #include "contiki.h"
#include "sys/log.h"
#include "sys/mt.h" #include "sys/mt.h"
static char buf[12]; static char *ptr;
PROCESS(multi_threading_process, "Multi-threading process"); PROCESS(multi_threading_process, "Multi-threading process");
AUTOSTART_PROCESSES(&multi_threading_process); AUTOSTART_PROCESSES(&multi_threading_process);
@ -71,7 +59,7 @@ AUTOSTART_PROCESSES(&multi_threading_process);
static void static void
thread_func(char *str, int len) thread_func(char *str, int len)
{ {
sprintf(buf, "%s\n", str + len); ptr = str + len;
mt_yield(); mt_yield();
if(len) { if(len) {
@ -79,7 +67,7 @@ thread_func(char *str, int len)
mt_yield(); mt_yield();
} }
sprintf(buf, "%s\n", str + len); ptr = str + len;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
@ -117,7 +105,7 @@ PROCESS_THREAD(multi_threading_process, ev, data)
mt_exec(&count_thread); mt_exec(&count_thread);
toggle++; toggle++;
} }
printf(buf); log_message(ptr, "");
etimer_set(&timer, CLOCK_SECOND / 2); etimer_set(&timer, CLOCK_SECOND / 2);
} }