-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove.c
31 lines (30 loc) · 1.08 KB
/
remove.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "buffer.h"
#include <linux/ktime.h>
#include <linux/slab.h>
// function that removes the item
node * remove_item ( list * lst, node * element )
{
node * val = NULL;
if ( element == lst->front ) { //you cannot remove the front
return val;
} else if ( element == lst->rear ) { //you cannot remove the rear, too
return val;
} else if ( lst -> size == 0 ) { //nothing is here. nothing.
return val;
} else {
node * n = element -> next; //element's next node is n.
node * p = element -> prev; //element's previous node is p.
n -> prev = p; //skip the element, re-connect previous node as p
p -> next = n; //skip the element, re-connect next node as n;
val = element ; //element->key will be the return value.
kfree ( element ) ; //successfully deleted
lst -> size -- ; //new_size=old_size-1
}
return val ; //return the value.
}
node * dequeue ( list * lst )
{
node * i = remove_item ( lst, lst -> front -> next ) ;
return i;
} //alias to dequeue action
MODULE_LICENSE("GPL");