Subversion Repositories shark

Rev

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
 * 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
/*
44
 *
45
 */
46
 
47
#include <modules/bd_edf.h>
48
 
49
static __inline__ void get_dl(request_prologue_t *e)
50
{
51
  e->x.dl=bd_edf_getdl();
52
}
53
 
54
/*
55
 *
56
 */
57
 
58
int bd_edf_init(bd_edf_queue_t *q)
59
{
60
  __b_fastmutex_init(&q->mutex);
61
  q->disk=NULL;
62
  q->queue=NULL;
63
  q->counter=0;
64
  q->inservice=0;
65
  return 0;
66
}
67
 
68
int bd_edf_numelements(bd_edf_queue_t *q)
69
{
70
  return q->counter;
71
}
72
 
73
int bd_edf_insertrequest(bd_edf_queue_t *q, request_prologue_t *e)
74
{
75
  request_prologue_t *p,*o;
76
 
77
  __b_fastmutex_lock(&q->mutex);
78
 
79
  get_dl(e);
80
 
81
  if (q->queue==NULL) {
82
    q->queue=e;
83
    e->x.next=NULL;
84
  } else {
85
    o=NULL;
86
    p=q->queue;
87
    if (q->inservice) {
88
      /* no preemption possible! */
89
      o=p;
90
      p=p->x.next;
91
    }
92
    while (p!=NULL) {
93
      if (e->x.dl<p->x.dl) break;
94
      o=p;
95
      p=p->x.next;
96
    }
97
    o->x.next=e;
98
    e->x.next=p;    
99
  }
100
 
101
  q->counter++;
102
  __b_fastmutex_unlock(&q->mutex);
103
 
104
  return 0;
105
}
106
 
107
request_prologue_t *bd_edf_getrequest(bd_edf_queue_t *q)
108
{
109
  request_prologue_t *ret;
110
 
111
  __b_fastmutex_lock(&q->mutex);
112
  ret=q->queue;
113
  if (ret!=NULL) q->inservice=1;
114
  __b_fastmutex_lock(&q->mutex);
115
 
116
  return ret;
117
}
118
 
119
int bd_edf_removerequest(bd_edf_queue_t *q)
120
{
121
  __b_fastmutex_lock(&q->mutex);
122
  assertk(q->queue!=NULL);
123
  q->queue=q->queue->x.next;
124
  q->inservice=0;
125
  q->counter--;
126
  __b_fastmutex_unlock(&q->mutex);
127
 
128
  return 0;
129
}
130
 
131
 
132