Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * (see the web pages for full authors list) |
||
13 | * |
||
14 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
15 | * |
||
16 | * http://www.sssup.it |
||
17 | * http://retis.sssup.it |
||
18 | * http://shark.sssup.it |
||
19 | */ |
||
20 | |||
21 | /* |
||
22 | * Copyright (C) 2000 Massimiliano Giorgi |
||
23 | * |
||
24 | * This program is free software; you can redistribute it and/or modify |
||
25 | * it under the terms of the GNU General Public License as published by |
||
26 | * the Free Software Foundation; either version 2 of the License, or |
||
27 | * (at your option) any later version. |
||
28 | * |
||
29 | * This program is distributed in the hope that it will be useful, |
||
30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
32 | * GNU General Public License for more details. |
||
33 | * |
||
34 | * You should have received a copy of the GNU General Public License |
||
35 | * along with this program; if not, write to the Free Software |
||
36 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
37 | * |
||
38 | */ |
||
39 | |||
40 | #include "bqueue.h" |
||
41 | #include "glue.h" |
||
42 | |||
43 | int look_init(look_queue_t *q) |
||
44 | { |
||
45 | __b_fastmutex_init(&q->mutex); |
||
46 | q->disk=NULL; |
||
47 | q->queue[0]=NULL; |
||
48 | q->queue[1]=NULL; |
||
49 | q->dir=0; |
||
50 | q->counter=0; |
||
51 | return 0; |
||
52 | } |
||
53 | |||
54 | int look_numelements(look_queue_t *q) |
||
55 | { |
||
56 | return q->counter; |
||
57 | } |
||
58 | |||
59 | /* 0 -> no starvation */ |
||
60 | /* 1 -> possible starvation */ |
||
61 | #define STARVATION 1 |
||
62 | |||
63 | int look_insertrequest(look_queue_t *q, request_prologue_t *e) |
||
64 | { |
||
65 | request_prologue_t *p,*o; |
||
66 | |||
67 | __b_fastmutex_lock(&q->mutex); |
||
68 | |||
69 | if (q->queue[q->dir]==NULL) q->dir^=1; |
||
70 | |||
71 | if (q->queue[q->dir]==NULL) { |
||
72 | q->queue[q->dir]=e; |
||
73 | e->x.next=NULL; |
||
74 | } else { |
||
75 | |||
76 | if (e->cylinder==q->queue[q->dir]->cylinder) { |
||
77 | if (q->dir==STARVATION) goto HI_INS; |
||
78 | else goto LO_INS; |
||
79 | } |
||
80 | |||
81 | if (e->cylinder<q->queue[q->dir]->cylinder) { |
||
82 | LO_INS: |
||
83 | /* insert into low queue */ |
||
84 | o=NULL; |
||
85 | p=q->queue[0]; |
||
86 | while (p!=NULL) { |
||
87 | if (e->cylinder>p->cylinder) break; |
||
88 | o=p; |
||
89 | p=p->x.next; |
||
90 | } |
||
91 | if (o==NULL) q->queue[0]=e; |
||
92 | else o->x.next=e; |
||
93 | e->x.next=p; |
||
94 | } else { |
||
95 | HI_INS: |
||
96 | /* insert into high queue */ |
||
97 | o=NULL; |
||
98 | p=q->queue[1]; |
||
99 | while (p!=NULL) { |
||
100 | if (e->cylinder<p->cylinder) break; |
||
101 | o=p; |
||
102 | p=p->x.next; |
||
103 | } |
||
104 | if (o==NULL) q->queue[1]=e; |
||
105 | else o->x.next=e; |
||
106 | e->x.next=p; |
||
107 | } |
||
108 | |||
109 | } |
||
110 | |||
111 | q->counter++; |
||
112 | __b_fastmutex_unlock(&q->mutex); |
||
113 | return 0; |
||
114 | } |
||
115 | |||
116 | request_prologue_t *look_getrequest(look_queue_t *q) |
||
117 | { |
||
118 | request_prologue_t *ret; |
||
119 | __b_fastmutex_lock(&q->mutex); |
||
120 | ret=q->queue[q->dir]; |
||
121 | if (ret==NULL) { |
||
122 | q->dir^=1; |
||
123 | ret=q->queue[q->dir]; |
||
124 | } |
||
125 | __b_fastmutex_lock(&q->mutex); |
||
126 | return ret; |
||
127 | } |
||
128 | |||
129 | int look_removerequest(look_queue_t *q) |
||
130 | { |
||
131 | __b_fastmutex_lock(&q->mutex); |
||
132 | assertk(q->queue[q->dir]!=NULL); |
||
133 | q->queue[q->dir]=q->queue[q->dir]->x.next; |
||
134 | q->counter--; |
||
135 | __b_fastmutex_unlock(&q->mutex); |
||
136 | return 0; |
||
137 | } |