File: taskimpl.h

package info (click to toggle)
mongrel2 1.9.1-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 5,956 kB
  • sloc: ansic: 43,228; python: 2,827; sql: 1,555; makefile: 347; sh: 307; asm: 234; yacc: 145; php: 73; sed: 5
file content (153 lines) | stat: -rw-r--r-- 3,717 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Copyright (c) 2005-2006 Russ Cox, MIT; see COPYRIGHT */

#if defined(__sun__)
#    define __EXTENSIONS__ 1 /* SunOS */
#    if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__)
        /* NOT USING #define __MAKECONTEXT_V2_SOURCE 1 / * SunOS */
#    else
#        define __MAKECONTEXT_V2_SOURCE 1
#    endif
#endif

#define USE_UCONTEXT 1

#if defined(__OpenBSD__)
#undef USE_UCONTEXT
#define USE_UCONTEXT 0
#endif

#if defined(__APPLE__)
#include <AvailabilityMacros.h>
#if defined(MAC_OS_X_VERSION_10_5)
#undef USE_UCONTEXT
#define USE_UCONTEXT 0
#endif
#endif

#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sched.h>
#include <signal.h>
#if USE_UCONTEXT
#include <ucontext.h>
#endif
#include <sys/utsname.h>
#include <inttypes.h>
#include "task.h"

#define nelem(x) (sizeof(x)/sizeof((x)[0]))

#define ulong task_ulong
#define uint task_uint
#define uchar task_uchar
#define ushort task_ushort
#define uvlong task_uvlong
#define vlong task_vlong

typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long long uvlong;
typedef long long vlong;

#if defined(__FreeBSD__) && __FreeBSD__ < 5
extern    int        getmcontext(mcontext_t*);
extern    void        setmcontext(const mcontext_t*);
#define    setcontext(u)    setmcontext(&(u)->uc_mcontext)
#define    getcontext(u)    getmcontext(&(u)->uc_mcontext)
extern    int        swapcontext(ucontext_t*, const ucontext_t*);
extern    void        makecontext(ucontext_t*, void(*)(), int, ...);
#endif

#if defined(__APPLE__)
#    define mcontext libthread_mcontext
#    define mcontext_t libthread_mcontext_t
#    define ucontext libthread_ucontext
#    define ucontext_t libthread_ucontext_t
#    if defined(__i386__)
#        include "386-ucontext.h"
#    elif defined(__x86_64__)
#        include "amd64-ucontext.h"
#    else
#        include "power-ucontext.h"
#    endif    
#endif

#if defined(__OpenBSD__)
#    define mcontext libthread_mcontext
#    define mcontext_t libthread_mcontext_t
#    define ucontext libthread_ucontext
#    define ucontext_t libthread_ucontext_t
#    if defined __i386__
#        include "386-ucontext.h"
#    elif defined(__x86_64__)
#        include "amd64-ucontext.h"
#    else
#        include "power-ucontext.h"
#    endif
extern pid_t rfork_thread(int, void*, int(*)(void*), void*);
#endif

#if 0 &&  defined(__sun__)
#    define mcontext libthread_mcontext
#    define mcontext_t libthread_mcontext_t
#    define ucontext libthread_ucontext
#    define ucontext_t libthread_ucontext_t
#    include "sparc-ucontext.h"
#endif

#if 0 && defined(__arm__)
int getmcontext(mcontext_t*);
void setmcontext(const mcontext_t*);
#define    setcontext(u)    setmcontext((void *)&((u)->uc_mcontext.arm_r0))
#define    getcontext(u)    getmcontext((void *)&((u)->uc_mcontext.arm_r0))
#endif

typedef struct Context Context;

enum
{
    STACK = 8192
};

struct Context
{
    ucontext_t    uc;
};

struct Task
{
    char    name[MAX_STATE_LENGTH];    // offset known to acid
    char    state[MAX_STATE_LENGTH];
    Task    *next;
    Task    *prev;
    Context    context;
    uvlong    alarmtime;
    uint    id;
    uchar    *stk;
    uint    stksize;
    int    exiting;
    int    alltaskslot;
    int    system;
    int    ready;
    void    (*startfn)(void*);
    void    *startarg;
    int signal;
};

void    taskready(Task*);
void    taskswitch(void);

void    addtask(Tasklist*, Task*);
void    deltask(Tasklist*, Task*);

extern Task    *taskrunning;
extern int    taskcount;