Statistics
| Branch: | Revision:

root / src / sim / task.h @ 08285dff

History | View | Annotate | Download (2.31 KB)

1 01873262 Georg Kunz
//========================================================================
2
//  TASK.H - part of
3
//
4
//                 OMNeT++/OMNEST
5
//              Discrete System Simulation in C++
6
//
7
//  Author: Andras Varga
8
//          based on Stig Kofoed's portable coroutines, see the Manual
9
//========================================================================
10
11
/*--------------------------------------------------------------*
12
  Copyright (C) 1992-2008 Andras Varga
13
  Copyright (C) 2006-2008 OpenSim Ltd.
14

15
  This file is distributed WITHOUT ANY WARRANTY. See the file
16
  `license' for details on this and other legal matters.
17
*--------------------------------------------------------------*/
18
19
#ifndef __TASK_H
20
#define __TASK_H
21
22
#include <setjmp.h>
23
#include "platdep/platdefs.h"
24
25
NAMESPACE_BEGIN
26
27
#define JMP_BUF jmp_buf
28
#define SETJMP  setjmp
29
#define LONGJMP longjmp
30
31
//=== some defines
32
#define SAFETY_AREA     512
33
#define MIN_STACKSIZE  1024
34
35
//
36
// All "beef" are used to test stack overflow/stack usage by checking
37
// whether byte patterns placed in the memory have been overwritten by
38
// the coroutine function's normal stack usage.
39
//
40
41
#define DEADBEEF       0xdeafbeef
42
#define EATFRAME_MAX   (sizeof(_Task)+200)
43
44
typedef void (*_Task_fn)( void * );
45
46
struct _Task
47
{
48
  unsigned long guardbeef1;     // contains DEADBEEF; should stay first field
49
  JMP_BUF jmpb;                 // jump state
50
  JMP_BUF rst_jmpb;             // jump state restart task
51
  int used;                     // used or free
52
  unsigned size;                // size of actually allocated block
53
  _Task *next;                  // pointer to next control block
54
55
  _Task_fn fnp;                  // pointer to task function
56
  void *arg;                    // argument to task function
57
  unsigned stack_size;          // requested stack size
58
59
  _Task *prevbeef;              // pointer to previous eat() invocation's block
60
  unsigned long guardbeef2;     // contains DEADBEEF; should stay last field
61
};
62
63
extern _Task main_task;
64
extern _Task *current_task;
65
extern JMP_BUF tmp_jmpb;
66
67
void task_init( unsigned total_stack, unsigned main_stack );
68
_Task *task_create( _Task_fn fnp, void *arg, unsigned stack_size );
69
void task_switchto( _Task *p );
70
void task_free( _Task *t );
71
void task_restart( _Task *t );
72
bool task_testoverflow( _Task *t );
73
unsigned task_stackusage( _Task *t );
74
75
NAMESPACE_END
76
77
78
#endif
79