Subversion Repositories shark

Rev

Rev 3 | Go to most recent revision | 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 fcfs_init(fcfs_queue_t *q)
44
{
45
  __b_fastmutex_init(&q->mutex);
46
  q->disk=NULL;
47
  q->head=NULL;
48
  q->tail=NULL;
49
  q->counter=0;
50
  return 0;
51
}
52
 
53
int fcfs_numelements(fcfs_queue_t *q)
54
{
55
  return q->counter;
56
}
57
 
58
int fcfs_insertrequest(fcfs_queue_t *q, request_prologue_t *e)
59
{
60
 
61
  //cprintf("Û%p into %pÛ",e,q);
62
 
63
  __b_fastmutex_lock(&q->mutex);  
64
  if (q->head==NULL) q->head=e;
65
  else               q->tail->x.next=e;
66
  q->tail=e;
67
  e->x.next=NULL;
68
  q->counter++;
69
  __b_fastmutex_unlock(&q->mutex);
70
 
71
  return 0;
72
}
73
 
74
request_prologue_t *fcfs_getrequest(fcfs_queue_t *q)
75
{
76
  request_prologue_t *ret;
77
 
78
  //cprintf("Ûfrom %p have %pÛ",q,q->head);
79
 
80
  __b_fastmutex_lock(&q->mutex);
81
  ret=q->head;
228 giacomo 82
  __b_fastmutex_unlock(&q->mutex);
2 pj 83
 
84
  return ret;
85
}
86
 
87
int fcfs_removerequest(fcfs_queue_t *q)
88
{
89
  //cprintf("Ûremoved %p from %pÛ",q->head,q);
90
 
91
  __b_fastmutex_lock(&q->mutex);
92
  assertk(q->head!=NULL);
93
  q->head=q->head->x.next;
94
  q->counter--;
95
  __b_fastmutex_unlock(&q->mutex);
96
 
97
  return 0;
98
}