]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Make ESIParser::Parsers a std::list (#138)
authorAmos Jeffries <yadij@users.noreply.github.com>
Tue, 30 Jan 2018 13:13:38 +0000 (02:13 +1300)
committerAmos Jeffries <yadij@users.noreply.github.com>
Fri, 2 Feb 2018 04:45:24 +0000 (17:45 +1300)
... and Replace ESIParser::Parsers global with ESIParser::GetRegistry() lookup function

Resolves assertions on shutdown and an outstanding TODO.

src/esi/Parser.cc
src/esi/Parser.h

index 4d81ef59c60255d36d92d7b1dba56d5247899b3c..cf4e34cd15fffeace0c85d5ebf8653086335f4bc 100644 (file)
 #include "fatal.h"
 
 char *ESIParser::Type = NULL;
-ESIParser::Register *ESIParser::Parsers = NULL;
 ESIParser::Register *ESIParser::Parser = NULL;
 
+std::list<ESIParser::Register *> &
+ESIParser::GetRegistry()
+{
+    static std::list<ESIParser::Register *> 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);
 }
 
index bb5de185bf0e3c0f9cefdee41f2662d4eb6731d6..fd83ceac174010135b054a27f161f14d0cd2dbd4 100644 (file)
@@ -9,6 +9,10 @@
 #ifndef SQUID_ESIPARSER_H
 #define SQUID_ESIPARSER_H
 
+#include "base/RefCount.h"
+
+#include <list>
+
 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<Register *> & GetRegistry();
 };
 
 class ESIParser::Register
@@ -59,7 +59,6 @@ public:
 
     const char *name;
     ESIParser::Pointer (*newParser)(ESIParserClient *aClient);
-    Register * next;
 };
 
 #define EsiParserDefinition(ThisClass) \