~ubuntu-branches/ubuntu/lucid/9base/lucid

« back to all changes in this revision

Viewing changes to lib9/qlock.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2006-01-25 15:33:00 UTC
  • Revision ID: james.westby@ubuntu.com-20060125153300-6hh4p9wx8iqqply5
Tags: upstream-2
ImportĀ upstreamĀ versionĀ 2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <u.h>
 
2
#include <libc.h>
 
3
 
 
4
/*
 
5
 * The function pointers are supplied by the thread
 
6
 * library during its initialization.  If there is no thread
 
7
 * library, there is no multithreading.
 
8
 */
 
9
 
 
10
int     (*_lock)(Lock*, int, ulong);
 
11
void    (*_unlock)(Lock*, ulong);
 
12
int     (*_qlock)(QLock*, int, ulong);  /* do not use */
 
13
void    (*_qunlock)(QLock*, ulong);
 
14
void    (*_rsleep)(Rendez*, ulong);     /* do not use */
 
15
int     (*_rwakeup)(Rendez*, int, ulong);
 
16
int     (*_rlock)(RWLock*, int, ulong); /* do not use */
 
17
int     (*_wlock)(RWLock*, int, ulong);
 
18
void    (*_runlock)(RWLock*, ulong);
 
19
void    (*_wunlock)(RWLock*, ulong);
 
20
 
 
21
void
 
22
lock(Lock *l)
 
23
{
 
24
        /*
 
25
        if(_lock)
 
26
                (*_lock)(l, 1, getcallerpc(&l));
 
27
        else
 
28
                l->held = 1;
 
29
                */
 
30
}
 
31
 
 
32
int
 
33
canlock(Lock *l)
 
34
{
 
35
        /*
 
36
        if(_lock)
 
37
                return (*_lock)(l, 0, getcallerpc(&l));
 
38
        else{
 
39
                if(l->held)
 
40
                        return 0;
 
41
                l->held = 1;
 
42
                return 1;
 
43
        }
 
44
        */
 
45
        return 1;
 
46
}
 
47
 
 
48
void
 
49
unlock(Lock *l)
 
50
{
 
51
        /*
 
52
        if(_unlock)
 
53
                (*_unlock)(l, getcallerpc(&l));
 
54
        else
 
55
                l->held = 0;
 
56
                */
 
57
}
 
58
 
 
59
void
 
60
qlock(QLock *l)
 
61
{
 
62
        /*
 
63
        if(_qlock)
 
64
                (*_qlock)(l, 1, getcallerpc(&l));
 
65
        else
 
66
                l->l.held = 1;
 
67
                */
 
68
}
 
69
 
 
70
int
 
71
canqlock(QLock *l)
 
72
{
 
73
        /*
 
74
        if(_qlock)
 
75
                return (*_qlock)(l, 0, getcallerpc(&l));
 
76
        else{
 
77
                if(l->l.held)
 
78
                        return 0;
 
79
                l->l.held = 1;
 
80
                return 1;
 
81
        }
 
82
        */
 
83
        return 1;
 
84
}
 
85
 
 
86
void
 
87
qunlock(QLock *l)
 
88
{
 
89
        /*
 
90
        if(_qunlock)
 
91
                (*_qunlock)(l, getcallerpc(&l));
 
92
        else
 
93
                l->l.held = 0;
 
94
                */
 
95
}
 
96
 
 
97
void
 
98
rlock(RWLock *l)
 
99
{
 
100
        /*
 
101
        if(_rlock)
 
102
                (*_rlock)(l, 1, getcallerpc(&l));
 
103
        else
 
104
                l->readers++;
 
105
                */
 
106
}
 
107
 
 
108
int
 
109
canrlock(RWLock *l)
 
110
{
 
111
        /*
 
112
        if(_rlock)
 
113
                return (*_rlock)(l, 0, getcallerpc(&l));
 
114
        else{
 
115
                if(l->writer)
 
116
                        return 0;
 
117
                l->readers++;
 
118
                return 1;
 
119
        }
 
120
        */
 
121
        return 1;
 
122
}
 
123
 
 
124
void
 
125
runlock(RWLock *l)
 
126
{
 
127
        /*
 
128
        if(_runlock)
 
129
                (*_runlock)(l, getcallerpc(&l));
 
130
        else
 
131
                l->readers--;
 
132
                */
 
133
}
 
134
 
 
135
void
 
136
wlock(RWLock *l)
 
137
{
 
138
        /*
 
139
        if(_wlock)
 
140
                (*_wlock)(l, 1, getcallerpc(&l));
 
141
        else
 
142
                l->writer = (void*)1;
 
143
                */
 
144
}
 
145
 
 
146
int
 
147
canwlock(RWLock *l)
 
148
{
 
149
        /*
 
150
        if(_wlock)
 
151
                return (*_wlock)(l, 0, getcallerpc(&l));
 
152
        else{
 
153
                if(l->writer || l->readers)
 
154
                        return 0;
 
155
                l->writer = (void*)1;
 
156
                return 1;
 
157
        }
 
158
        */
 
159
        return 1;
 
160
}
 
161
 
 
162
void
 
163
wunlock(RWLock *l)
 
164
{
 
165
        /*
 
166
        if(_wunlock)
 
167
                (*_wunlock)(l, getcallerpc(&l));
 
168
        else
 
169
                l->writer = nil;
 
170
                */
 
171
}
 
172
 
 
173
void
 
174
rsleep(Rendez *r)
 
175
{
 
176
        /*
 
177
        if(_rsleep)
 
178
                (*_rsleep)(r, getcallerpc(&r));
 
179
                */
 
180
}
 
181
 
 
182
int
 
183
rwakeup(Rendez *r)
 
184
{
 
185
        /*
 
186
        if(_rwakeup)
 
187
                return (*_rwakeup)(r, 0, getcallerpc(&r));
 
188
                */
 
189
        return 0;
 
190
}
 
191
 
 
192
int
 
193
rwakeupall(Rendez *r)
 
194
{
 
195
        /*
 
196
        if(_rwakeup)
 
197
                return (*_rwakeup)(r, 1, getcallerpc(&r));
 
198
                */
 
199
        return 0;
 
200
}