3 * cpulimit - a cpu limiter for Linux
5 * Copyright (C) 2005-2008, by: Angelo Marletta <marlonx80@hotmail.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 **********************************************************************
23 * Dynamic list implementation
29 #define EMPTYLIST NULL
31 void init_list(struct list *l,int keysize) {
32 l->first=l->last=NULL;
37 struct list_node *add_elem(struct list *l,void *elem) {
38 struct list_node *newnode=malloc(sizeof(struct list_node));
40 newnode->previous=l->last;
43 l->first=l->last=newnode;
46 l->last->next=newnode;
53 void delete_node(struct list *l,struct list_node *node) {
54 if (l->count==1) l->first=l->last=NULL;
57 node->next->previous=NULL;
62 node->previous->next=NULL;
63 l->last=node->previous;
66 node->previous->next=node->next;
67 node->next->previous=node->previous;
73 void destroy_node(struct list *l,struct list_node *node) {
79 int is_EMPTYLIST_list(struct list *l) {
80 return (l->count==0?TRUE:FALSE);
83 int get_list_count(struct list *l) {
87 void *first_elem(struct list *l) {
88 return l->first->data;
91 struct list_node *first_node(struct list *l) {
95 void *last_elem(struct list *l) {
99 struct list_node *last_node(struct list *l) {
103 struct list_node *xlocate_node(struct list *l,void *elem,int offset,int length) {
104 struct list_node *tmp;
107 if(!memcmp(tmp->data+offset,elem,length==0?l->keysize:length)) return (tmp);
113 struct list_node *locate_node(struct list *l,void *elem) {
114 return(xlocate_node(l,elem,0,0));
117 void *xlocate_elem(struct list *l,void *elem,int offset,int length) {
118 struct list_node *node=xlocate_node(l,elem,offset,length);
119 return(node==NULL?NULL:node->data);
122 void *locate_elem(struct list *l,void *elem) {
123 return(xlocate_elem(l,elem,0,0));
126 void flush_list(struct list *l) {
127 struct list_node *tmp;
128 while(l->first!=EMPTYLIST) {
130 l->first=l->first->next;
138 void destroy_list(struct list *l) {
139 struct list_node *tmp;
140 while(l->first!=EMPTYLIST) {
142 l->first=l->first->next;