From 6e11c9c9f817ee37da4ccfa5f50d2cca71de949e Mon Sep 17 00:00:00 2001 From: bmagistro Date: Sun, 31 Dec 2023 09:19:28 -0500 Subject: Make default context thread_local (#286) * Make default context thread_local Signed-off-by: Ben Magistro Co-authored-by: Vincent Richard --- src/vmime/parsingContext.cpp | 2 +- src/vmime/parsingContext.hpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/vmime/parsingContext.cpp b/src/vmime/parsingContext.cpp index 0975e3d7..2ffdfa87 100644 --- a/src/vmime/parsingContext.cpp +++ b/src/vmime/parsingContext.cpp @@ -42,7 +42,7 @@ parsingContext::parsingContext(const parsingContext& ctx) parsingContext& parsingContext::getDefaultContext() { - static parsingContext ctx; + static thread_local parsingContext ctx; return ctx; } diff --git a/src/vmime/parsingContext.hpp b/src/vmime/parsingContext.hpp index d13d94ef..1107fd57 100644 --- a/src/vmime/parsingContext.hpp +++ b/src/vmime/parsingContext.hpp @@ -42,6 +42,12 @@ struct headerParseRecoveryMethod { }; /** Holds configuration parameters used for parsing messages. + * + * Within vmime there are some functions that only utilize the default parsing + * context. If you need to manipulate the behavior of the parser for those + * functions, it is suggested to get the default context and make the + * appropriate set calls to adjust the behavior. You can also use this + * instance when making function calls the require a context be passed in. */ class VMIME_EXPORT parsingContext : public context { @@ -50,9 +56,10 @@ public: parsingContext(); parsingContext(const parsingContext& ctx); - /** Returns the default context used for parsing messages. + /** Returns the default context used for parsing messages. The context + * is scoped as a thread local variable. * - * @return a reference to the default parsing context + * @return a reference to the default parsing context for that thread */ static parsingContext& getDefaultContext(); -- cgit v1.2.3