ReactOS 0.4.17-dev-1190-g4c812f4
notify.h File Reference
#include <uacpi/types.h>
Include dependency graph for notify.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

uacpi_status uacpi_install_notify_handler (uacpi_namespace_node *node, uacpi_notify_handler handler, uacpi_handle handler_context)
 
uacpi_status uacpi_uninstall_notify_handler (uacpi_namespace_node *node, uacpi_notify_handler handler)
 

Function Documentation

◆ uacpi_install_notify_handler()

uacpi_status uacpi_install_notify_handler ( uacpi_namespace_node *  node,
uacpi_notify_handler  handler,
uacpi_handle  handler_context 
)

Install a Notify() handler to a device node. A handler installed to the root node will receive all notifications, even if a device already has a dedicated Notify handler. 'handler_context' is passed to the handler on every invocation.

Definition at line 182 of file notify.c.

186{
190 uacpi_device_notify_handler *new_handler;
191
193
194 if (node == uacpi_namespace_root()) {
195 obj = g_uacpi_rt_ctx.root_object;
196 } else {
200 );
202 return ret;
203 }
204
207 goto out_no_mutex;
208
209 handlers = obj->handlers;
210
213 goto out;
214 }
215
216 new_handler = uacpi_kernel_alloc_zeroed(sizeof(*new_handler));
217 if (uacpi_unlikely(new_handler == UACPI_NULL)) {
219 goto out;
220 }
221
222 new_handler->callback = handler;
223 new_handler->user_context = handler_context;
224 new_handler->next = handlers->notify_head;
225
226 uacpi_atomic_store_ptr(&handlers->notify_head, new_handler);
227
228out:
230out_no_mutex:
231 if (node != uacpi_namespace_root())
233
234 return ret;
235}
static uacpi_status uacpi_release_native_mutex(uacpi_handle mtx)
Definition: mutex.h:44
static uacpi_status uacpi_acquire_native_mutex(uacpi_handle mtx)
Definition: mutex.h:32
#define uacpi_atomic_store_ptr(ptr_to_ptr, value)
Definition: atomic.h:344
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7708
#define UACPI_ENSURE_INIT_LEVEL_AT_LEAST(lvl)
Definition: context.h:127
struct uacpi_runtime_context g_uacpi_rt_ctx
Definition: uacpi.c:18
uacpi_status uacpi_namespace_node_acquire_object_typed(const uacpi_namespace_node *node, uacpi_object_type_bits, uacpi_object **out_obj)
Definition: namespace.c:677
#define uacpi_kernel_alloc_zeroed
Definition: stdlib.h:127
uacpi_namespace_node * uacpi_namespace_root(void)
Definition: namespace.c:264
#define uacpi_unlikely(expr)
Definition: compiler.h:88
#define UACPI_NULL
Definition: types.h:33
#define uacpi_unlikely_error(expr)
Definition: status.h:50
uacpi_status
Definition: status.h:10
@ UACPI_STATUS_OUT_OF_MEMORY
Definition: status.h:13
@ UACPI_STATUS_ALREADY_EXISTS
Definition: status.h:20
@ UACPI_OBJECT_PROCESSOR_BIT
Definition: types.h:146
@ UACPI_OBJECT_THERMAL_ZONE_BIT
Definition: types.h:147
@ UACPI_OBJECT_DEVICE_BIT
Definition: types.h:140
@ UACPI_INIT_LEVEL_SUBSYSTEM_INITIALIZED
Definition: types.h:72
void uacpi_object_unref(uacpi_object *obj)
Definition: types.c:761
return ret
Definition: mutex.c:147
static uacpi_device_notify_handler * handler_container(uacpi_handlers *handlers, uacpi_notify_handler target_handler)
Definition: notify.c:166
static uacpi_handle notify_mutex
Definition: notify.c:13
static xmlCharEncodingHandlerPtr * handlers
Definition: encoding.c:1380
struct uacpi_device_notify_handler * next
Definition: types.h:95
uacpi_notify_handler callback
Definition: types.h:93
uacpi_handle user_context
Definition: types.h:94
Definition: dlist.c:348
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

◆ uacpi_uninstall_notify_handler()

uacpi_status uacpi_uninstall_notify_handler ( uacpi_namespace_node *  node,
uacpi_notify_handler  handler 
)

Uninstall a Notify() handler previously installed to a device node. The handler is guaranteed to not be running, and to never be invoked again once this function returns.

NOTE: this waits for all of the in-flight notifications to complete, and therefore must not be called from a notify handler, any other work scheduled via uacpi_kernel_schedule_work, an address space handler, or with the global lock held.

Definition at line 237 of file notify.c.

240{
244 uacpi_device_notify_handler *prev_handler, *containing = UACPI_NULL;
245
247
248 if (node == uacpi_namespace_root()) {
249 obj = g_uacpi_rt_ctx.root_object;
250 } else {
254 );
256 return ret;
257 }
258
261 goto out_no_mutex;
262
263 handlers = obj->handlers;
264
265 containing = handler_container(handlers, handler);
266 if (containing == UACPI_NULL) {
268 goto out;
269 }
270
271 prev_handler = handlers->notify_head;
272
273 // Are we the last linked handler?
274 if (prev_handler == containing) {
275 uacpi_atomic_store_ptr(&handlers->notify_head, containing->next);
276 goto out;
277 }
278
279 // Nope, we're somewhere in the middle. Do a search.
280 while (prev_handler) {
281 if (prev_handler->next == containing) {
282 uacpi_atomic_store_ptr(&prev_handler->next, containing->next);
283 goto out;
284 }
285
286 prev_handler = prev_handler->next;
287 }
288
289out:
291out_no_mutex:
292 if (node != uacpi_namespace_root())
294
296 /*
297 * The handler is no longer reachable, but a notification that started
298 * before we unlinked it might still be about to call it. Wait for
299 * those to finish, this also guarantees that the handler is never
300 * invoked again after we return.
301 *
302 * This must be done without the notify mutex held: the work that we
303 * are waiting for needs it in order to dispatch a Notify().
304 */
306 uacpi_free(containing, sizeof(*containing));
307 }
308
309 return ret;
310}
#define uacpi_free(mem, _)
Definition: stdlib.h:96
#define uacpi_likely_success(expr)
Definition: status.h:54
@ UACPI_STATUS_NOT_FOUND
Definition: status.h:17
uacpi_status uacpi_kernel_wait_for_work_completion(void)
Definition: uacpiosl.c:235