Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / ex / list.c
1 /* $Id$
2  * reactos list functions emulation of libcaptive
3  * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "reactos/ddk/exfuncs.h"
23 #include <glib/gmessages.h>
24 #include "reactos/ntos/types.h" /* for PSLIST_ENTRY */
25
26
27 /**
28  * InterlockedPopEntrySList:
29  * @ListHead: List to remove the first entry from.
30  * %NULL value is forbidden.
31  *
32  * Function will remove the first item of @ListHead list and returns its entry @PSLIST_ENTRY.
33  * Function should behave in multiprocessing safe way - not handled by libcaptive.
34  *
35  * Returns: The first entry item of @ListHead. Passed @ListHead will have the first item removed.
36  * %NULL value if the list was empty.
37  */
38 PSLIST_ENTRY InterlockedPopEntrySList(IN PSLIST_HEADER ListHead)
39 {
40 KSPIN_LOCK SpinLock;
41
42         g_return_val_if_fail(ListHead!=NULL,NULL);
43
44         /* TODO:thread */
45         KeInitializeSpinLock(&SpinLock);
46         return ExInterlockedPopEntrySList(ListHead,&SpinLock);
47 }
48
49
50 /**
51  * InterlockedPushEntrySList:
52  * @ListHead: List to insert @ListEntry item to its start.
53  * %NULL value is forbidden.
54  * @ListEntry: List item to insert to @ListHead.
55  * %NULL value is forbidden.
56  *
57  * Function will insert @ListEntry as the first item of @ListHead list.
58  * Function should behave in multiprocessing safe way - not handled by libcaptive.
59  *
60  * Returns: The previous first entry item of @ListHead (currently the second one).
61  * Passed @ListHead will have the first item @ListEntry.
62  * Returns %NULL value if the list was empty.
63  */
64 PSLIST_ENTRY InterlockedPushEntrySList(IN PSLIST_HEADER ListHead,IN PSLIST_ENTRY ListEntry)
65 {
66 KSPIN_LOCK SpinLock;
67
68         g_return_val_if_fail(ListHead!=NULL,NULL);
69         g_return_val_if_fail(ListEntry!=NULL,NULL);
70
71         /* TODO:thread */
72         KeInitializeSpinLock(&SpinLock);
73         return ExInterlockedPushEntrySList(ListHead,ListEntry,&SpinLock);
74 }