implemented support for data argument when starting threads:

given function is called from a wrapper instead of immediately returned to via the stack
This commit is contained in:
fros4943 2008-11-21 10:28:32 +00:00
parent daec791521
commit 1fbcfde0d6
2 changed files with 19 additions and 6 deletions

View file

@ -28,18 +28,27 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: mtarch.c,v 1.5 2008/08/27 13:10:29 fros4943 Exp $
* @(#)$Id: mtarch.c,v 1.6 2008/11/21 10:28:32 fros4943 Exp $
*/
#include <stdio.h>
#include "sys/mt.h"
static unsigned short *sptmp;
static struct mtarch_thread *running;
/*--------------------------------------------------------------------------*/
void
mtarch_init(void)
{
}
/*--------------------------------------------------------------------------*/
static void
mtarch_wrapper(void)
{
/* Call thread function with argument */
((void (*)(void *))running->function)((void*)running->data);
}
/*--------------------------------------------------------------------------*/
void
@ -57,15 +66,17 @@ mtarch_start(struct mtarch_thread *t,
*t->sp = (unsigned short)mt_exit;
--t->sp;
*t->sp = (unsigned short)function;
*t->sp = (unsigned short)mtarch_wrapper;
--t->sp;
/* Space for registers. */
t->sp -= 11;
/* Store function and argument (used in mtarch_wrapper) */
t->data = data;
t->function = function;
}
/*--------------------------------------------------------------------------*/
static unsigned short *sptmp;
static struct mtarch_thread *running;
static void
sw(void)

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: mtarch.h,v 1.2 2006/09/26 20:56:56 adamdunkels Exp $
* @(#)$Id: mtarch.h,v 1.3 2008/11/21 10:28:32 fros4943 Exp $
*/
#ifndef __MTARCH_H__
#define __MTARCH_H__
@ -38,6 +38,8 @@
struct mtarch_thread {
unsigned short stack[MTARCH_STACKSIZE];
unsigned short *sp;
void *data;
void *function;
};
struct mt_thread;
@ -46,4 +48,4 @@ int mtarch_stack_usage(struct mt_thread *t);
#endif /* __MTARCH_H__ */