Subversion Repositories HelenOS

Rev

Rev 2938 | Rev 2940 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2938 Rev 2939
Line 32... Line 32...
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <stdlib.h>
35
#include <stdlib.h>
36
#include <libadt/list.h>
36
#include <libadt/list.h>
-
 
37
#include <assert.h>
-
 
38
#include <futex.h>
-
 
39
#include <async.h>
37
 
40
 
38
#include "dthread.h"
41
#include "dthread.h"
39
 
42
 
40
static int last_thread_id = 0;
43
static int last_thread_id = 0;
41
 
44
 
Line 51... Line 54...
51
        exit(1);
54
        exit(1);
52
    }
55
    }
53
 
56
 
54
    dt->id = ++last_thread_id;
57
    dt->id = ++last_thread_id;
55
    dt->hash = hash;
58
    dt->hash = hash;
-
 
59
    dt->fid = 0;
-
 
60
    dt->stopped = 0;
56
 
61
 
57
    if (!cwt) cwt = dt;
62
    if (!cwt) cwt = dt;
58
 
63
 
59
    list_append(&dt->link, &dthreads);
64
    list_append(&dt->link, &dthreads);
60
 
65
 
Line 65... Line 70...
65
{
70
{
66
    list_remove(&dt->link);
71
    list_remove(&dt->link);
67
    free(dt);
72
    free(dt);
68
}
73
}
69
 
74
 
-
 
75
/*
-
 
76
 * Get dthread struct serviced by fibril fid.
-
 
77
 */
-
 
78
dthread_t *dthread_get_by_fid(fid_t fid)
-
 
79
{
-
 
80
    link_t *cur;
-
 
81
    dthread_t *dt;
-
 
82
 
-
 
83
    dt = NULL;
-
 
84
    for (cur = dthreads.next; cur != &dthreads; cur = cur->next) {
-
 
85
        dt = list_get_instance(cur, dthread_t, link);
-
 
86
        if (dt->fid == fid) return dt;
-
 
87
    }  
-
 
88
 
-
 
89
    return NULL;
-
 
90
}
-
 
91
 
-
 
92
/*
-
 
93
 * Get dthread struct for dthread serviced by the current fibril.
-
 
94
 */
-
 
95
dthread_t *dthread_get(void)
-
 
96
{
-
 
97
    return dthread_get_by_fid(fibril_get_id());
-
 
98
}
-
 
99
 
-
 
100
void dthread_stop_me(void)
-
 
101
{
-
 
102
    dthread_t *dt;
-
 
103
    int i;
-
 
104
 
-
 
105
    dt = dthread_get();
-
 
106
    assert(dt);
-
 
107
 
-
 
108
    futex_down(&async_futex);
-
 
109
 
-
 
110
    dt->stopped = 1;
-
 
111
    fibril_switch(FIBRIL_TO_MANAGER);
-
 
112
 
-
 
113
    futex_up(&async_futex);
-
 
114
}
-
 
115
 
-
 
116
void dthread_resume(dthread_t *dt)
-
 
117
{
-
 
118
    if (!dt->stopped) return;
-
 
119
 
-
 
120
    futex_down(&async_futex);
-
 
121
 
-
 
122
    fibril_add_ready(dt->fid);
-
 
123
    dt->stopped = 0;
-
 
124
 
-
 
125
    futex_up(&async_futex);
-
 
126
}
-
 
127
 
70
 
128
 
71
/** @}
129
/** @}
72
 */
130
 */