[darwin] move RunLoop initialization to static variable
This commit is contained in:
4
platform/darwin/src/MGLFoundation.mm
Normal file
4
platform/darwin/src/MGLFoundation.mm
Normal file
@@ -0,0 +1,4 @@
|
||||
#import "MGLFoundation_Private.h"
|
||||
|
||||
/// Initializes the run loop shim that lives on the main thread.
|
||||
mbgl::util::RunLoop mgl_runLoop;
|
||||
5
platform/darwin/src/MGLFoundation_Private.h
Normal file
5
platform/darwin/src/MGLFoundation_Private.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#import "MGLFoundation.h"
|
||||
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
extern mbgl::util::RunLoop mgl_runLoop;
|
||||
@@ -7,7 +7,11 @@
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>;
|
||||
// Use a static function to avoid the static initialization order fiasco.
|
||||
static auto& current() {
|
||||
static ThreadLocal<RunLoop> tl;
|
||||
return tl;
|
||||
};
|
||||
|
||||
class RunLoop::Impl {
|
||||
public:
|
||||
@@ -15,19 +19,20 @@ public:
|
||||
};
|
||||
|
||||
RunLoop* RunLoop::Get() {
|
||||
assert(current.get());
|
||||
return current.get();
|
||||
assert(current().get());
|
||||
return current().get();
|
||||
}
|
||||
|
||||
RunLoop::RunLoop(Type)
|
||||
: impl(std::make_unique<Impl>()) {
|
||||
assert(!current.get());
|
||||
current.set(this);
|
||||
assert(!current().get());
|
||||
current().set(this);
|
||||
impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this));
|
||||
}
|
||||
|
||||
RunLoop::~RunLoop() {
|
||||
current.set(nullptr);
|
||||
assert(current().get());
|
||||
current().set(nullptr);
|
||||
}
|
||||
|
||||
void RunLoop::push(std::shared_ptr<WorkTask> task) {
|
||||
|
||||
@@ -171,6 +171,10 @@
|
||||
556660CA1E1BF3A900E2C41B /* MGLFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 556660C91E1BF3A900E2C41B /* MGLFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
556660D81E1D085500E2C41B /* MGLVersionNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = 556660D71E1D085500E2C41B /* MGLVersionNumber.m */; };
|
||||
556660DB1E1D8E8D00E2C41B /* MGLFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 556660C91E1BF3A900E2C41B /* MGLFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
558DE7A01E5615E400C7916D /* MGLFoundation_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 558DE79E1E5615E400C7916D /* MGLFoundation_Private.h */; };
|
||||
558DE7A11E5615E400C7916D /* MGLFoundation_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 558DE79E1E5615E400C7916D /* MGLFoundation_Private.h */; };
|
||||
558DE7A21E5615E400C7916D /* MGLFoundation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 558DE79F1E5615E400C7916D /* MGLFoundation.mm */; };
|
||||
558DE7A31E5615E400C7916D /* MGLFoundation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 558DE79F1E5615E400C7916D /* MGLFoundation.mm */; };
|
||||
55D8C9961D0F18CE00F42F10 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D8C9951D0F18CE00F42F10 /* libsqlite3.tbd */; };
|
||||
6407D6701E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6407D66F1E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift */; };
|
||||
7E016D7E1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D7C1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h */; };
|
||||
@@ -625,6 +629,8 @@
|
||||
554180411D2E97DE00012372 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
|
||||
556660C91E1BF3A900E2C41B /* MGLFoundation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLFoundation.h; sourceTree = "<group>"; };
|
||||
556660D71E1D085500E2C41B /* MGLVersionNumber.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MGLVersionNumber.m; path = ../../darwin/test/MGLVersionNumber.m; sourceTree = "<group>"; };
|
||||
558DE79E1E5615E400C7916D /* MGLFoundation_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFoundation_Private.h; sourceTree = "<group>"; };
|
||||
558DE79F1E5615E400C7916D /* MGLFoundation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLFoundation.mm; sourceTree = "<group>"; };
|
||||
55D8C9941D0F133500F42F10 /* config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = config.xcconfig; path = ../../build/ios/config.xcconfig; sourceTree = "<group>"; };
|
||||
55D8C9951D0F18CE00F42F10 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
|
||||
6407D66F1E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MGLDocumentationExampleTests.swift; path = ../../darwin/test/MGLDocumentationExampleTests.swift; sourceTree = "<group>"; };
|
||||
@@ -1187,6 +1193,8 @@
|
||||
DAF0D8171DFE6B2800B28378 /* MGLAttributionInfo_Private.h */,
|
||||
DA00FC8D1D5EEB0D009AABC8 /* MGLAttributionInfo.mm */,
|
||||
556660C91E1BF3A900E2C41B /* MGLFoundation.h */,
|
||||
558DE79E1E5615E400C7916D /* MGLFoundation_Private.h */,
|
||||
558DE79F1E5615E400C7916D /* MGLFoundation.mm */,
|
||||
DA8847E21CBAFA5100AB86E3 /* MGLMapCamera.h */,
|
||||
DA8848031CBAFA6200AB86E3 /* MGLMapCamera.mm */,
|
||||
DD0902A41DB18F1B00C5BDCE /* MGLNetworkConfiguration.h */,
|
||||
@@ -1550,6 +1558,7 @@
|
||||
DA8848551CBAFB9800AB86E3 /* MGLLocationManager.h in Headers */,
|
||||
408AA8571DAEDA1700022900 /* NSDictionary+MGLAdditions.h in Headers */,
|
||||
DA88483F1CBAFB8500AB86E3 /* MGLUserLocation.h in Headers */,
|
||||
558DE7A01E5615E400C7916D /* MGLFoundation_Private.h in Headers */,
|
||||
DA88483D1CBAFB8500AB86E3 /* MGLMapView+IBAdditions.h in Headers */,
|
||||
DA17BE301CC4BAC300402C41 /* MGLMapView_Private.h in Headers */,
|
||||
DAD165781CF4CDFF001FF4B9 /* MGLShapeCollection.h in Headers */,
|
||||
@@ -1656,6 +1665,7 @@
|
||||
DABFB86F1CBE9A0F00D62B32 /* MGLMapView.h in Headers */,
|
||||
DA6408DC1DA4E7D300908C90 /* MGLVectorStyleLayer.h in Headers */,
|
||||
353933F31D3FB753003F57D7 /* MGLCircleStyleLayer.h in Headers */,
|
||||
558DE7A11E5615E400C7916D /* MGLFoundation_Private.h in Headers */,
|
||||
3538AA1E1D542239008EC33D /* MGLForegroundStyleLayer.h in Headers */,
|
||||
30E578181DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */,
|
||||
40F887711D7A1E59008ECB67 /* MGLShapeSource_Private.h in Headers */,
|
||||
@@ -2087,6 +2097,7 @@
|
||||
DA8848291CBAFA6200AB86E3 /* MGLStyle.mm in Sources */,
|
||||
357FE2DF1E02D2B20068B753 /* NSCoder+MGLAdditions.mm in Sources */,
|
||||
DA88481C1CBAFA6200AB86E3 /* MGLGeometry.mm in Sources */,
|
||||
558DE7A21E5615E400C7916D /* MGLFoundation.mm in Sources */,
|
||||
3510FFF21D6D9D8C00F413B2 /* NSExpression+MGLAdditions.mm in Sources */,
|
||||
DA88481F1CBAFA6200AB86E3 /* MGLMultiPoint.mm in Sources */,
|
||||
DA88482B1CBAFA6200AB86E3 /* MGLTypes.m in Sources */,
|
||||
@@ -2163,6 +2174,7 @@
|
||||
35305D491D22AA680007D005 /* NSData+MGLAdditions.mm in Sources */,
|
||||
357FE2E01E02D2B20068B753 /* NSCoder+MGLAdditions.mm in Sources */,
|
||||
DAA4E42D1CBB730400178DFB /* MGLAnnotationImage.m in Sources */,
|
||||
558DE7A31E5615E400C7916D /* MGLFoundation.mm in Sources */,
|
||||
3510FFF31D6D9D8C00F413B2 /* NSExpression+MGLAdditions.mm in Sources */,
|
||||
DAA4E4301CBB730400178DFB /* MGLLocationManager.m in Sources */,
|
||||
DAA4E4321CBB730400178DFB /* MGLMapView.mm in Sources */,
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#import "MGLGeometry_Private.h"
|
||||
#import "MGLMultiPoint_Private.h"
|
||||
#import "MGLOfflineStorage_Private.h"
|
||||
#import "MGLFoundation_Private.h"
|
||||
|
||||
#import "NSBundle+MGLAdditions.h"
|
||||
#import "NSDate+MGLAdditions.h"
|
||||
@@ -136,11 +137,6 @@ typedef std::unordered_map<MGLAnnotationTag, MGLAnnotationContext> MGLAnnotation
|
||||
/// Mapping from an annotation object to an annotation tag.
|
||||
typedef std::map<id<MGLAnnotation>, MGLAnnotationTag> MGLAnnotationObjectTagMap;
|
||||
|
||||
/// Initializes the run loop shim that lives on the main thread.
|
||||
void MGLinitializeRunLoop() {
|
||||
static mbgl::util::RunLoop mainRunLoop;
|
||||
}
|
||||
|
||||
mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction *function)
|
||||
{
|
||||
if ( ! function)
|
||||
@@ -394,8 +390,6 @@ public:
|
||||
|
||||
- (void)commonInit
|
||||
{
|
||||
MGLinitializeRunLoop();
|
||||
|
||||
_isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent;
|
||||
_opaque = NO;
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@
|
||||
5548BE781D09E718005DDE81 /* libmbgl-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DAE6C3451CC31D1200DB3429 /* libmbgl-core.a */; };
|
||||
556660C61E1BEA0100E2C41B /* MGLFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 556660C51E1BEA0100E2C41B /* MGLFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
556660D61E1D07E400E2C41B /* MGLVersionNumber.m in Sources */ = {isa = PBXBuildFile; fileRef = 556660D51E1D07E400E2C41B /* MGLVersionNumber.m */; };
|
||||
558DE7A61E56161C00C7916D /* MGLFoundation_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 558DE7A41E56161C00C7916D /* MGLFoundation_Private.h */; };
|
||||
558DE7A71E56161C00C7916D /* MGLFoundation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 558DE7A51E56161C00C7916D /* MGLFoundation.mm */; };
|
||||
558F18221D0B13B100123F46 /* libmbgl-loop.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 558F18211D0B13B000123F46 /* libmbgl-loop.a */; };
|
||||
55D9B4B11D005D3900C1CCE2 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D9B4B01D005D3900C1CCE2 /* libz.tbd */; };
|
||||
DA00FC8A1D5EEAC3009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -321,6 +323,8 @@
|
||||
5548BE7B1D0ACBBD005DDE81 /* libmbgl-loop-darwin.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-loop-darwin.a"; path = "cmake/Debug/libmbgl-loop-darwin.a"; sourceTree = "<group>"; };
|
||||
556660C51E1BEA0100E2C41B /* MGLFoundation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLFoundation.h; sourceTree = "<group>"; };
|
||||
556660D51E1D07E400E2C41B /* MGLVersionNumber.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = MGLVersionNumber.m; path = ../../darwin/test/MGLVersionNumber.m; sourceTree = "<group>"; };
|
||||
558DE7A41E56161C00C7916D /* MGLFoundation_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLFoundation_Private.h; sourceTree = "<group>"; };
|
||||
558DE7A51E56161C00C7916D /* MGLFoundation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLFoundation.mm; sourceTree = "<group>"; };
|
||||
558F18211D0B13B000123F46 /* libmbgl-loop.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libmbgl-loop.a"; path = "../../build/osx/Debug/libmbgl-loop.a"; sourceTree = "<group>"; };
|
||||
55D9B4B01D005D3900C1CCE2 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
|
||||
55FE0E8D1D100A0900FD240B /* config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = config.xcconfig; path = ../../build/macos/config.xcconfig; sourceTree = "<group>"; };
|
||||
@@ -951,6 +955,8 @@
|
||||
DAF0D8151DFE6B1800B28378 /* MGLAttributionInfo_Private.h */,
|
||||
DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */,
|
||||
556660C51E1BEA0100E2C41B /* MGLFoundation.h */,
|
||||
558DE7A41E56161C00C7916D /* MGLFoundation_Private.h */,
|
||||
558DE7A51E56161C00C7916D /* MGLFoundation.mm */,
|
||||
DAE6C34D1CC31E0400DB3429 /* MGLMapCamera.h */,
|
||||
DAE6C36E1CC31E2A00DB3429 /* MGLMapCamera.mm */,
|
||||
DD0902B01DB1AC6400C5BDCE /* MGLNetworkConfiguration.h */,
|
||||
@@ -1071,6 +1077,7 @@
|
||||
DA35A2CF1CCAAED300E826B2 /* NSValue+MGLAdditions.h in Headers */,
|
||||
DAE6C3A61CC31E9400DB3429 /* MGLMapViewDelegate.h in Headers */,
|
||||
DAE6C38B1CC31E2A00DB3429 /* MGLOfflinePack_Private.h in Headers */,
|
||||
558DE7A61E56161C00C7916D /* MGLFoundation_Private.h in Headers */,
|
||||
DACC22141CF3D3E200D220D9 /* MGLFeature.h in Headers */,
|
||||
3538AA231D542685008EC33D /* MGLStyleLayer.h in Headers */,
|
||||
DAE6C35C1CC31E0400DB3429 /* MGLGeometry.h in Headers */,
|
||||
@@ -1307,6 +1314,7 @@
|
||||
35602BFB1D3EA99F0050646F /* MGLFillStyleLayer.mm in Sources */,
|
||||
DAE6C3931CC31E2A00DB3429 /* MGLShape.mm in Sources */,
|
||||
352742861D4C244700A1ECE6 /* MGLRasterSource.mm in Sources */,
|
||||
558DE7A71E56161C00C7916D /* MGLFoundation.mm in Sources */,
|
||||
DAE6C39D1CC31E2A00DB3429 /* NSString+MGLAdditions.m in Sources */,
|
||||
3598195A1E02F611008FC139 /* NSCoder+MGLAdditions.mm in Sources */,
|
||||
DAE6C3941CC31E2A00DB3429 /* MGLStyle.mm in Sources */,
|
||||
|
||||
@@ -105,11 +105,6 @@ NSImage *MGLDefaultMarkerImage() {
|
||||
return [[NSImage alloc] initWithContentsOfFile:path];
|
||||
}
|
||||
|
||||
/// Initializes the run loop shim that lives on the main thread.
|
||||
void MGLinitializeRunLoop() {
|
||||
static mbgl::util::RunLoop mainRunLoop;
|
||||
}
|
||||
|
||||
/// Converts a media timing function into a unit bezier object usable in mbgl.
|
||||
mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction *function) {
|
||||
if (!function) {
|
||||
@@ -246,8 +241,6 @@ public:
|
||||
}
|
||||
|
||||
- (void)commonInit {
|
||||
MGLinitializeRunLoop();
|
||||
|
||||
_isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent;
|
||||
|
||||
// Set up cross-platform controllers and resources.
|
||||
|
||||
Reference in New Issue
Block a user