]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/dsp/dspgateway/proclist.h
Merge current mainline tree into linux-omap tree
[linux-2.6-omap-h63xx.git] / drivers / dsp / dspgateway / proclist.h
1 /*
2  * This file is part of OMAP DSP driver (DSP Gateway version 3.3.1)
3  *
4  * Copyright (C) 2004-2006 Nokia Corporation. All rights reserved.
5  *
6  * Contact: Toshihiro Kobayashi <toshihiro.kobayashi@nokia.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
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 St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #ifndef __PLAT_OMAP_DSP_PROCLIST_H
25 #define __PLAT_OMAP_DSP_PROCLIST_H
26
27 struct proc_list {
28         struct list_head list_head;
29         pid_t pid;
30         struct file *file;
31 };
32
33 static inline int proc_list_add(spinlock_t *lock, struct list_head *list,
34                                      struct task_struct *tsk, struct file *file)
35 {
36         struct proc_list *new;
37
38         new = kmalloc(sizeof(struct proc_list), GFP_KERNEL);
39         if (new == NULL)
40                 return -ENOMEM;
41         new->pid = tsk->pid;
42         new->file = file;
43         spin_lock(lock);
44         list_add_tail(&new->list_head, list);
45         spin_unlock(lock);
46
47         return 0;
48 }
49
50 static inline void proc_list_del(spinlock_t *lock, struct list_head *list,
51                                      struct task_struct *tsk, struct file *file)
52 {
53         struct proc_list *pl;
54
55         spin_lock(lock);
56         list_for_each_entry(pl, list, list_head) {
57                 if (pl->file == file) {
58                         list_del(&pl->list_head);
59                         kfree(pl);
60                         spin_unlock(lock);
61                         return;
62                 }
63         }
64
65         /* correspinding file struct isn't found in the list ???  */
66         printk(KERN_ERR "proc_list_del(): proc_list is inconsistent!\n"
67                         "struct file (%p) not found\n", file);
68         printk(KERN_ERR "listing proc_list...\n");
69         list_for_each_entry(pl, list, list_head)
70                 printk(KERN_ERR "  pid:%d file:%p\n", pl->pid, pl->file);
71         spin_unlock(lock);
72 }
73
74 static inline void proc_list_flush(spinlock_t *lock, struct list_head *list)
75 {
76         struct proc_list *pl;
77
78         spin_lock(lock);
79         while (!list_empty(list)) {
80                 pl = list_entry(list->next, struct proc_list, list_head);
81                 list_del(&pl->list_head);
82                 kfree(pl);
83         }
84         spin_unlock(lock);
85 }
86
87 #endif /* __PLAT_OMAP_DSP_PROCLIST_H */