浏览代码

BUG: #82345 - JLIB - fix thread unsafeness in dumping namecount table (not enabled by default anyway)

Signed-off-by: Jake Smith <jake.smith@lexisnexis.com>
Jake Smith 14 年之前
父节点
当前提交
894ef438de
共有 2 个文件被更改,包括 23 次插入9 次删除
  1. 1 0
      system/jlib/jsuperhash.hpp
  2. 22 9
      system/jlib/jutil.cpp

+ 1 - 0
system/jlib/jsuperhash.hpp

@@ -423,6 +423,7 @@ friend class AtomRefTable;
 typedef const char constcharptr;
 class jlib_decl AtomRefTable : public SuperHashTableOf<HashKeyElement, constcharptr>
 {
+protected:
     CriticalSection crit;
     bool nocase;
 

+ 22 - 9
system/jlib/jutil.cpp

@@ -2002,10 +2002,29 @@ StringBuffer &genUUID(StringBuffer &out, bool nocase)
 
 //==============================================================
 
-static AtomRefTable *namedCountHT;
+class jlib_decl CNameCountTable : public AtomRefTable
+{
+public:
+    CNameCountTable(bool _nocase=false) : AtomRefTable(_nocase) { }
+    StringBuffer &dump(StringBuffer &str)
+    {
+        SuperHashIteratorOf<HashKeyElement> iter(*this);
+        CriticalBlock b(crit);
+        ForEach (iter)
+        {
+            HashKeyElement &elem = iter.query();
+            str.append(elem.get()).append(", count = ").append(elem.queryReferences()).newline();
+        }
+        return str;
+    }
+};
+
+static CNameCountTable *namedCountHT;
+
+
 MODULE_INIT(INIT_PRIORITY_SYSTEM)
 {
-    namedCountHT = new AtomRefTable;
+    namedCountHT = new CNameCountTable;
     return true;
 }
 
@@ -2029,13 +2048,7 @@ void NamedCount::set(const char *name)
 
 StringBuffer &dumpNamedCounts(StringBuffer &str)
 {
-    SuperHashIteratorOf<HashKeyElement> iter(*namedCountHT);
-    ForEach (iter)
-    {
-        HashKeyElement &e = iter.query();
-        str.append(e.get()).append(", count = ").append(e.queryReferences()).newline();
-    }
-    return str;
+    return namedCountHT->dump(str);
 }
 
 //==============================================================