From f5f77865257de1a173a9333addb2a2dbdb9b82ce Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Wed, 31 Jan 2018 02:13:38 +1300 Subject: [PATCH] Make ESIParser::Parsers a std::list (#138) ... and Replace ESIParser::Parsers global with ESIParser::GetRegistry() lookup function Resolves assertions on shutdown and an outstanding TODO. --- src/esi/Parser.cc | 23 ++++++++++++++--------- src/esi/Parser.h | 11 +++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/esi/Parser.cc b/src/esi/Parser.cc index 4d81ef59c6..cf4e34cd15 100644 --- a/src/esi/Parser.cc +++ b/src/esi/Parser.cc @@ -13,19 +13,27 @@ #include "fatal.h" char *ESIParser::Type = NULL; -ESIParser::Register *ESIParser::Parsers = NULL; ESIParser::Register *ESIParser::Parser = NULL; +std::list & +ESIParser::GetRegistry() +{ + static std::list parsers; + return parsers; +} + ESIParser::Pointer ESIParser::NewParser(ESIParserClient *aClient) { if (Parser == NULL) { - Parser = Parsers; + Parser = GetRegistry().front(); // if type name matters, use it if (strcasecmp(Type, "auto") != 0) { - while (Parser && strcasecmp(Parser->name, Type) != 0) - Parser = Parser->next; + for (auto *p : GetRegistry()) { + if (p && strcasecmp(p->name, Type) != 0) + Parser = p; + } } if (Parser == NULL) @@ -37,14 +45,11 @@ ESIParser::NewParser(ESIParserClient *aClient) ESIParser::Register::Register(const char *_name, ESIParser::Pointer (*_newParser)(ESIParserClient *aClient)) : name(_name), newParser(_newParser) { - this->next = ESIParser::Parsers; - ESIParser::Parsers = this; + ESIParser::GetRegistry().emplace_back(this); } ESIParser::Register::~Register() { - // TODO: support random-order deregistration - assert(ESIParser::Parsers == this); - ESIParser::Parsers = next; + ESIParser::GetRegistry().remove(this); } diff --git a/src/esi/Parser.h b/src/esi/Parser.h index bb5de185bf..fd83ceac17 100644 --- a/src/esi/Parser.h +++ b/src/esi/Parser.h @@ -9,6 +9,10 @@ #ifndef SQUID_ESIPARSER_H #define SQUID_ESIPARSER_H +#include "base/RefCount.h" + +#include + class ESIParserClient { public: @@ -19,8 +23,6 @@ public: virtual ~ESIParserClient() {}; }; -#include "base/RefCount.h" - class ESIParser : public RefCountable { public: @@ -45,9 +47,7 @@ protected: private: static Register *Parser; - static Register *Parsers; - -public: + static std::list & GetRegistry(); }; class ESIParser::Register @@ -59,7 +59,6 @@ public: const char *name; ESIParser::Pointer (*newParser)(ESIParserClient *aClient); - Register * next; }; #define EsiParserDefinition(ThisClass) \ -- 2.47.2