Add Initialize/Terminate method to Platform base plugin

Platform holds a smart pointer to each platform object created in a
static variable what cause the platform destructors called only on
program exit when other static variables are not availables. With this
change the destructors are called on lldb_private::Terminate()

+ Fix DebuggerRefCount handling in ScriptInterpreterPython

Differential Revision: http://reviews.llvm.org/D7590

llvm-svn: 228944
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index f4c387a..97be084 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -29,7 +29,9 @@
 
 using namespace lldb;
 using namespace lldb_private;
-    
+
+static uint32_t g_initialize_count = 0;
+
 // Use a singleton function for g_local_platform_sp to avoid init
 // constructors since LLDB is often part of a shared library
 static PlatformSP&
@@ -76,6 +78,25 @@
 }
 
 void
+Platform::Initialize ()
+{
+    g_initialize_count++;
+}
+
+void
+Platform::Terminate ()
+{
+    if (g_initialize_count > 0)
+    {
+        if (--g_initialize_count == 0)
+        {
+            Mutex::Locker locker(GetPlatformListMutex ());
+            GetPlatformList().clear();
+        }
+    }
+}
+
+void
 Platform::SetHostPlatform (const lldb::PlatformSP &platform_sp)
 {
     // The native platform should use its static void Platform::Initialize()