Subversion Repositories shark

Rev

Rev 927 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
847 giacomo 1
#include <linuxcomp.h>
2
#include <linux/wait.h>
3
#include <linux/config.h>
4
#include <linux/list.h>
5
 
6
#include <kernel/types.h>
7
 
8
extern int task_activate(PID pid);
9
extern int exec_shadow;
10
 
11
struct task_struct {
12
        PID pid;
13
        int state;
14
        char comm[1024];
15
};
16
 
17
typedef struct task_struct task_t;
18
 
19
inline void init_waitqueue_head(wait_queue_head_t *q)
20
{
21
        q->lock = SPIN_LOCK_UNLOCKED;
22
        INIT_LIST_HEAD(&q->task_list);
23
}
24
 
25
static int try_to_wake_up(task_t * p, unsigned int state, int sync)
26
{
27
        task_activate(p->pid);
28
        return 0;
29
}
30
 
31
int default_wake_function(wait_queue_t *curr, unsigned mode, int sync)
32
{
33
        task_t *p = curr->task;
34
        return try_to_wake_up(p, mode, sync);
35
}
36
 
37
void __wake_up_common(wait_queue_head_t *q, unsigned int mode, int nr_exclusive, int sync)
38
{
39
        struct list_head *tmp, *next;
40
 
41
        list_for_each_safe(tmp, next, &q->task_list) {
42
                wait_queue_t *curr;
43
                unsigned flags;
44
 
45
                curr = list_entry(tmp, wait_queue_t, task_list);
46
                flags = curr->flags;
47
                curr->func(curr, mode, sync);
48
        }
49
 
50
}
51
 
52
void __wake_up(wait_queue_head_t *q, unsigned int mode, int nr_exclusive)
53
{
54
        unsigned long flags;
55
 
56
        spin_lock_irqsave(&q->lock, flags);
57
        __wake_up_common(q, mode, nr_exclusive, 0);
58
        spin_unlock_irqrestore(&q->lock, flags);
59
}
60
 
61
inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
62
{
63
        list_add(&new->task_list, &head->task_list);
64
}
65
 
66
void add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
67
{
68
        unsigned long flags;
69
 
70
        wait->flags &= ~WQ_FLAG_EXCLUSIVE;
71
        spin_lock_irqsave(&q->lock, flags);
72
        __add_wait_queue(q, wait);
73
        spin_unlock_irqrestore(&q->lock, flags);
74
}
75
 
76
void remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
77
{
78
        unsigned long flags;
79
 
80
        spin_lock_irqsave(&q->lock, flags);
81
        __remove_wait_queue(q, wait);
82
        spin_unlock_irqrestore(&q->lock, flags);
83
}
84
 
85
inline int waitqueue_active(wait_queue_head_t *q)
86
{
87
        return !list_empty(&q->task_list);
88
}
89
 
90
inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
91
{
92
        q->flags = 0;
93
        q->task = p;
94
        q->func = default_wake_function;
95
}
96
 
97
extern void * malloc(size_t size);
98
 
99
struct task_struct * get_current26(void)
100
{
101
        struct task_struct *tsp;
102
 
103
        tsp = malloc(sizeof(struct task_struct));
104
        if (!tsp)
105
        {
106
                printk(KERN_DEBUG "@get_current26 out of memory!!!\n");
107
                //
108
                // sys_abort?
109
                //
110
        }
111
        tsp->pid = exec_shadow;
112
 
113
        //        printk(KERN_DEBUG "File: %s Pid=%d\n", __FILE__, tsp->pid);
114
        return tsp;
115
}