[darwin] Use explicit initialization rather than global static variables for the default RunLoop

When linking Mapbox GL as a static library, the object file (MGLFoundation.o) containing the global static variable initialization was not linked into the resulting binary since it was not referenced. This resulted in the RunLoop not being initialized in the main thread.

Reverts 03a14ff000
This commit is contained in:
Konstantin Käfer
2017-03-08 14:50:49 -08:00
committed by Jesse Bounds
parent 01f126cbc6
commit e9cf787779
3 changed files with 7 additions and 2 deletions

View File

@@ -1,4 +1,6 @@
#import "MGLFoundation_Private.h"
/// Initializes the run loop shim that lives on the main thread.
mbgl::util::RunLoop mgl_runLoop;
void MGLInitializeRunLoop() {
static mbgl::util::RunLoop runLoop;
}

View File

@@ -2,4 +2,4 @@
#include <mbgl/util/run_loop.hpp>
extern mbgl::util::RunLoop mgl_runLoop;
void MGLInitializeRunLoop();

View File

@@ -1,5 +1,6 @@
#import "MGLOfflineStorage_Private.h"
#import "MGLFoundation_Private.h"
#import "MGLAccountManager_Private.h"
#import "MGLGeometry_Private.h"
#import "MGLNetworkConfiguration.h"
@@ -170,6 +171,8 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = MGLOfflinePackUserInfoK
}
- (instancetype)init {
MGLInitializeRunLoop();
if (self = [super init]) {
NSURL *cacheURL = [[self class] cacheURLIncludingSubdirectory:YES];
NSString *cachePath = cacheURL.path ?: @"";