From 2c8d978c72e799b81045cf5815d6354797c8c4bd Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Sat, 1 Mar 2025 21:41:35 +0100 Subject: [PATCH] prunratelimited => prun with throttling --- pclsync/plocalnotify.c | 4 ++-- pclsync/plocalscan.c | 4 ++-- pclsync/{prunratelimit.c => prunthrottled.c} | 12 ++++++------ pclsync/{prunratelimit.h => prunthrottled.h} | 5 ++--- pclsync/pstatus.c | 6 +++--- 5 files changed, 15 insertions(+), 16 deletions(-) rename pclsync/{prunratelimit.c => prunthrottled.c} (91%) rename pclsync/{prunratelimit.h => prunthrottled.h} (89%) diff --git a/pclsync/plocalnotify.c b/pclsync/plocalnotify.c index a3aacc4..96f45db 100644 --- a/pclsync/plocalnotify.c +++ b/pclsync/plocalnotify.c @@ -35,16 +35,16 @@ #include #include #include +#include #include #include #include "plocalnotify.h" -#include "pfile.h" +#include "pfoldersync.h" #include "plibs.h" #include "prun.h" #include "plist.h" #include "plocalscan.h" -#include "psettings.h" #define NOTIFY_MSG_ADD 0 #define NOTIFY_MSG_DEL 1 diff --git a/pclsync/plocalscan.c b/pclsync/plocalscan.c index 1687ef4..f98a715 100644 --- a/pclsync/plocalscan.c +++ b/pclsync/plocalscan.c @@ -46,7 +46,7 @@ #include "plocalnotify.h" #include "plocalscan.h" #include "ppathstatus.h" -#include "prunratelimit.h" +#include "prunthrottled.h" #include "psettings.h" #include "pssl.h" #include "pstatus.h" @@ -1234,7 +1234,7 @@ static void psync_do_wake_localscan() { } void psync_wake_localscan() { - psync_run_ratelimited("wake localscan", psync_do_wake_localscan, + prun_throttled("wake localscan", psync_do_wake_localscan, PSYNC_LOCALSCAN_MIN_INTERVAL, 0); } diff --git a/pclsync/prunratelimit.c b/pclsync/prunthrottled.c similarity index 91% rename from pclsync/prunratelimit.c rename to pclsync/prunthrottled.c index 43fdceb..fee88cf 100644 --- a/pclsync/prunratelimit.c +++ b/pclsync/prunthrottled.c @@ -29,7 +29,7 @@ DAMAGE. */ -#include "prunratelimit.h" +#include "prunthrottled.h" #include "plibs.h" #include "ptimer.h" #include "ptree.h" @@ -38,7 +38,7 @@ typedef struct { psync_tree tree; - psync_run_ratelimit_callback0 call; + prun_throttle_cb call; const char *name; unsigned char scheduled; } psync_rr_tree_node; @@ -46,10 +46,10 @@ typedef struct { static pthread_mutex_t task_mutex = PTHREAD_MUTEX_INITIALIZER; static psync_tree *tasks = PSYNC_TREE_EMPTY; -static void psync_run_ratelimited_timer(psync_timer_t timer, void *ptr) { +static void ratelimit_timer(psync_timer_t timer, void *ptr) { psync_rr_tree_node *node; const char *name; - psync_run_ratelimit_callback0 call; + prun_throttle_cb call; int run; node = (psync_rr_tree_node *)ptr; pthread_mutex_lock(&task_mutex); @@ -72,7 +72,7 @@ static void psync_run_ratelimited_timer(psync_timer_t timer, void *ptr) { } } -void psync_run_ratelimited(const char *name, psync_run_ratelimit_callback0 call, +void prun_throttled(const char *name, prun_throttle_cb call, uint32_t minintervalsec, int runinthread) { psync_tree *tr, **addto; psync_rr_tree_node *node; @@ -128,6 +128,6 @@ void psync_run_ratelimited(const char *name, psync_run_ratelimit_callback0 call, debug(D_NOTICE, "running %s on this thread", name); call(); } - psync_timer_register(psync_run_ratelimited_timer, minintervalsec, node); + psync_timer_register(ratelimit_timer, minintervalsec, node); } } diff --git a/pclsync/prunratelimit.h b/pclsync/prunthrottled.h similarity index 89% rename from pclsync/prunratelimit.h rename to pclsync/prunthrottled.h index 434b049..13e34df 100644 --- a/pclsync/prunratelimit.h +++ b/pclsync/prunthrottled.h @@ -34,9 +34,8 @@ #include -typedef void (*psync_run_ratelimit_callback0)(); +typedef void (*prun_throttle_cb)(); -void psync_run_ratelimited(const char *name, psync_run_ratelimit_callback0 call, - uint32_t minintervalsec, int runinthread); +void prun_throttled(const char *name, prun_throttle_cb call, uint32_t minintervalsec, int runinthread); #endif diff --git a/pclsync/pstatus.c b/pclsync/pstatus.c index 28b4046..6cdb0c0 100644 --- a/pclsync/pstatus.c +++ b/pclsync/pstatus.c @@ -33,7 +33,7 @@ #include "pstatus.h" #include "pfstasks.h" #include "plibs.h" -#include "prunratelimit.h" +#include "prunthrottled.h" #include "psettings.h" #include "ptask.h" #include "putil.h" @@ -232,11 +232,11 @@ void pstatus_upload_recalc() { } void pstatus_download_recalc_async() { - psync_run_ratelimited("recalc download", proc_recalc_download, PSYNC_MIN_INTERVAL_RECALC_DOWNLOAD, 1); + prun_throttled("recalc download", proc_recalc_download, PSYNC_MIN_INTERVAL_RECALC_DOWNLOAD, 1); } void pstatus_upload_recalc_async() { - psync_run_ratelimited("recalc upload", proc_recalc_upload, PSYNC_MIN_INTERVAL_RECALC_UPLOAD, 1); + prun_throttled("recalc upload", proc_recalc_upload, PSYNC_MIN_INTERVAL_RECALC_UPLOAD, 1); } uint32_t pstatus_get(uint32_t statusid) {