Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / ke / event.c
1 /* $Id$
2  * reactos events 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/kefuncs.h"        /* self */
23 #include <glib/gmessages.h>
24 #include "reactos/ddk/exfuncs.h"        /* for InterlockedExchange() */
25
26
27 /**
28  * KeInitializeEvent:
29  * @Event: Event to initialize.
30  * %NULL value is forbidden.
31  * @Type: %NotificationEvent or %SynchronizationEvent.
32  * @State: Initial signal state.
33  *
34  * Initalizes a kernel event. Currently libcaptive doesn't use multithreading
35  * and thus this function is a NOP now.
36  */
37 VOID KeInitializeEvent(PKEVENT Event,EVENT_TYPE Type,BOOLEAN State)
38 {
39         g_return_if_fail(Event!=NULL);
40         g_return_if_fail(Type==NotificationEvent || Type==SynchronizationEvent);
41
42         /* TODO:thread */
43 }
44
45
46 /**
47  * KeSetEvent:
48  * @Event: Event to set its signal state on.
49  * %NULL value is forbidden.
50  * @Increment: Thread priority increase during wait; ignored by libcaptive.
51  * @Wait: Do not release locks, KeWait() is required afterwards; ignored by libcaptive.
52  *
53  * Sets the signal state of @Event. Currently libcaptive doesn't use multithreading
54  * and thus this function will just set the @Event's internal state and it returns
55  * the previous value.
56  * See also KeResetEvent(), KeClearEvent().
57  *
58  * Returns: Previous signal state value of @Event.
59  */
60 LONG KeSetEvent(PKEVENT Event,KPRIORITY Increment,BOOLEAN Wait)
61 {
62         g_return_val_if_fail(Event!=NULL,0);
63
64         /* TODO:thread */
65         return InterlockedExchange(&(Event->Header.SignalState),1);
66 }
67
68
69 /**
70  * KeResetEvent:
71  * @Event: Event to clear its signal state off.
72  * %NULL value is forbidden.
73  *
74  * Clears the signal state of @Event. See also KeSetEvent().
75  * Use KeClearEvent() if you do not need the previous signal state of @Event.
76  *
77  * Returns: Previous signal state value of @Event.
78  */
79 LONG KeResetEvent(PKEVENT Event)
80 {
81         g_return_val_if_fail(Event!=NULL,0);
82
83         return InterlockedExchange(&(Event->Header.SignalState),0);
84 }
85
86
87 /**
88  * KeClearEvent:
89  * @Event: Event to clear its signal state off.
90  * %NULL value is forbidden.
91  *
92  * Clears the signal state of @Event. See also KeSetEvent().
93  * Use KeResetEvent() if you need the previous signal state of @Event.
94  */
95 VOID KeClearEvent(PKEVENT Event)
96 {
97         g_return_if_fail(Event!=NULL);
98
99         Event->Header.SignalState=FALSE;
100 }