This commit is contained in:
Evgeny committed 2026-06-02 21:05:06 +03:00
1 parent 226a5744b5
commit 4556f327c2
10 files changed
+63 -94

No files matched your search

+17 -24
View File
@@ -291,13 +291,15 @@ static void check_waiters(struct ll_queue* q) {
struct queue_waiter_handle* h = waiter->handle;
if (h) h->internal = NULL;
queue_threshold_callback_fn cb = waiter->callback;
void* arg = waiter->callback_arg;
u_free(waiter);
if (h) {
if (cb) {
DEBUG_DEBUG(DEBUG_CATEGORY_LL_QUEUE, "check_waiters: waking head waiter, count=%d<=%d, bytes=%zu<=%zu",
q->count, q->threshold_max_packets, q->total_bytes, q->threshold_max_bytes);
h->callback(q, h->callback_arg);
cb(q, arg);
}
}
@@ -554,29 +556,18 @@ void queue_set_threshold(struct ll_queue* q, int max_packets, size_t max_bytes)
q->threshold_max_bytes = max_bytes;
}
void queue_waiter_handle_init(struct queue_waiter_handle* h,
queue_threshold_callback_fn callback, void* arg) {
if (!h) return;
h->internal = NULL;
h->callback = callback;
h->callback_arg = arg;
}
int queue_waiter_wait(struct ll_queue* q, struct queue_waiter_handle* h,
queue_threshold_callback_fn callback, void* arg) {
if (!q || !h) return -1;
if (h->internal) queue_waiter_cancel(q, h);
int queue_waiter_wait(struct ll_queue* q, struct queue_waiter_handle* h) {
if (!q || !h) return 1;
if (h->internal) {
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] queue_waiter_wait: waiter already registered", q->name);
return 1;
}
// Проверить условие немедленно
if (q->count <= q->threshold_max_packets
&& (q->threshold_max_bytes == 0 || q->total_bytes <= q->threshold_max_bytes)) {
h->callback(q, h->callback_arg);
callback(q, arg);
return 1;
}
struct queue_waiter* waiter = u_malloc(sizeof(struct queue_waiter));
if (!waiter) {
DEBUG_ERROR(DEBUG_CATEGORY_LL_QUEUE, "[%s] queue_waiter_wait: u_malloc failed", q->name);
@@ -584,11 +575,13 @@ int queue_waiter_wait(struct ll_queue* q, struct queue_waiter_handle* h) {
}
waiter->next = NULL;
waiter->handle = h;
waiter->callback = callback;
waiter->callback_arg = arg;
h->internal = waiter;
if (q->waiter_tail) q->waiter_tail->next = waiter; else q->waiter_head = waiter;
q->waiter_tail = waiter;
return 0;
}