2 * Server-side event management
4 * Copyright (C) 1998 Alexandre Julliard
13 #include "server/thread.h"
17 struct object obj
; /* object header */
18 int manual_reset
; /* is it a manual reset event? */
19 int signaled
; /* event has been signaled */
22 static void event_dump( struct object
*obj
, int verbose
);
23 static int event_signaled( struct object
*obj
, struct thread
*thread
);
24 static int event_satisfied( struct object
*obj
, struct thread
*thread
);
25 static void event_destroy( struct object
*obj
);
27 static const struct object_ops event_ops
=
41 struct object
*create_event( const char *name
, int manual_reset
, int initial_state
)
45 if (!(event
= (struct event
*)create_named_object( name
, &event_ops
, sizeof(*event
) )))
47 if (GET_ERROR() != ERROR_ALREADY_EXISTS
)
49 /* initialize it if it didn't already exist */
50 event
->manual_reset
= manual_reset
;
51 event
->signaled
= initial_state
;
56 int open_event( unsigned int access
, int inherit
, const char *name
)
58 return open_object( name
, &event_ops
, access
, inherit
);
61 int pulse_event( int handle
)
65 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
66 EVENT_MODIFY_STATE
, &event_ops
)))
69 /* wake up all waiters if manual reset, a single one otherwise */
70 wake_up( &event
->obj
, !event
->manual_reset
);
72 release_object( event
);
76 int set_event( int handle
)
80 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
81 EVENT_MODIFY_STATE
, &event_ops
)))
84 /* wake up all waiters if manual reset, a single one otherwise */
85 wake_up( &event
->obj
, !event
->manual_reset
);
86 release_object( event
);
90 int reset_event( int handle
)
94 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
95 EVENT_MODIFY_STATE
, &event_ops
)))
98 release_object( event
);
102 static void event_dump( struct object
*obj
, int verbose
)
104 struct event
*event
= (struct event
*)obj
;
105 assert( obj
->ops
== &event_ops
);
106 printf( "Event manual=%d signaled=%d\n", event
->manual_reset
, event
->signaled
);
109 static int event_signaled( struct object
*obj
, struct thread
*thread
)
111 struct event
*event
= (struct event
*)obj
;
112 assert( obj
->ops
== &event_ops
);
113 return event
->signaled
;
116 static int event_satisfied( struct object
*obj
, struct thread
*thread
)
118 struct event
*event
= (struct event
*)obj
;
119 assert( obj
->ops
== &event_ops
);
120 /* Reset if it's an auto-reset event */
121 if (!event
->manual_reset
) event
->signaled
= 0;
122 return 0; /* Not abandoned */
125 static void event_destroy( struct object
*obj
)
127 struct event
*event
= (struct event
*)obj
;
128 assert( obj
->ops
== &event_ops
);