@@ -207,7 +207,7 @@ static void _CFBundleAddToTables(CFBundleRef bundle) {
207
207
208
208
CFStringRef bundleID = CFBundleGetIdentifier (bundle );
209
209
210
- pthread_mutex_lock (& CFBundleGlobalDataLock );
210
+ __CFLock (& CFBundleGlobalDataLock );
211
211
212
212
// Add to the _allBundles list
213
213
if (!_allBundles ) {
@@ -266,7 +266,7 @@ static void _CFBundleAddToTables(CFBundleRef bundle) {
266
266
CFRelease (bundlesWithThisID );
267
267
}
268
268
}
269
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
269
+ __CFUnlock (& CFBundleGlobalDataLock );
270
270
}
271
271
272
272
static void _CFBundleRemoveFromTables (CFBundleRef bundle , CFURLRef bundleURL , CFStringRef bundleID ) {
@@ -278,7 +278,7 @@ static void _CFBundleRemoveFromTables(CFBundleRef bundle, CFURLRef bundleURL, CF
278
278
// Unique bundles aren't in the tables anyway
279
279
if (bundle -> _isUnique ) return ;
280
280
281
- pthread_mutex_lock (& CFBundleGlobalDataLock );
281
+ __CFLock (& CFBundleGlobalDataLock );
282
282
// Remove from the table of all bundles
283
283
if (_allBundles ) {
284
284
CFIndex i = CFArrayGetFirstIndexOfValue (_allBundles , CFRangeMake (0 , CFArrayGetCount (_allBundles )), bundle );
@@ -300,14 +300,14 @@ static void _CFBundleRemoveFromTables(CFBundleRef bundle, CFURLRef bundleURL, CF
300
300
if (0 == CFArrayGetCount (bundlesWithThisID )) CFDictionaryRemoveValue (_bundlesByIdentifier , bundleID );
301
301
}
302
302
}
303
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
303
+ __CFUnlock (& CFBundleGlobalDataLock );
304
304
}
305
305
#endif
306
306
}
307
307
308
308
static CFBundleRef _CFBundleGetFromTables (CFStringRef bundleID ) {
309
309
CFBundleRef result = NULL , bundle ;
310
- pthread_mutex_lock (& CFBundleGlobalDataLock );
310
+ __CFLock (& CFBundleGlobalDataLock );
311
311
if (_bundlesByIdentifier && bundleID ) {
312
312
// Note that this array is maintained in descending order by version number
313
313
CFArrayRef bundlesWithThisID = (CFArrayRef )CFDictionaryGetValue (_bundlesByIdentifier , bundleID );
@@ -324,7 +324,7 @@ static CFBundleRef _CFBundleGetFromTables(CFStringRef bundleID) {
324
324
}
325
325
}
326
326
}
327
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
327
+ __CFUnlock (& CFBundleGlobalDataLock );
328
328
return result ;
329
329
}
330
330
@@ -342,14 +342,14 @@ static CFBundleRef _CFBundleCopyFromTablesForURL(CFURLRef url) {
342
342
Since the main bundle is not part of the bundle tables, we can support this scenario by having the _bundlesByURL data structure hold the bundle for URL "/S/L/F/Foo.framework/Foo" and _mainBundle (in CFBundle_Main.c) hold the bundle for URL "/S/L/F/Foo.framework/food".
343
343
*/
344
344
CFBundleRef result = NULL ;
345
- pthread_mutex_lock (& CFBundleGlobalDataLock );
345
+ __CFLock (& CFBundleGlobalDataLock );
346
346
if (_bundlesByURL ) result = (CFBundleRef )CFDictionaryGetValue (_bundlesByURL , url );
347
347
if (result && !result -> _url ) {
348
348
result = NULL ;
349
349
CFDictionaryRemoveValue (_bundlesByURL , url );
350
350
}
351
351
if (result ) CFRetain (result );
352
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
352
+ __CFUnlock (& CFBundleGlobalDataLock );
353
353
return result ;
354
354
}
355
355
@@ -478,15 +478,15 @@ static void _CFBundleArrayApplyFlushBundleCaches(const void *value, void *unused
478
478
#endif
479
479
480
480
CF_PRIVATE void _CFBundleFlushAllBundleCaches (void ) {
481
- pthread_mutex_lock (& CFBundleGlobalDataLock );
481
+ __CFLock (& CFBundleGlobalDataLock );
482
482
#if __OBJC__ || __OBJC2__
483
483
for (id value in (id )_allBundles ) {
484
484
_CFBundleFlushBundleCachesAlreadyLocked ((CFBundleRef )value , true);
485
485
}
486
486
#else
487
487
CFArrayApplyFunction (_allBundles , CFRangeMake (0 , CFArrayGetCount (_allBundles )), & _CFBundleArrayApplyFlushBundleCaches , NULL );
488
488
#endif
489
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
489
+ __CFUnlock (& CFBundleGlobalDataLock );
490
490
}
491
491
492
492
CFBundleRef CFBundleGetBundleWithIdentifier (CFStringRef bundleID ) {
@@ -1145,7 +1145,7 @@ Boolean _CFBundleLoadExecutableAndReturnError(CFBundleRef bundle, Boolean forceG
1145
1145
CFURLRef executableURL = CFBundleCopyExecutableURL (bundle );
1146
1146
1147
1147
1148
- pthread_mutex_lock (& (bundle -> _bundleLoadingLock ));
1148
+ __CFLock (& (bundle -> _bundleLoadingLock ));
1149
1149
if (!executableURL ) bundle -> _binaryType = __CFBundleNoBinary ;
1150
1150
// make sure we know whether bundle is already loaded or not
1151
1151
#if defined(BINARY_SUPPORT_DLFCN )
@@ -1163,30 +1163,30 @@ Boolean _CFBundleLoadExecutableAndReturnError(CFBundleRef bundle, Boolean forceG
1163
1163
if (executableURL ) CFRelease (executableURL );
1164
1164
1165
1165
if (bundle -> _isLoaded ) {
1166
- pthread_mutex_unlock (& (bundle -> _bundleLoadingLock ));
1166
+ __CFUnlock (& (bundle -> _bundleLoadingLock ));
1167
1167
// Remove from the scheduled unload set if we are there.
1168
- pthread_mutex_lock (& CFBundleGlobalDataLock );
1168
+ __CFLock (& CFBundleGlobalDataLock );
1169
1169
if (_bundlesToUnload ) CFSetRemoveValue (_bundlesToUnload , bundle );
1170
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
1170
+ __CFUnlock (& CFBundleGlobalDataLock );
1171
1171
return true;
1172
1172
}
1173
1173
1174
1174
// Unload bundles scheduled for unloading
1175
1175
if (!_scheduledBundlesAreUnloading ) {
1176
- pthread_mutex_unlock (& (bundle -> _bundleLoadingLock ));
1176
+ __CFUnlock (& (bundle -> _bundleLoadingLock ));
1177
1177
_CFBundleUnloadScheduledBundles ();
1178
- pthread_mutex_lock (& (bundle -> _bundleLoadingLock ));
1178
+ __CFLock (& (bundle -> _bundleLoadingLock ));
1179
1179
}
1180
1180
1181
1181
if (bundle -> _isLoaded ) {
1182
- pthread_mutex_unlock (& (bundle -> _bundleLoadingLock ));
1182
+ __CFUnlock (& (bundle -> _bundleLoadingLock ));
1183
1183
// Remove from the scheduled unload set if we are there.
1184
- pthread_mutex_lock (& CFBundleGlobalDataLock );
1184
+ __CFLock (& CFBundleGlobalDataLock );
1185
1185
if (_bundlesToUnload ) CFSetRemoveValue (_bundlesToUnload , bundle );
1186
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
1186
+ __CFUnlock (& CFBundleGlobalDataLock );
1187
1187
return true;
1188
1188
}
1189
- pthread_mutex_unlock (& (bundle -> _bundleLoadingLock ));
1189
+ __CFUnlock (& (bundle -> _bundleLoadingLock ));
1190
1190
1191
1191
switch (bundle -> _binaryType ) {
1192
1192
#if defined(BINARY_SUPPORT_DLFCN )
@@ -1264,7 +1264,7 @@ Boolean CFBundlePreflightExecutable(CFBundleRef bundle, CFErrorRef *error) {
1264
1264
#endif
1265
1265
CFURLRef executableURL = CFBundleCopyExecutableURL (bundle );
1266
1266
1267
- pthread_mutex_lock (& (bundle -> _bundleLoadingLock ));
1267
+ __CFLock (& (bundle -> _bundleLoadingLock ));
1268
1268
if (!executableURL ) bundle -> _binaryType = __CFBundleNoBinary ;
1269
1269
// make sure we know whether bundle is already loaded or not
1270
1270
#if defined(BINARY_SUPPORT_DLFCN )
@@ -1282,10 +1282,10 @@ Boolean CFBundlePreflightExecutable(CFBundleRef bundle, CFErrorRef *error) {
1282
1282
if (executableURL ) CFRelease (executableURL );
1283
1283
1284
1284
if (bundle -> _isLoaded ) {
1285
- pthread_mutex_unlock (& (bundle -> _bundleLoadingLock ));
1285
+ __CFUnlock (& (bundle -> _bundleLoadingLock ));
1286
1286
return true;
1287
1287
}
1288
- pthread_mutex_unlock (& (bundle -> _bundleLoadingLock ));
1288
+ __CFUnlock (& (bundle -> _bundleLoadingLock ));
1289
1289
1290
1290
switch (bundle -> _binaryType ) {
1291
1291
#if defined(BINARY_SUPPORT_DLFCN )
@@ -1349,19 +1349,19 @@ void CFBundleUnloadExecutable(CFBundleRef bundle) {
1349
1349
if (!bundle -> _isLoaded ) return ;
1350
1350
1351
1351
// Remove from the scheduled unload set if we are there.
1352
- if (!_scheduledBundlesAreUnloading ) pthread_mutex_lock (& CFBundleGlobalDataLock );
1352
+ if (!_scheduledBundlesAreUnloading ) __CFLock (& CFBundleGlobalDataLock );
1353
1353
if (_bundlesToUnload ) CFSetRemoveValue (_bundlesToUnload , bundle );
1354
- if (!_scheduledBundlesAreUnloading ) pthread_mutex_unlock (& CFBundleGlobalDataLock );
1354
+ if (!_scheduledBundlesAreUnloading ) __CFUnlock (& CFBundleGlobalDataLock );
1355
1355
1356
1356
// Give the plugIn code a chance to realize this...
1357
1357
_CFPlugInWillUnload (bundle );
1358
1358
1359
- pthread_mutex_lock (& (bundle -> _bundleLoadingLock ));
1359
+ __CFLock (& (bundle -> _bundleLoadingLock ));
1360
1360
if (!bundle -> _isLoaded ) {
1361
- pthread_mutex_unlock (& (bundle -> _bundleLoadingLock ));
1361
+ __CFUnlock (& (bundle -> _bundleLoadingLock ));
1362
1362
return ;
1363
1363
}
1364
- pthread_mutex_unlock (& (bundle -> _bundleLoadingLock ));
1364
+ __CFUnlock (& (bundle -> _bundleLoadingLock ));
1365
1365
1366
1366
switch (bundle -> _binaryType ) {
1367
1367
#if defined(BINARY_SUPPORT_DYLD )
@@ -1392,25 +1392,25 @@ void CFBundleUnloadExecutable(CFBundleRef bundle) {
1392
1392
}
1393
1393
1394
1394
CF_PRIVATE void _CFBundleScheduleForUnloading (CFBundleRef bundle ) {
1395
- pthread_mutex_lock (& CFBundleGlobalDataLock );
1395
+ __CFLock (& CFBundleGlobalDataLock );
1396
1396
if (!_bundlesToUnload ) {
1397
1397
CFSetCallBacks nonRetainingCallbacks = kCFTypeSetCallBacks ;
1398
1398
nonRetainingCallbacks .retain = NULL ;
1399
1399
nonRetainingCallbacks .release = NULL ;
1400
1400
_bundlesToUnload = CFSetCreateMutable (kCFAllocatorSystemDefault , 0 , & nonRetainingCallbacks );
1401
1401
}
1402
1402
CFSetAddValue (_bundlesToUnload , bundle );
1403
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
1403
+ __CFUnlock (& CFBundleGlobalDataLock );
1404
1404
}
1405
1405
1406
1406
CF_PRIVATE void _CFBundleUnscheduleForUnloading (CFBundleRef bundle ) {
1407
- pthread_mutex_lock (& CFBundleGlobalDataLock );
1407
+ __CFLock (& CFBundleGlobalDataLock );
1408
1408
if (_bundlesToUnload ) CFSetRemoveValue (_bundlesToUnload , bundle );
1409
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
1409
+ __CFUnlock (& CFBundleGlobalDataLock );
1410
1410
}
1411
1411
1412
1412
static void _CFBundleUnloadScheduledBundles (void ) {
1413
- pthread_mutex_lock (& CFBundleGlobalDataLock );
1413
+ __CFLock (& CFBundleGlobalDataLock );
1414
1414
if (_bundlesToUnload ) {
1415
1415
CFIndex i , c = CFSetGetCount (_bundlesToUnload );
1416
1416
if (c > 0 ) {
@@ -1425,7 +1425,7 @@ static void _CFBundleUnloadScheduledBundles(void) {
1425
1425
CFAllocatorDeallocate (kCFAllocatorSystemDefault , unloadThese );
1426
1426
}
1427
1427
}
1428
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
1428
+ __CFUnlock (& CFBundleGlobalDataLock );
1429
1429
}
1430
1430
1431
1431
#pragma mark -
@@ -1566,7 +1566,7 @@ static void _CFBundleEnsureBundleExistsForImagePath(CFStringRef imagePath, Boole
1566
1566
// NB doFinalProcessing must be false here, see below
1567
1567
bundle = _CFBundleCreate (kCFAllocatorSystemDefault , curURL , false, false, true);
1568
1568
if (bundle ) {
1569
- pthread_mutex_lock (& (bundle -> _bundleLoadingLock ));
1569
+ __CFLock (& (bundle -> _bundleLoadingLock ));
1570
1570
if (!bundle -> _isLoaded ) {
1571
1571
// make sure that these bundles listed as loaded, and mark them frameworks (we probably can't see anything else here, and we cannot unload them)
1572
1572
#if defined(BINARY_SUPPORT_DLFCN )
@@ -1583,7 +1583,7 @@ static void _CFBundleEnsureBundleExistsForImagePath(CFStringRef imagePath, Boole
1583
1583
#endif /* LOG_BUNDLE_LOAD */
1584
1584
bundle -> _isLoaded = true;
1585
1585
}
1586
- pthread_mutex_unlock (& (bundle -> _bundleLoadingLock ));
1586
+ __CFUnlock (& (bundle -> _bundleLoadingLock ));
1587
1587
// Perform delayed final processing steps.
1588
1588
// This must be done after _isLoaded has been set, for security reasons (3624341).
1589
1589
_CFBundleInitPlugIn (bundle );
@@ -1635,14 +1635,14 @@ CFArrayRef CFBundleGetAllBundles(void) {
1635
1635
// This API is fundamentally broken from a thread safety point of view. To mitigate the issues, we keep around the last list we handed out. If the list of allBundles changed, we leak the last one and return a new copy. If no bundle loading is done this list would be static.
1636
1636
// Fortunately this method is rarely used.
1637
1637
CFArrayRef result = NULL ;
1638
- pthread_mutex_lock (& CFBundleGlobalDataLock );
1638
+ __CFLock (& CFBundleGlobalDataLock );
1639
1639
static CFArrayRef _lastBundleList = NULL ;
1640
1640
if (!_lastBundleList ) {
1641
1641
// This is the first time we've been asked for a list of all bundles
1642
1642
// Unlock the global lock. CopyAllBundles will use it.
1643
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
1643
+ __CFUnlock (& CFBundleGlobalDataLock );
1644
1644
result = _CFBundleCopyAllBundles ();
1645
- pthread_mutex_lock (& CFBundleGlobalDataLock );
1645
+ __CFLock (& CFBundleGlobalDataLock );
1646
1646
if (_lastBundleList ) {
1647
1647
// Another thread beat us here
1648
1648
CFRelease (result );
@@ -1651,25 +1651,25 @@ CFArrayRef CFBundleGetAllBundles(void) {
1651
1651
}
1652
1652
} else if (!CFEqual (_lastBundleList , _allBundles )) {
1653
1653
// Check if the list of bundles has changed
1654
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
1654
+ __CFUnlock (& CFBundleGlobalDataLock );
1655
1655
result = _CFBundleCopyAllBundles ();
1656
- pthread_mutex_lock (& CFBundleGlobalDataLock );
1656
+ __CFLock (& CFBundleGlobalDataLock );
1657
1657
// note: intentionally leak the last value in _lastBundleList, due to API contract of 'get'
1658
1658
_lastBundleList = result ;
1659
1659
}
1660
1660
result = _lastBundleList ;
1661
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
1661
+ __CFUnlock (& CFBundleGlobalDataLock );
1662
1662
return result ;
1663
1663
}
1664
1664
1665
1665
CF_EXPORT CFArrayRef _CFBundleCopyAllBundles (void ) {
1666
1666
// To answer this properly, we have to have created the static bundles!
1667
1667
_CFBundleEnsureAllBundlesUpToDate ();
1668
1668
CFBundleRef main = CFBundleGetMainBundle ();
1669
- pthread_mutex_lock (& CFBundleGlobalDataLock );
1669
+ __CFLock (& CFBundleGlobalDataLock );
1670
1670
// _allBundles does not include the main bundle, so insert it here.
1671
1671
CFMutableArrayRef bundles = CFArrayCreateMutableCopy (kCFAllocatorSystemDefault , CFArrayGetCount (_allBundles ) + 1 , _allBundles );
1672
- pthread_mutex_unlock (& CFBundleGlobalDataLock );
1672
+ __CFUnlock (& CFBundleGlobalDataLock );
1673
1673
CFArrayInsertValueAtIndex (bundles , 0 , main );
1674
1674
return bundles ;
1675
1675
}
0 commit comments