mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-05 09:29:39 +00:00
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:
parent
daec791521
commit
1fbcfde0d6
@ -28,18 +28,27 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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 <stdio.h>
|
||||||
#include "sys/mt.h"
|
#include "sys/mt.h"
|
||||||
|
|
||||||
|
static unsigned short *sptmp;
|
||||||
|
static struct mtarch_thread *running;
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
mtarch_init(void)
|
mtarch_init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
mtarch_wrapper(void)
|
||||||
|
{
|
||||||
|
/* Call thread function with argument */
|
||||||
|
((void (*)(void *))running->function)((void*)running->data);
|
||||||
}
|
}
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
@ -57,15 +66,17 @@ mtarch_start(struct mtarch_thread *t,
|
|||||||
*t->sp = (unsigned short)mt_exit;
|
*t->sp = (unsigned short)mt_exit;
|
||||||
--t->sp;
|
--t->sp;
|
||||||
|
|
||||||
*t->sp = (unsigned short)function;
|
*t->sp = (unsigned short)mtarch_wrapper;
|
||||||
--t->sp;
|
--t->sp;
|
||||||
|
|
||||||
/* Space for registers. */
|
/* Space for registers. */
|
||||||
t->sp -= 11;
|
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
|
static void
|
||||||
sw(void)
|
sw(void)
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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__
|
#ifndef __MTARCH_H__
|
||||||
#define __MTARCH_H__
|
#define __MTARCH_H__
|
||||||
@ -38,6 +38,8 @@
|
|||||||
struct mtarch_thread {
|
struct mtarch_thread {
|
||||||
unsigned short stack[MTARCH_STACKSIZE];
|
unsigned short stack[MTARCH_STACKSIZE];
|
||||||
unsigned short *sp;
|
unsigned short *sp;
|
||||||
|
void *data;
|
||||||
|
void *function;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mt_thread;
|
struct mt_thread;
|
||||||
|
Loading…
Reference in New Issue
Block a user