From 25f07549a132703079369c0ff387837bd84e9790 Mon Sep 17 00:00:00 2001
From: Clifford Wolf <clifford@clifford.at>
Date: Sat, 30 Jun 2018 07:47:04 +0200
Subject: Refactor IdString::global_ctx

Signed-off-by: Clifford Wolf <clifford@clifford.at>
---
 common/nextpnr.cc |  2 +-
 common/nextpnr.h  | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/common/nextpnr.cc b/common/nextpnr.cc
index ee0c13ba..5af83a15 100644
--- a/common/nextpnr.cc
+++ b/common/nextpnr.cc
@@ -21,7 +21,7 @@
 
 NEXTPNR_NAMESPACE_BEGIN
 
-BaseCtx *IdString::global_ctx = nullptr;
+std::unordered_set<BaseCtx*> IdString::global_ctx;
 
 void IdString::set(const BaseCtx *ctx, const std::string &s)
 {
diff --git a/common/nextpnr.h b/common/nextpnr.h
index 36a8dc75..af092475 100644
--- a/common/nextpnr.h
+++ b/common/nextpnr.h
@@ -50,8 +50,6 @@ struct IdString
 {
     int index = 0;
 
-    static BaseCtx *global_ctx;
-
     static void initialize_arch(const BaseCtx *ctx);
     static void initialize_add(const BaseCtx *ctx, const char *s, int idx);
 
@@ -76,10 +74,12 @@ struct IdString
 
     // --- deprecated old API ---
 
+    static std::unordered_set<BaseCtx*> global_ctx;
+
     const std::string &global_str() const __attribute__((deprecated))
     {
-        assert(global_ctx != nullptr);
-        return str(global_ctx);
+        assert(global_ctx.size() == 1);
+        return str(*global_ctx.begin());
     }
 };
 
@@ -204,8 +204,7 @@ struct BaseCtx
 
     BaseCtx()
     {
-        // assert(IdString::global_ctx == nullptr);
-        IdString::global_ctx = this;
+        IdString::global_ctx.insert(this);
 
         idstring_str_to_idx = new std::unordered_map<std::string, int>;
         idstring_idx_to_str = new std::vector<const std::string *>;
@@ -215,6 +214,7 @@ struct BaseCtx
 
     ~BaseCtx()
     {
+        IdString::global_ctx.erase(this);
         delete idstring_str_to_idx;
         delete idstring_idx_to_str;
     }
-- 
cgit v1.2.3