#ifndef HID_BPF_ASYNC_MAX_CTX #error"HID_BPF_ASYNC_MAX_CTX should be set to the maximum number of concurrent async functions" #endif/* HID_BPF_ASYNC_MAX_CTX */
#define CLOCK_MONOTONIC 1
typedefint (*hid_bpf_async_callback_t)(void *map, int *key, void *value);
/* * internal cb for starting the delayed work callback in a workqueue.
*/ staticint __start_wq_timer_cb(void *map, int *key, void *value)
{ struct hid_bpf_async_map_elem *e = (struct hid_bpf_async_map_elem *)value;
bpf_wq_start(&e->wq, 0);
return 0;
}
staticint hid_bpf_async_find_empty_key(void)
{ int i;
staticint hid_bpf_async_delayed_call(struct hid_bpf_ctx *hctx, u64 milliseconds, int key,
hid_bpf_async_callback_t wq_cb)
{ struct hid_bpf_async_map_elem *elem; int err;
elem = bpf_map_lookup_elem(&hid_bpf_async_ctx_map, &key); if (!elem) return -EINVAL;
bpf_spin_lock(&elem->lock); /* The wq must be: * - HID_BPF_ASYNC_STATE_INITIALIZED -> it's been initialized and ready to be called * - HID_BPF_ASYNC_STATE_RUNNING -> possible re-entry from the wq itself
*/ if (elem->state != HID_BPF_ASYNC_STATE_INITIALIZED &&
elem->state != HID_BPF_ASYNC_STATE_RUNNING) {
bpf_spin_unlock(&elem->lock); return -EINVAL;
}
elem->state = HID_BPF_ASYNC_STATE_STARTING;
bpf_spin_unlock(&elem->lock);
elem->hid = hctx->hid->id;
err = bpf_wq_set_callback(&elem->wq, wq_cb, 0); if (err) return err;
if (milliseconds) { /* needed for every call because a cancel might unset this */
err = bpf_timer_set_callback(&elem->t, __start_wq_timer_cb); if (err) return err;
err = bpf_timer_start(&elem->t, ms_to_ns(milliseconds), 0); if (err) return err;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.