Skip to content

Commit 7da6532

Browse files
authored
Merge pull request #30 from cwakamo/prevent-recursive-logging-4.2
[4.2] [PlaygroundLogger] Add checks in the logger entrypoints to prevent recursive logging.
2 parents 590bb63 + b357798 commit 7da6532

File tree

9 files changed

+241
-6
lines changed

9 files changed

+241
-6
lines changed

PlaygroundLogger/PlaygroundLogger.xcodeproj/project.pbxproj

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
5E5D77842040F5E900EBC3A9 /* LoggingError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5D77832040F5E900EBC3A9 /* LoggingError.swift */; };
8383
5E5F600B20409D4E007EF0A8 /* LogPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5F600A20409D4E007EF0A8 /* LogPolicy.swift */; };
8484
5E5FE50B202D13C800E28C3C /* PGLConcurrentMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5FE50A202D13C800E28C3C /* PGLConcurrentMap.swift */; };
85+
5EB651C0213A01D0001CC984 /* LegacyEntrypointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EB651BF213A01D0001CC984 /* LegacyEntrypointTests.swift */; };
86+
5EB651C1213A01D0001CC984 /* LegacyEntrypointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EB651BF213A01D0001CC984 /* LegacyEntrypointTests.swift */; };
87+
5EB651C2213A01D0001CC984 /* LegacyEntrypointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EB651BF213A01D0001CC984 /* LegacyEntrypointTests.swift */; };
88+
5EB651C4213A081A001CC984 /* LoggerEntrypointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EB651C3213A081A001CC984 /* LoggerEntrypointTests.swift */; };
89+
5EB651C5213A081A001CC984 /* LoggerEntrypointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EB651C3213A081A001CC984 /* LoggerEntrypointTests.swift */; };
90+
5EB651C6213A081A001CC984 /* LoggerEntrypointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EB651C3213A081A001CC984 /* LoggerEntrypointTests.swift */; };
8591
5ECE8F911FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ECE8F901FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift */; };
8692
5EE3867420352F3200D625F0 /* CGFloat+CustomOpaqueLoggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EE3867320352F3200D625F0 /* CGFloat+CustomOpaqueLoggable.swift */; };
8793
5EF581532041387C00AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EF581512041384700AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift */; };
@@ -93,6 +99,8 @@
9399
5EF6403E204148B80007BDD2 /* NSBezierPath+PGLKeyedArchivingUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EF6403C204148B80007BDD2 /* NSBezierPath+PGLKeyedArchivingUtilities.m */; settings = {COMPILER_FLAGS = "-fobjc-arc-exceptions"; }; };
94100
5EF64041204149DE0007BDD2 /* UIBezierPath+PGLKeyedArchivingUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 5EF6403F204149DE0007BDD2 /* UIBezierPath+PGLKeyedArchivingUtilities.h */; settings = {ATTRIBUTES = (Public, ); }; };
95101
5EF64042204149DE0007BDD2 /* UIBezierPath+PGLKeyedArchivingUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EF64040204149DE0007BDD2 /* UIBezierPath+PGLKeyedArchivingUtilities.m */; settings = {COMPILER_FLAGS = "-fobjc-arc-exceptions"; }; };
102+
5EFB2A5321211BC300BA43D3 /* PGLThreadIsLogging.h in Headers */ = {isa = PBXBuildFile; fileRef = 5EFB2A5121211BC300BA43D3 /* PGLThreadIsLogging.h */; settings = {ATTRIBUTES = (Public, ); }; };
103+
5EFB2A5421211BC300BA43D3 /* PGLThreadIsLogging.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EFB2A5221211BC300BA43D3 /* PGLThreadIsLogging.m */; };
96104
5EFE9193203F6CF900E21BAA /* LegacyPlaygroundLoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ECE8F901FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift */; };
97105
5EFE919B203F6DD700E21BAA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EFE919A203F6DD700E21BAA /* AppDelegate.swift */; };
98106
5EFE919D203F6DD700E21BAA /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EFE919C203F6DD700E21BAA /* ViewController.swift */; };
@@ -260,6 +268,8 @@
260268
5E5D77832040F5E900EBC3A9 /* LoggingError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingError.swift; sourceTree = "<group>"; };
261269
5E5F600A20409D4E007EF0A8 /* LogPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogPolicy.swift; sourceTree = "<group>"; };
262270
5E5FE50A202D13C800E28C3C /* PGLConcurrentMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PGLConcurrentMap.swift; sourceTree = "<group>"; };
271+
5EB651BF213A01D0001CC984 /* LegacyEntrypointTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyEntrypointTests.swift; sourceTree = "<group>"; };
272+
5EB651C3213A081A001CC984 /* LoggerEntrypointTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerEntrypointTests.swift; sourceTree = "<group>"; };
263273
5ECE8F901FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyPlaygroundLoggerTests.swift; sourceTree = "<group>"; };
264274
5EE3867320352F3200D625F0 /* CGFloat+CustomOpaqueLoggable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGFloat+CustomOpaqueLoggable.swift"; sourceTree = "<group>"; };
265275
5EF581512041384700AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomPlaygroundDisplayConvertibleTests.swift; sourceTree = "<group>"; };
@@ -269,6 +279,8 @@
269279
5EF6403C204148B80007BDD2 /* NSBezierPath+PGLKeyedArchivingUtilities.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSBezierPath+PGLKeyedArchivingUtilities.m"; sourceTree = "<group>"; };
270280
5EF6403F204149DE0007BDD2 /* UIBezierPath+PGLKeyedArchivingUtilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIBezierPath+PGLKeyedArchivingUtilities.h"; sourceTree = "<group>"; };
271281
5EF64040204149DE0007BDD2 /* UIBezierPath+PGLKeyedArchivingUtilities.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIBezierPath+PGLKeyedArchivingUtilities.m"; sourceTree = "<group>"; };
282+
5EFB2A5121211BC300BA43D3 /* PGLThreadIsLogging.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PGLThreadIsLogging.h; sourceTree = "<group>"; };
283+
5EFB2A5221211BC300BA43D3 /* PGLThreadIsLogging.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PGLThreadIsLogging.m; sourceTree = "<group>"; };
272284
5EFE9189203F6CC400E21BAA /* PlaygroundLoggerTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PlaygroundLoggerTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
273285
5EFE918D203F6CC400E21BAA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
274286
5EFE9198203F6DD700E21BAA /* PlaygroundLoggerTestHost_iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PlaygroundLoggerTestHost_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -354,6 +366,7 @@
354366
5EFE91B1203F6E8D00E21BAA /* PlaygroundLoggerTestHost_tvOS */,
355367
5E11805820414E0C00B73EE9 /* Config Files */,
356368
5E2646281FB64876002DC6B6 /* Products */,
369+
5EFB2A352121145E00BA43D3 /* Frameworks */,
357370
);
358371
sourceTree = "<group>";
359372
};
@@ -400,6 +413,8 @@
400413
5EF581512041384700AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift */,
401414
5E48E0A92042925B00C7712D /* LogEntryTests.swift */,
402415
5E5D777F2040BD7D00EBC3A9 /* LogPolicyTests.swift */,
416+
5EB651C3213A081A001CC984 /* LoggerEntrypointTests.swift */,
417+
5EB651BF213A01D0001CC984 /* LegacyEntrypointTests.swift */,
403418
5ECE8F901FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift */,
404419
);
405420
path = PlaygroundLoggerTests;
@@ -599,10 +614,19 @@
599614
5E184716202BB80200F01AD1 /* PGLConcurrentMap.h */,
600615
5E184717202BB80200F01AD1 /* PGLConcurrentMap_MRR.m */,
601616
5E5FE50A202D13C800E28C3C /* PGLConcurrentMap.swift */,
617+
5EFB2A5121211BC300BA43D3 /* PGLThreadIsLogging.h */,
618+
5EFB2A5221211BC300BA43D3 /* PGLThreadIsLogging.m */,
602619
);
603620
path = Utilities;
604621
sourceTree = "<group>";
605622
};
623+
5EFB2A352121145E00BA43D3 /* Frameworks */ = {
624+
isa = PBXGroup;
625+
children = (
626+
);
627+
name = Frameworks;
628+
sourceTree = "<group>";
629+
};
606630
5EFE918A203F6CC400E21BAA /* PlaygroundLoggerTests_iOS */ = {
607631
isa = PBXGroup;
608632
children = (
@@ -651,6 +675,7 @@
651675
files = (
652676
5E184718202BB80200F01AD1 /* PGLConcurrentMap.h in Headers */,
653677
5EF64041204149DE0007BDD2 /* UIBezierPath+PGLKeyedArchivingUtilities.h in Headers */,
678+
5EFB2A5321211BC300BA43D3 /* PGLThreadIsLogging.h in Headers */,
654679
5EF6403D204148B80007BDD2 /* NSBezierPath+PGLKeyedArchivingUtilities.h in Headers */,
655680
5EF64039204145A80007BDD2 /* NSAttributedString+PGLKeyedArchivingUtilities.h in Headers */,
656681
5E2646381FB64876002DC6B6 /* PlaygroundLogger.h in Headers */,
@@ -778,7 +803,7 @@
778803
5E26461E1FB64876002DC6B6 /* Project object */ = {
779804
isa = PBXProject;
780805
attributes = {
781-
LastSwiftUpdateCheck = 0930;
806+
LastSwiftUpdateCheck = 1000;
782807
LastUpgradeCheck = 0910;
783808
ORGANIZATIONNAME = "Apple Inc. and the Swift project authors";
784809
TargetAttributes = {
@@ -952,6 +977,7 @@
952977
5E2755CF1FB657F200B69C83 /* LogEntry.swift in Sources */,
953978
5E2756221FC4873000B69C83 /* UInt64+TaggedOpaqueRepresentation.swift in Sources */,
954979
5E2756281FC4895100B69C83 /* Double+TaggedOpaqueRepresentation.swift in Sources */,
980+
5EFB2A5421211BC300BA43D3 /* PGLThreadIsLogging.m in Sources */,
955981
5E2756481FC4DE1500B69C83 /* NSView+OpaqueImageRepresentable.swift in Sources */,
956982
5E2755D31FB672DC00B69C83 /* SendData.swift in Sources */,
957983
5E27567E1FCF429900B69C83 /* NSCursor+CustomOpaqueLoggable.swift in Sources */,
@@ -964,6 +990,8 @@
964990
isa = PBXSourcesBuildPhase;
965991
buildActionMask = 2147483647;
966992
files = (
993+
5EB651C0213A01D0001CC984 /* LegacyEntrypointTests.swift in Sources */,
994+
5EB651C4213A081A001CC984 /* LoggerEntrypointTests.swift in Sources */,
967995
5E5D77802040BD7D00EBC3A9 /* LogPolicyTests.swift in Sources */,
968996
5E48E0AA2042925B00C7712D /* LogEntryTests.swift in Sources */,
969997
5EF581532041387C00AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift in Sources */,
@@ -975,6 +1003,8 @@
9751003
isa = PBXSourcesBuildPhase;
9761004
buildActionMask = 2147483647;
9771005
files = (
1006+
5EB651C1213A01D0001CC984 /* LegacyEntrypointTests.swift in Sources */,
1007+
5EB651C5213A081A001CC984 /* LoggerEntrypointTests.swift in Sources */,
9781008
5E5D77812040BD7D00EBC3A9 /* LogPolicyTests.swift in Sources */,
9791009
5E48E0AB2042925B00C7712D /* LogEntryTests.swift in Sources */,
9801010
5EF581542041387C00AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift in Sources */,
@@ -1004,6 +1034,8 @@
10041034
isa = PBXSourcesBuildPhase;
10051035
buildActionMask = 2147483647;
10061036
files = (
1037+
5EB651C2213A01D0001CC984 /* LegacyEntrypointTests.swift in Sources */,
1038+
5EB651C6213A081A001CC984 /* LoggerEntrypointTests.swift in Sources */,
10071039
5E5D77822040BD7D00EBC3A9 /* LogPolicyTests.swift in Sources */,
10081040
5E48E0AC2042925B00C7712D /* LogEntryTests.swift in Sources */,
10091041
5EF581552041387C00AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift in Sources */,

PlaygroundLogger/PlaygroundLogger/LegacySupport/LegacyEntrypoints.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ fileprivate func legacySendDataStub(_: NSData) -> Void {
3535
}
3636

3737
@_silgen_name("playground_log_hidden")
38-
public func legacyLog<T>(instance: T, name: String, id: Int, startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject {
38+
public func legacyLog<T>(instance: T, name: String, id: Int, startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject? {
39+
guard !PGLGetThreadIsLogging() else { return nil }
40+
PGLSetThreadIsLogging(true)
41+
defer { PGLSetThreadIsLogging(false) }
42+
3943
let packet = LogPacket(describingResult: instance, named: name, withPolicy: .default, startLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
4044

4145
let data: Data
@@ -68,7 +72,11 @@ public func legacyLog<T>(instance: T, name: String, id: Int, startLine: Int, end
6872
}
6973

7074
@_silgen_name ("playground_log_scope_entry")
71-
public func legacyLogScopeEntry(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject {
75+
public func legacyLogScopeEntry(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject? {
76+
guard !PGLGetThreadIsLogging() else { return nil }
77+
PGLSetThreadIsLogging(true)
78+
defer { PGLSetThreadIsLogging(false) }
79+
7280
let packet = LogPacket(scopeEntryWithStartLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
7381

7482
// Encoding a scope entry packet should not fail under any circumstances.
@@ -78,7 +86,11 @@ public func legacyLogScopeEntry(startLine: Int, endLine: Int, startColumn: Int,
7886
}
7987

8088
@_silgen_name ("playground_log_scope_exit")
81-
public func legacyLogScopeExit(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject {
89+
public func legacyLogScopeExit(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject? {
90+
guard !PGLGetThreadIsLogging() else { return nil }
91+
PGLSetThreadIsLogging(true)
92+
defer { PGLSetThreadIsLogging(false) }
93+
8294
let packet = LogPacket(scopeExitWithStartLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
8395

8496
// Encoding a scope exit packet should not fail under any circumstances.
@@ -88,7 +100,11 @@ public func legacyLogScopeExit(startLine: Int, endLine: Int, startColumn: Int, e
88100
}
89101

90102
@_silgen_name ("playground_log_postprint")
91-
public func legacyLogPostPrint(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject {
103+
public func legacyLogPostPrint(startLine: Int, endLine: Int, startColumn: Int, endColumn: Int) -> AnyObject? {
104+
guard !PGLGetThreadIsLogging() else { return nil }
105+
PGLSetThreadIsLogging(true)
106+
defer { PGLSetThreadIsLogging(false) }
107+
92108
let printedString = Thread.current.threadDictionary[printedStringThreadDictionaryKey] as! String? ?? ""
93109

94110
Thread.current.threadDictionary.removeObject(forKey: printedStringThreadDictionaryKey)

PlaygroundLogger/PlaygroundLogger/LoggerEntrypoints.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func logResult(_ result: Any,
1919
endLine: Int,
2020
startColumn: Int,
2121
endColumn: Int) {
22+
guard !PGLGetThreadIsLogging() else { return }
23+
PGLSetThreadIsLogging(true)
24+
defer { PGLSetThreadIsLogging(false) }
25+
2226
let packet = LogPacket(describingResult: result, named: name, withPolicy: .default, startLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
2327

2428
let data: Data
@@ -54,6 +58,10 @@ func logScopeEntry(startLine: Int,
5458
endLine: Int,
5559
startColumn: Int,
5660
endColumn: Int) {
61+
guard !PGLGetThreadIsLogging() else { return }
62+
PGLSetThreadIsLogging(true)
63+
defer { PGLSetThreadIsLogging(false) }
64+
5765
let packet = LogPacket(scopeEntryWithStartLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
5866

5967
// Encoding a scope entry packet should not fail under any circumstances.
@@ -66,6 +74,10 @@ func logScopeExit(startLine: Int,
6674
endLine: Int,
6775
startColumn: Int,
6876
endColumn: Int) {
77+
guard !PGLGetThreadIsLogging() else { return }
78+
PGLSetThreadIsLogging(true)
79+
defer { PGLSetThreadIsLogging(false) }
80+
6981
let packet = LogPacket(scopeExitWithStartLine: startLine, endLine: endLine, startColumn: startColumn, endColumn: endColumn)
7082

7183
// Encoding a scope exit packet should not fail under any circumstances.
@@ -77,13 +89,20 @@ func logScopeExit(startLine: Int,
7789
let printedStringThreadDictionaryKey: NSString = "org.swift.PlaygroundLogger.printedString"
7890

7991
func printHook(string: String) {
92+
// Don't store the printed string if we're already logging elsewhere in this thread.
93+
guard !PGLGetThreadIsLogging() else { return }
94+
8095
Thread.current.threadDictionary[printedStringThreadDictionaryKey] = string as NSString
8196
}
8297

8398
func logPostPrint(startLine: Int,
8499
endLine: Int,
85100
startColumn: Int,
86101
endColumn: Int) {
102+
guard !PGLGetThreadIsLogging() else { return }
103+
PGLSetThreadIsLogging(true)
104+
defer { PGLSetThreadIsLogging(false) }
105+
87106
guard let printedString = Thread.current.threadDictionary[printedStringThreadDictionaryKey] as! String? else {
88107
return
89108
}

PlaygroundLogger/PlaygroundLogger/PlaygroundLogger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ FOUNDATION_EXPORT double PlaygroundLoggerVersionNumber;
1919
FOUNDATION_EXPORT const unsigned char PlaygroundLoggerVersionString[];
2020

2121
#import <PlaygroundLogger/PGLConcurrentMap.h>
22+
#import <PlaygroundLogger/PGLThreadIsLogging.h>
2223

2324
#import <PlaygroundLogger/NSAttributedString+PGLKeyedArchivingUtilities.h>
2425
#import <PlaygroundLogger/NSBezierPath+PGLKeyedArchivingUtilities.h>

PlaygroundLogger/PlaygroundLogger/SendData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import Foundation
1414

15-
fileprivate func unsetSendData(_: NSData) {
15+
internal /*testable*/ func unsetSendData(_: NSData) {
1616
fatalError("PlaygroundLogger not initialized")
1717
}
1818

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- PGLThreadIsLogging.h ---------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#import <sys/cdefs.h>
14+
#import <stdbool.h>
15+
16+
__BEGIN_DECLS
17+
18+
/// A thread-local `bool` which indicates whether or not the current thread is
19+
/// logging.
20+
///
21+
/// This is used by the functions in LoggerEntrypoints.swift and
22+
/// LegacyEntrypoints.swift to prevent generating log packets while already
23+
/// generating a log packet. It means the side-effects of logging are not
24+
/// themselves logged.
25+
extern __thread bool PGLThreadIsLogging;
26+
27+
/// A helper function to get the value of `PGLThreadIsLogging` safely from Swift.
28+
static inline bool PGLGetThreadIsLogging(void) {
29+
return PGLThreadIsLogging;
30+
}
31+
32+
/// A helper function to set the value of `PGLThreadIsLogging` safely from Swift.
33+
static inline void PGLSetThreadIsLogging(bool threadIsLogging) {
34+
PGLThreadIsLogging = threadIsLogging;
35+
}
36+
37+
__END_DECLS
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===--- PGLThreadIsLogging.m ---------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#import <PlaygroundLogger/PGLThreadIsLogging.h>
14+
15+
__thread bool PGLThreadIsLogging = false;

0 commit comments

Comments
 (0)