diff options
Diffstat (limited to 'WebCore/platform/mac/ThreadCheck.mm')
-rw-r--r-- | WebCore/platform/mac/ThreadCheck.mm | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/WebCore/platform/mac/ThreadCheck.mm b/WebCore/platform/mac/ThreadCheck.mm index b862598..ddee05c 100644 --- a/WebCore/platform/mac/ThreadCheck.mm +++ b/WebCore/platform/mac/ThreadCheck.mm @@ -32,56 +32,74 @@ namespace WebCore { -static ThreadViolationBehavior defaultThreadViolationBehavior = RaiseExceptionOnThreadViolation; - static bool didReadThreadViolationBehaviorFromUserDefaults = false; -static bool threadViolationBehaviorIsDefault; -static ThreadViolationBehavior threadViolationBehavior; +static bool threadViolationBehaviorIsDefault = true; +static ThreadViolationBehavior threadViolationBehavior[MaximumThreadViolationRound] = { RaiseExceptionOnThreadViolation, RaiseExceptionOnThreadViolation }; static void readThreadViolationBehaviorFromUserDefaults() { + didReadThreadViolationBehaviorFromUserDefaults = true; + + ThreadViolationBehavior newBehavior = LogOnFirstThreadViolation; NSString *threadCheckLevel = [[NSUserDefaults standardUserDefaults] stringForKey:@"WebCoreThreadCheck"]; + if (!threadCheckLevel) + return; + if ([threadCheckLevel isEqualToString:@"None"]) - threadViolationBehavior = NoThreadCheck; + newBehavior = NoThreadCheck; else if ([threadCheckLevel isEqualToString:@"Exception"]) - threadViolationBehavior = RaiseExceptionOnThreadViolation; + newBehavior = RaiseExceptionOnThreadViolation; else if ([threadCheckLevel isEqualToString:@"Log"]) - threadViolationBehavior = LogOnThreadViolation; + newBehavior = LogOnThreadViolation; else if ([threadCheckLevel isEqualToString:@"LogOnce"]) - threadViolationBehavior = LogOnFirstThreadViolation; - else { - threadViolationBehavior = defaultThreadViolationBehavior; - threadViolationBehaviorIsDefault = true; - } - didReadThreadViolationBehaviorFromUserDefaults = true; + newBehavior = LogOnFirstThreadViolation; + else + ASSERT_NOT_REACHED(); + + threadViolationBehaviorIsDefault = false; + + for (unsigned i = 0; i < MaximumThreadViolationRound; ++i) + threadViolationBehavior[i] = newBehavior; } -void setDefaultThreadViolationBehavior(ThreadViolationBehavior behavior) +void setDefaultThreadViolationBehavior(ThreadViolationBehavior behavior, ThreadViolationRound round) { - defaultThreadViolationBehavior = behavior; + ASSERT(round < MaximumThreadViolationRound); + if (round >= MaximumThreadViolationRound) + return; + if (!didReadThreadViolationBehaviorFromUserDefaults) + readThreadViolationBehaviorFromUserDefaults(); if (threadViolationBehaviorIsDefault) - threadViolationBehavior = behavior; + threadViolationBehavior[round] = behavior; } -void reportThreadViolation(const char* function) +void reportThreadViolation(const char* function, ThreadViolationRound round) { + ASSERT(round < MaximumThreadViolationRound); + if (round >= MaximumThreadViolationRound) + return; if (!didReadThreadViolationBehaviorFromUserDefaults) - readThreadViolationBehaviorFromUserDefaults(); - if (threadViolationBehavior == NoThreadCheck) + readThreadViolationBehaviorFromUserDefaults(); + if (threadViolationBehavior[round] == NoThreadCheck) return; if (pthread_main_np()) return; - WebCoreReportThreadViolation(function); + WebCoreReportThreadViolation(function, round); } } // namespace WebCore // Split out the actual reporting of the thread violation to make it easier to set a breakpoint -void WebCoreReportThreadViolation(const char* function) +void WebCoreReportThreadViolation(const char* function, WebCore::ThreadViolationRound round) { using namespace WebCore; + + ASSERT(round < MaximumThreadViolationRound); + if (round >= MaximumThreadViolationRound) + return; + DEFINE_STATIC_LOCAL(HashSet<String>, loggedFunctions, ()); - switch (threadViolationBehavior) { + switch (threadViolationBehavior[round]) { case NoThreadCheck: break; case LogOnFirstThreadViolation: |