From: Scott Worley Date: Tue, 10 Oct 2023 08:14:15 +0000 (-0700) Subject: client: Make the queue size bounds configurable X-Git-Tag: v0.1.0~29 X-Git-Url: http://git.scottworley.com/tattlekey/commitdiff_plain/a36c278f05a806c9ced1a96b04eae0e6b9d8a5d5?ds=inline client: Make the queue size bounds configurable --- diff --git a/client/config.c b/client/config.c index 8a31cf5..0e1a86d 100644 --- a/client/config.c +++ b/client/config.c @@ -24,3 +24,18 @@ u32_t config_minimum_seconds_between_button_presses = 1; /* Send each report multiple times. */ uint config_resend_count = 5; + +/* These control the size of the per-send-count press queues. +When the button is pressed more than config_maximum_queue_size times +within the resend interval, some presses will be reported fewer +than config_resend_count times. This is usually fine because it's +the old, longest-delayed, most-redundant reports that get dropped; +fresh, timely reports of new button presses will not get anywhere near +config_resend_count in a resend interval because the early resend internals +are so short. */ +uint config_maximum_queue_size = 512; + +/* This is paranoia about unanticipated delays. Setting this to zero +would probably be fine, but imposing a minimum queue size is an easy +safety measure. */ +uint config_minimum_queue_size = 32; diff --git a/client/config.h b/client/config.h index 744e586..23f04d5 100644 --- a/client/config.h +++ b/client/config.h @@ -28,4 +28,19 @@ extern u32_t config_minimum_seconds_between_button_presses; /* Send each report multiple times. */ extern uint config_resend_count; +/* These control the size of the per-send-count press queues. +When the button is pressed more than config_maximum_queue_size times +within the resend interval, some presses will be reported fewer +than config_resend_count times. This is usually fine because it's +the old, longest-delyed, most-redundant reports that get dropped; +fresh, timely reports of new button presses will not get anywhere near +config_resend_count in a resend interval because the early resend interals +are so short. */ +extern uint config_maximum_queue_size; + +/* This is paranoia about unanticipated delays. Setting this to zero +would pobably be fine, but imposing a minimum queue size is an easy +safety measure. */ +extern uint config_minimum_queue_size; + #endif diff --git a/client/press.c b/client/press.c index cec1709..6c46ae9 100644 --- a/client/press.c +++ b/client/press.c @@ -29,9 +29,10 @@ press_pile_t *create_press_pile() { pp->presses = (queue_t *)xcalloc(config_resend_count, sizeof(queue_t)); pp->sleeps = (queue_t **)xcalloc(config_resend_count, sizeof(queue_t *)); for (int i = 0; i < config_resend_count; i++) { - uint element_count = 1 << i; - element_count = MAX(element_count, 32); - element_count = MIN(element_count, 512); + const uint paranoid_safety_fudge = 10; + uint element_count = paranoid_safety_fudge + (1 << i); + element_count = MAX(element_count, config_minimum_queue_size); + element_count = MIN(element_count, config_maximum_queue_size); queue_init(&pp->presses[i], sizeof(press_t), element_count); } pp->sleeps_heap =