Skip to content

Commit 38b419e

Browse files
committed
Factor out reference-counting code from PlatformApple*
into PlatformAppleSimulator. This is legal because that is the only entry point for the Terminate/Initialize functions.
1 parent e486921 commit 38b419e

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -514,24 +514,19 @@ static llvm::StringRef GetXcodeSDKDir(std::string preferred,
514514
return sdk;
515515
}
516516

517-
static unsigned g_ios_initialize_count = 0;
518517
static const char *g_ios_plugin_name = "ios-simulator";
519518
static const char *g_ios_description = "iPhone simulator platform plug-in.";
520519

521520
/// IPhone Simulator Plugin.
522521
struct PlatformiOSSimulator {
523522
static void Initialize() {
524-
if (g_ios_initialize_count++ == 0) {
525-
PluginManager::RegisterPlugin(ConstString(g_ios_plugin_name),
526-
g_ios_description,
527-
PlatformiOSSimulator::CreateInstance);
528-
}
523+
PluginManager::RegisterPlugin(ConstString(g_ios_plugin_name),
524+
g_ios_description,
525+
PlatformiOSSimulator::CreateInstance);
529526
}
530527

531528
static void Terminate() {
532-
if (g_ios_initialize_count > 0)
533-
if (--g_ios_initialize_count == 0)
534-
PluginManager::UnregisterPlugin(PlatformiOSSimulator::CreateInstance);
529+
PluginManager::UnregisterPlugin(PlatformiOSSimulator::CreateInstance);
535530
}
536531

537532
static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
@@ -567,24 +562,19 @@ struct PlatformiOSSimulator {
567562
}
568563
};
569564

570-
static unsigned g_tvos_initialize_count = 0;
571565
static const char *g_tvos_plugin_name = "tvos-simulator";
572566
static const char *g_tvos_description = "tvOS simulator platform plug-in.";
573567

574568
/// Apple TV Simulator Plugin.
575569
struct PlatformAppleTVSimulator {
576570
static void Initialize() {
577-
if (g_tvos_initialize_count++ == 0) {
578-
PluginManager::RegisterPlugin(ConstString(g_tvos_plugin_name),
579-
g_tvos_description,
580-
PlatformAppleTVSimulator::CreateInstance);
581-
}
571+
PluginManager::RegisterPlugin(ConstString(g_tvos_plugin_name),
572+
g_tvos_description,
573+
PlatformAppleTVSimulator::CreateInstance);
582574
}
583575

584576
static void Terminate() {
585-
if (g_tvos_initialize_count > 0)
586-
if (--g_tvos_initialize_count == 0)
587-
PluginManager::UnregisterPlugin(PlatformAppleTVSimulator::CreateInstance);
577+
PluginManager::UnregisterPlugin(PlatformAppleTVSimulator::CreateInstance);
588578
}
589579

590580
static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
@@ -611,26 +601,21 @@ struct PlatformAppleTVSimulator {
611601
};
612602

613603

614-
static unsigned g_watchos_initialize_count = 0;
615604
static const char *g_watchos_plugin_name = "watchos-simulator";
616605
static const char *g_watchos_description =
617606
"Apple Watch simulator platform plug-in.";
618607

619608
/// Apple Watch Simulator Plugin.
620609
struct PlatformAppleWatchSimulator {
621610
static void Initialize() {
622-
if (g_watchos_initialize_count++ == 0) {
623-
PluginManager::RegisterPlugin(
624-
ConstString(g_watchos_plugin_name), g_watchos_description,
625-
PlatformAppleWatchSimulator::CreateInstance);
626-
}
611+
PluginManager::RegisterPlugin(ConstString(g_watchos_plugin_name),
612+
g_watchos_description,
613+
PlatformAppleWatchSimulator::CreateInstance);
627614
}
628615

629616
static void Terminate() {
630-
if (g_watchos_initialize_count > 0)
631-
if (--g_watchos_initialize_count == 0)
632-
PluginManager::UnregisterPlugin(
633-
PlatformAppleWatchSimulator::CreateInstance);
617+
PluginManager::UnregisterPlugin(
618+
PlatformAppleWatchSimulator::CreateInstance);
634619
}
635620

636621
static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
@@ -657,18 +642,25 @@ struct PlatformAppleWatchSimulator {
657642
};
658643

659644

645+
static unsigned g_initialize_count = 0;
646+
660647
// Static Functions
661648
void PlatformAppleSimulator::Initialize() {
662-
PlatformDarwin::Initialize();
663-
PlatformiOSSimulator::Initialize();
664-
PlatformAppleTVSimulator::Initialize();
665-
PlatformAppleWatchSimulator::Initialize();
649+
if (g_initialize_count++ == 0) {
650+
PlatformDarwin::Initialize();
651+
PlatformiOSSimulator::Initialize();
652+
PlatformAppleTVSimulator::Initialize();
653+
PlatformAppleWatchSimulator::Initialize();
654+
}
666655
}
667656

668657
void PlatformAppleSimulator::Terminate() {
669-
PlatformAppleWatchSimulator::Terminate();
670-
PlatformAppleTVSimulator::Terminate();
671-
PlatformiOSSimulator::Terminate();
672-
PlatformDarwin::Terminate();
658+
if (g_initialize_count > 0)
659+
if (--g_initialize_count == 0) {
660+
PlatformAppleWatchSimulator::Terminate();
661+
PlatformAppleTVSimulator::Terminate();
662+
PlatformiOSSimulator::Terminate();
663+
PlatformDarwin::Terminate();
664+
}
673665
}
674666

0 commit comments

Comments
 (0)