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
=
42 struct object
*create_event( const char *name
, int manual_reset
, int initial_state
)
46 if (!(event
= (struct event
*)create_named_object( name
, &event_ops
, sizeof(*event
) )))
48 if (GET_ERROR() != ERROR_ALREADY_EXISTS
)
50 /* initialize it if it didn't already exist */
51 event
->manual_reset
= manual_reset
;
52 event
->signaled
= initial_state
;
57 int open_event( unsigned int access
, int inherit
, const char *name
)
59 return open_object( name
, &event_ops
, access
, inherit
);
62 int pulse_event( int handle
)
66 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
67 EVENT_MODIFY_STATE
, &event_ops
)))
70 /* wake up all waiters if manual reset, a single one otherwise */
71 wake_up( &event
->obj
, !event
->manual_reset
);
73 release_object( event
);
77 int set_event( int handle
)
81 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
82 EVENT_MODIFY_STATE
, &event_ops
)))
85 /* wake up all waiters if manual reset, a single one otherwise */
86 wake_up( &event
->obj
, !event
->manual_reset
);
87 release_object( event
);
91 int reset_event( int handle
)
95 if (!(event
= (struct event
*)get_handle_obj( current
->process
, handle
,
96 EVENT_MODIFY_STATE
, &event_ops
)))
99 release_object( event
);
103 static void event_dump( struct object
*obj
, int verbose
)
105 struct event
*event
= (struct event
*)obj
;
106 assert( obj
->ops
== &event_ops
);
107 fprintf( stderr
, "Event manual=%d signaled=%d name='%s'\n",
108 event
->manual_reset
, event
->signaled
,
109 get_object_name( &event
->obj
) );
112 static int event_signaled( struct object
*obj
, struct thread
*thread
)
114 struct event
*event
= (struct event
*)obj
;
115 assert( obj
->ops
== &event_ops
);
116 return event
->signaled
;
119 static int event_satisfied( struct object
*obj
, struct thread
*thread
)
121 struct event
*event
= (struct event
*)obj
;
122 assert( obj
->ops
== &event_ops
);
123 /* Reset if it's an auto-reset event */
124 if (!event
->manual_reset
) event
->signaled
= 0;
125 return 0; /* Not abandoned */
128 static void event_destroy( struct object
*obj
)
130 struct event
*event
= (struct event
*)obj
;
131 assert( obj
->ops
== &event_ops
);