summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/Watchdog.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/JavaScriptCore/runtime/Watchdog.h
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/JavaScriptCore/runtime/Watchdog.h')
-rw-r--r--Source/JavaScriptCore/runtime/Watchdog.h89
1 files changed, 52 insertions, 37 deletions
diff --git a/Source/JavaScriptCore/runtime/Watchdog.h b/Source/JavaScriptCore/runtime/Watchdog.h
index 01a869748..15784d6e2 100644
--- a/Source/JavaScriptCore/runtime/Watchdog.h
+++ b/Source/JavaScriptCore/runtime/Watchdog.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,76 +26,91 @@
#ifndef Watchdog_h
#define Watchdog_h
-#include <wtf/Lock.h>
-#include <wtf/Ref.h>
-#include <wtf/ThreadSafeRefCounted.h>
-#include <wtf/WorkQueue.h>
+#if PLATFORM(MAC) || PLATFORM(IOS)
+#include <dispatch/dispatch.h>
+#endif
namespace JSC {
class ExecState;
class VM;
-class Watchdog : public WTF::ThreadSafeRefCounted<Watchdog> {
- WTF_MAKE_FAST_ALLOCATED;
+class Watchdog {
public:
class Scope;
Watchdog();
+ ~Watchdog();
typedef bool (*ShouldTerminateCallback)(ExecState*, void* data1, void* data2);
- void setTimeLimit(std::chrono::microseconds limit, ShouldTerminateCallback = 0, void* data1 = 0, void* data2 = 0);
- JS_EXPORT_PRIVATE void terminateSoon();
+ void setTimeLimit(VM&, double seconds, ShouldTerminateCallback = 0, void* data1 = 0, void* data2 = 0);
- bool shouldTerminate(ExecState* exec)
- {
- if (!m_timerDidFire)
- return false;
- return shouldTerminateSlow(exec);
- }
+ // This version of didFire() will check the elapsed CPU time and call the
+ // callback (if needed) to determine if the watchdog should fire.
+ bool didFire(ExecState*);
- bool hasTimeLimit();
- void enteredVM();
- void exitedVM();
+ bool isEnabled();
- void* timerDidFireAddress() { return &m_timerDidFire; }
+ // This version of didFire() is a more efficient version for when we want
+ // to know if the watchdog has fired in the past, and not whether it should
+ // fire right now.
+ bool didFire() { return m_didFire; }
+ JS_EXPORT_PRIVATE void fire();
- static const std::chrono::microseconds noTimeLimit;
+ void* timerDidFireAddress() { return &m_timerDidFire; }
private:
- void startTimer(LockHolder&, std::chrono::microseconds timeLimit);
- void stopTimer(LockHolder&);
-
- bool shouldTerminateSlow(ExecState*);
-
- // m_timerDidFire indicates whether the timer fired. The Watchdog
+ void arm();
+ void disarm();
+ void startCountdownIfNeeded();
+ void startCountdown(double limit);
+ void stopCountdown();
+ bool isArmed() { return !!m_reentryCount; }
+
+ // Platform specific timer implementation:
+ void initTimer();
+ void destroyTimer();
+ void startTimer(double limit);
+ void stopTimer();
+
+ // m_timerDidFire (above) indicates whether the timer fired. The Watchdog
// still needs to check if the allowed CPU time has elapsed. If so, then
// the Watchdog fires and m_didFire will be set.
// NOTE: m_timerDidFire is only set by the platform specific timer
// (probably from another thread) but is only cleared in the script thread.
bool m_timerDidFire;
+ bool m_didFire;
- std::chrono::microseconds m_timeLimit;
-
- std::chrono::microseconds m_cpuDeadline;
- std::chrono::microseconds m_wallClockDeadline;
-
- // Writes to m_timerDidFire and m_timeLimit, and Reads+Writes to m_cpuDeadline and m_wallClockDeadline
- // must be guarded by this lock.
- Lock m_lock;
+ // All time units are in seconds.
+ double m_limit;
+ double m_startTime;
+ double m_elapsedTime;
- bool m_hasEnteredVM { false };
+ int m_reentryCount;
+ bool m_isStopped;
ShouldTerminateCallback m_callback;
void* m_callbackData1;
void* m_callbackData2;
- Ref<WorkQueue> m_timerQueue;
- std::function<void ()> m_timerHandler;
+#if PLATFORM(MAC) || PLATFORM(IOS)
+ dispatch_queue_t m_queue;
+ dispatch_source_t m_timer;
+#endif
+ friend class Watchdog::Scope;
friend class LLIntOffsetsExtractor;
};
+class Watchdog::Scope {
+public:
+ Scope(Watchdog&);
+ ~Scope();
+
+private:
+ Watchdog& m_watchdog;
+};
+
} // namespace JSC
#endif // Watchdog_h