From 9a5c2bc14dde13477c24f51e672651bdf3abd649 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 2 Oct 2024 00:32:49 +0100 Subject: [PATCH] Add comment on thread safety to mosquitto_broker.h Closes #3080 --- include/mosquitto_broker.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/mosquitto_broker.h b/include/mosquitto_broker.h index 9a6ba1e4ab..854eb0bdc8 100644 --- a/include/mosquitto_broker.h +++ b/include/mosquitto_broker.h @@ -39,6 +39,20 @@ extern "C" { #include #include +/* + * Topic: Threads + * Unless otherwise noted, the functions provided for plugins to use should + * only be called in the context of the main broker thread. This is the thread + * which calls your callbacks. + * + * If you have a separate thread running in your plugin which needs to + * interact with the broker that isn't tied to a specific callback, the + * easiest way to handle this is to use the `tick` event and pass your data + * structure as the userdata argument when you register the callback. Note + * that you still need to ensure appropriate synchronisation between your + * thread and the broker thread using e.g. a mutex. + */ + struct mosquitto; typedef struct mqtt5__property mosquitto_property;