Skip to content

Commit 300f3fd

Browse files
committed
Better memory order
1 parent bb394a0 commit 300f3fd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

stdlib/public/stubs/FoundationHelpers.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#import <objc/runtime.h>
2525
#include "swift/Runtime/Once.h"
2626
#include <dlfcn.h>
27+
#include "swift/Runtime/Atomic.h"
2728

2829
typedef enum {
2930
dyld_objc_string_kind
@@ -51,7 +52,7 @@
5152
static swift_once_t initializeBridgingStateOnce;
5253

5354
static CFBridgingState const *getBridgingState() {
54-
return bridgingState.load(std::memory_order_acquire);
55+
return bridgingState.load(SWIFT_MEMORY_ORDER_CONSUME);
5556
}
5657

5758
extern "C" bool _dyld_is_objc_constant(DyldObjCConstantKind kind,
@@ -114,7 +115,7 @@ static inline bool initializeBridgingFunctions() {
114115
state->NSSetClass = objc_lookUpClass("NSSet");
115116
state->NSDictionaryClass = objc_lookUpClass("NSDictionary");
116117
state->NSEnumeratorClass = objc_lookUpClass("NSEnumerator");
117-
bridgingState.store(state);
118+
bridgingState.store(state, std::memory_order_relaxed);
118119
_reparentClasses();
119120
});
120121
auto state = getBridgingState();
@@ -124,11 +125,11 @@ static inline bool initializeBridgingFunctions() {
124125
SWIFT_RUNTIME_EXPORT void swift_initializeCoreFoundationState(CFBridgingState const * const state) {
125126
//Consume the once token to make sure that the lazy version of this in initializeBridgingFunctions only runs if we didn't hit this
126127
swift::once(initializeBridgingStateOnce, [state](){
127-
bridgingState.store(state);
128+
bridgingState.store(state, std::memory_order_relaxed);
128129
});
129130
//It's fine if this runs more than once, it's a noop if it's been done before
130131
//and we want to make sure it still happens if CF loads late after it failed initially
131-
bridgingState.store(state);
132+
bridgingState.store(state, std::memory_order_release);
132133
_reparentClasses();
133134
}
134135

0 commit comments

Comments
 (0)