Details | 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 | /* |
||
23 | * Copyright (C) 2000 Massimiliano Giorgi |
||
24 | * |
||
25 | * This program is free software; you can redistribute it and/or modify |
||
26 | * it under the terms of the GNU General Public License as published by |
||
27 | * the Free Software Foundation; either version 2 of the License, or |
||
28 | * (at your option) any later version. |
||
29 | * |
||
30 | * This program is distributed in the hope that it will be useful, |
||
31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
33 | * GNU General Public License for more details. |
||
34 | * |
||
35 | * You should have received a copy of the GNU General Public License |
||
36 | * along with this program; if not, write to the Free Software |
||
37 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
38 | * |
||
39 | */ |
||
40 | |||
41 | #include "bqueue.h" |
||
42 | #include "glue.h" |
||
43 | |||
44 | int clook_init(clook_queue_t *q) |
||
45 | { |
||
46 | __b_fastmutex_init(&q->mutex); |
||
47 | q->disk=NULL; |
||
48 | q->queue[0]=NULL; |
||
49 | q->queue[1]=NULL; |
||
50 | q->act=0; |
||
51 | q->counter=0; |
||
52 | return 0; |
||
53 | } |
||
54 | |||
55 | int clook_numelements(clook_queue_t *q) |
||
56 | { |
||
57 | return q->counter; |
||
58 | } |
||
59 | |||
60 | /* 0 -> no starvation */ |
||
61 | /* 1 -> possible starvation */ |
||
62 | #define STARVATION 0 |
||
63 | |||
64 | int clook_insertrequest(clook_queue_t *q, request_prologue_t *e) |
||
65 | { |
||
66 | request_prologue_t *p,*o; |
||
67 | |||
68 | __b_fastmutex_lock(&q->mutex); |
||
69 | |||
70 | if (q->queue[q->act]==NULL) { |
||
71 | q->queue[q->act]=e; |
||
72 | e->x.next=NULL; |
||
73 | } else if (e->cylinder>q->queue[q->act]->cylinder-STARVATION) { |
||
74 | o=q->queue[q->act]; |
||
75 | p=o->x.next; |
||
76 | while (p!=NULL) { |
||
77 | if (e->cylinder<p->cylinder) break; |
||
78 | o=p; |
||
79 | p=p->x.next; |
||
80 | } |
||
81 | o->x.next=e; |
||
82 | e->x.next=p; |
||
83 | } else { |
||
84 | o=NULL; |
||
85 | p=q->queue[q->act^1]; |
||
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[q->act^1]=e; |
||
92 | else o->x.next=e; |
||
93 | e->x.next=p; |
||
94 | } |
||
95 | |||
96 | q->counter++; |
||
97 | __b_fastmutex_unlock(&q->mutex); |
||
98 | return 0; |
||
99 | } |
||
100 | |||
101 | request_prologue_t *clook_getrequest(clook_queue_t *q) |
||
102 | { |
||
103 | request_prologue_t *ret; |
||
104 | __b_fastmutex_lock(&q->mutex); |
||
105 | ret=q->queue[q->act]; |
||
106 | if (ret==NULL) { |
||
107 | q->act^=1; |
||
108 | ret=q->queue[q->act]; |
||
109 | } |
||
110 | __b_fastmutex_lock(&q->mutex); |
||
111 | return ret; |
||
112 | } |
||
113 | |||
114 | int clook_removerequest(clook_queue_t *q) |
||
115 | { |
||
116 | __b_fastmutex_lock(&q->mutex); |
||
117 | assertk(q->queue[q->act]!=NULL); |
||
118 | q->queue[q->act]=q->queue[q->act]->x.next; |
||
119 | q->counter--; |
||
120 | __b_fastmutex_unlock(&q->mutex); |
||
121 | return 0; |
||
122 | } |