44// / @file
55// / @brief Delegate library options header file.
66
7+ // Pull in user config if provided, otherwise use library defaults.
8+ // To provide your own config: -DDMQ_USER_CONFIG="path/to/DelegateMQConfig.h"
9+ #ifdef DMQ_USER_CONFIG
10+ #include DMQ_USER_CONFIG
11+ #endif
12+ #include " DelegateMQConfig_Default.h"
13+
714#if defined(_WIN32) || defined(_WIN64)
815 #ifndef WIN32_LEAN_AND_MEAN
916 #define WIN32_LEAN_AND_MEAN
5966#endif
6067
6168#include < chrono>
62- #if defined(DMQ_THREAD_STDLIB) || defined(DMQ_THREAD_WIN32) || defined(DMQ_THREAD_QT)
69+ #if defined(DMQ_THREAD_STDLIB) || defined(DMQ_THREAD_WIN32) || defined(DMQ_THREAD_QT) || \
70+ defined (DMQ_THREAD_FREERTOS) || defined(DMQ_THREAD_THREADX) || \
71+ defined(DMQ_THREAD_ZEPHYR) || defined(DMQ_THREAD_CMSIS_RTOS2)
6372 #include <mutex>
6473#endif
6574
7281 // Windows / Linux / macOS / Qt (Standard Library)
7382 #include < condition_variable>
7483#elif defined(DMQ_THREAD_FREERTOS)
75- #include < mutex>
7684 #include " port/os/freertos/FreeRTOSClock.h"
7785 #include " port/os/freertos/FreeRTOSMutex.h"
7886 #include " port/os/freertos/FreeRTOSConditionVariable.h"
7987#elif defined(DMQ_THREAD_THREADX)
80- #include < mutex>
8188 #include " port/os/threadx/ThreadXClock.h"
8289 #include " port/os/threadx/ThreadXMutex.h"
8390 #include " port/os/threadx/ThreadXConditionVariable.h"
@@ -107,6 +114,28 @@ namespace dmq
107114 PortableLockGuard& operator =(const PortableLockGuard&) = delete ;
108115 };
109116
117+ // --- PORTABLE SCOPED LOCK ---
118+ // Maps to std::scoped_lock on all known threaded ports (desktop + RTOS).
119+ // All RTOS mutex types satisfy BasicLockable (lock/unlock), so std::scoped_lock
120+ // works with them directly. Falls back to a no-op for DMQ_THREAD_NONE and for
121+ // any unrecognized bare-metal build where no thread model is defined.
122+ #if defined(DMQ_THREAD_STDLIB) || defined(DMQ_THREAD_WIN32) || defined(DMQ_THREAD_QT) || \
123+ defined (DMQ_THREAD_FREERTOS) || defined(DMQ_THREAD_THREADX) || \
124+ defined(DMQ_THREAD_ZEPHYR) || defined(DMQ_THREAD_CMSIS_RTOS2)
125+ template <typename... M>
126+ using ScopedLock = std::scoped_lock<M...>;
127+ #else
128+ // No-op: DMQ_THREAD_NONE or no thread model defined (bare-metal, single-threaded)
129+ template <typename ... M>
130+ class ScopedLock {
131+ public:
132+ explicit ScopedLock (M&...) noexcept {}
133+ ~ScopedLock () noexcept = default ;
134+ ScopedLock (const ScopedLock&) = delete ;
135+ ScopedLock& operator =(const ScopedLock&) = delete ;
136+ };
137+ #endif
138+
110139 // @TODO: Change aliases to switch clock type globally if necessary
111140
112141 // --- CLOCK SELECTION ---
@@ -140,23 +169,31 @@ namespace dmq
140169 using TimePoint = typename Clock::time_point;
141170
142171 // / @brief Default timeout for the TIMEOUT queue-full policy across all Thread ports.
143- // / Override per-thread at construction or project-wide before including this header .
144- inline constexpr std::chrono::seconds DEFAULT_DISPATCH_TIMEOUT{2 };
172+ // / Override via DMQ_DEFAULT_DISPATCH_TIMEOUT in DelegateMQConfig.h .
173+ inline constexpr std::chrono::seconds DEFAULT_DISPATCH_TIMEOUT{DMQ_DEFAULT_DISPATCH_TIMEOUT };
145174
146175 // --- RESOURCE LIMITS & SBO CONFIGURATION ---
147-
176+
148177 // / @brief Max timers processed in one tick without heap allocation.
149- inline constexpr size_t MAX_TIMER_EXPIRED = 16 ;
178+ // / Override via DMQ_MAX_TIMER_EXPIRED in delegatemqconfig.h.
179+ inline constexpr size_t MAX_TIMER_EXPIRED = DMQ_MAX_TIMER_EXPIRED;
150180
151- // / @brief Signal Small-Buffer Optimization (SBO) count.
181+ // / @brief Signal Small-Buffer Optimization (SBO) count.
152182 // / Signals with <= this many subscribers are invoked heap-free.
153- inline constexpr size_t SIGNAL_SBO_COUNT = 8 ;
183+ // / Override via DMQ_SIGNAL_SBO_COUNT in delegatemqconfig.h.
184+ inline constexpr size_t SIGNAL_SBO_COUNT = DMQ_SIGNAL_SBO_COUNT;
154185
155186 // / @brief Default internal queue size for all dmq::os::Thread ports.
156- inline constexpr size_t DEFAULT_QUEUE_SIZE = 20 ;
187+ // / Override via DMQ_DEFAULT_QUEUE_SIZE in delegatemqconfig.h.
188+ inline constexpr size_t DEFAULT_QUEUE_SIZE = DMQ_DEFAULT_QUEUE_SIZE;
157189
158190 // / @brief Max number of threads that can be monitored by the watchdog.
159- inline constexpr size_t MAX_WATCHDOG_THREADS = 16 ;
191+ // / Override via DMQ_MAX_WATCHDOG_THREADS in delegatemqconfig.h.
192+ inline constexpr size_t MAX_WATCHDOG_THREADS = DMQ_MAX_WATCHDOG_THREADS;
193+
194+ // / @brief Max number of remote Participants the DataBus can hold without heap allocation.
195+ // / Override via DMQ_MAX_PARTICIPANTS in delegatemqconfig.h.
196+ inline constexpr size_t MAX_PARTICIPANTS = DMQ_MAX_PARTICIPANTS;
160197
161198 // --- MUTEX / LOCK SELECTION ---
162199#if defined(DMQ_THREAD_STDLIB) || defined(DMQ_THREAD_WIN32) || defined(DMQ_THREAD_QT)
@@ -241,13 +278,15 @@ namespace dmq
241278 // Use stl_allocator fixed-block allocator for dynamic storage allocation
242279 #include " extras/allocator/xstring.h"
243280 #include " extras/allocator/xlist.h"
281+ #include " extras/allocator/xmap.h"
244282 #include " extras/allocator/xsstream.h"
245283 #include " extras/allocator/stl_allocator.h"
246284 #include " extras/allocator/xnew.h"
247285 #include " extras/allocator/xmake_shared.h"
248286#else
249287 #include < string>
250288 #include < list>
289+ #include < map>
251290 #include < sstream>
252291 #include < memory>
253292 #include < utility>
@@ -288,6 +327,13 @@ namespace dmq
288327 delete p;
289328 }
290329 }
330+
331+ // Fallback xmap/xmultimap — use std::map when fixed-block allocator is disabled
332+ template <typename Key, typename Value, typename Alloc = std::allocator<std::pair<const Key, Value>>>
333+ using xmap = std::map<Key, Value, std::less<Key>, Alloc>;
334+
335+ template <typename Key, typename Value, typename Alloc = std::allocator<std::pair<const Key, Value>>>
336+ using xmultimap = std::multimap<Key, Value, std::less<Key>, Alloc>;
291337#endif
292338
293339// @TODO: Select the desired logging (see Port.cmake).
@@ -303,4 +349,4 @@ namespace dmq
303349 #define LOG_ERROR (...) do {} while (0 )
304350#endif
305351
306- #endif // _DELEGATE_OPT_H
352+ #endif // _DELEGATE_OPT_H
0 commit comments