OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 { | 55 { |
56 start(interval, 0, caller); | 56 start(interval, 0, caller); |
57 } | 57 } |
58 | 58 |
59 void stop(); | 59 void stop(); |
60 bool isActive() const; | 60 bool isActive() const; |
61 const WebTraceLocation& location() const { return m_location; } | 61 const WebTraceLocation& location() const { return m_location; } |
62 | 62 |
63 double nextFireInterval() const; | 63 double nextFireInterval() const; |
64 double nextUnalignedFireInterval() const; | 64 double nextUnalignedFireInterval() const; |
65 NO_LAZY_SWEEP_SANITIZE_ADDRESS | |
66 double repeatInterval() const { return m_repeatInterval; } | 65 double repeatInterval() const { return m_repeatInterval; } |
67 | 66 |
68 void augmentRepeatInterval(double delta) { | 67 void augmentRepeatInterval(double delta) { |
69 double now = monotonicallyIncreasingTime(); | 68 double now = monotonicallyIncreasingTime(); |
70 setNextFireTime(now, m_nextFireTime - now + delta); | 69 setNextFireTime(now, m_nextFireTime - now + delta); |
71 m_repeatInterval += delta; | 70 m_repeatInterval += delta; |
72 } | 71 } |
73 | 72 |
74 void didChangeAlignmentInterval(double now); | 73 void didChangeAlignmentInterval(double now); |
75 | 74 |
| 75 #if defined(ADDRESS_SANITIZER) |
| 76 protected: |
| 77 CancellableTaskFactory& cancellableTaskFactory() { return m_cancellableTaskF
actory; } |
| 78 #endif |
| 79 |
76 private: | 80 private: |
77 virtual void fired() = 0; | 81 virtual void fired() = 0; |
78 | 82 |
79 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 83 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 84 virtual bool canFire() const { return true; } |
| 85 |
80 virtual double alignedFireTime(double fireTime) const { return fireTime; } | 86 virtual double alignedFireTime(double fireTime) const { return fireTime; } |
81 | 87 |
82 void setNextFireTime(double now, double delay); | 88 void setNextFireTime(double now, double delay); |
83 | 89 |
84 void run(); | 90 void run(); |
85 | 91 |
86 double m_nextFireTime; // 0 if inactive | 92 double m_nextFireTime; // 0 if inactive |
87 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment
interval | 93 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment
interval |
88 double m_repeatInterval; // 0 if not repeating | 94 double m_repeatInterval; // 0 if not repeating |
89 WebTraceLocation m_location; | 95 WebTraceLocation m_location; |
(...skipping 13 matching lines...) Expand all Loading... |
103 class TimerIsObjectAliveTrait { | 109 class TimerIsObjectAliveTrait { |
104 public: | 110 public: |
105 static bool isHeapObjectAlive(T*) { return true; } | 111 static bool isHeapObjectAlive(T*) { return true; } |
106 }; | 112 }; |
107 | 113 |
108 template<typename T> | 114 template<typename T> |
109 class TimerIsObjectAliveTrait<T, true> { | 115 class TimerIsObjectAliveTrait<T, true> { |
110 public: | 116 public: |
111 static bool isHeapObjectAlive(T* objectPointer) | 117 static bool isHeapObjectAlive(T* objectPointer) |
112 { | 118 { |
113 // Oilpan: if a timer fires while Oilpan heaps are being lazily | |
114 // swept, it is not safe to proceed if the object is about to | |
115 // be swept (and this timer will be stopped while doing so.) | |
116 return !Heap::willObjectBeLazilySwept(objectPointer); | 119 return !Heap::willObjectBeLazilySwept(objectPointer); |
117 } | 120 } |
118 }; | 121 }; |
119 | 122 |
120 template <typename TimerFiredClass> | 123 template <typename TimerFiredClass> |
121 class Timer : public TimerBase { | 124 class Timer : public TimerBase { |
122 public: | 125 public: |
123 typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); | 126 typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); |
124 | 127 |
125 Timer(TimerFiredClass* o, TimerFiredFunction f) | 128 Timer(TimerFiredClass* o, TimerFiredFunction f) |
126 : m_object(o), m_function(f) { } | 129 : m_object(o), m_function(f) |
| 130 { |
| 131 #if ENABLE(LAZY_SWEEPING) && defined(ADDRESS_SANITIZER) |
| 132 if (IsGarbageCollectedType<TimerFiredClass>::value) |
| 133 cancellableTaskFactory().setUnpoisonBeforeUpdate(); |
| 134 #endif |
| 135 } |
127 | 136 |
128 protected: | 137 protected: |
129 NO_LAZY_SWEEP_SANITIZE_ADDRESS | |
130 virtual void fired() override | 138 virtual void fired() override |
131 { | 139 { |
132 if (!TimerIsObjectAliveTrait<TimerFiredClass>::isHeapObjectAlive(m_objec
t)) | |
133 return; | |
134 (m_object->*m_function)(this); | 140 (m_object->*m_function)(this); |
135 } | 141 } |
136 | 142 |
| 143 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 144 virtual bool canFire() const override |
| 145 { |
| 146 // Oilpan: if a timer fires while Oilpan heaps are being lazily |
| 147 // swept, it is not safe to proceed if the object is about to |
| 148 // be swept (and this timer will be stopped while doing so.) |
| 149 return TimerIsObjectAliveTrait<TimerFiredClass>::isHeapObjectAlive(m_obj
ect); |
| 150 } |
| 151 |
137 private: | 152 private: |
138 // FIXME: oilpan: TimerBase should be moved to the heap and m_object should
be traced. | 153 // FIXME: Oilpan: TimerBase should be moved to the heap and m_object should
be traced. |
139 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha
t's the case | 154 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha
t's the case |
140 // in the current code base). | 155 // in the current code base). |
141 GC_PLUGIN_IGNORE("363031") | 156 GC_PLUGIN_IGNORE("363031") |
142 TimerFiredClass* m_object; | 157 TimerFiredClass* m_object; |
143 TimerFiredFunction m_function; | 158 TimerFiredFunction m_function; |
144 }; | 159 }; |
145 | 160 |
146 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 161 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
147 inline bool TimerBase::isActive() const | 162 inline bool TimerBase::isActive() const |
148 { | 163 { |
149 ASSERT(m_thread == currentThread()); | 164 ASSERT(m_thread == currentThread()); |
150 return m_cancellableTaskFactory.isPending(); | 165 return m_cancellableTaskFactory.isPending(); |
151 } | 166 } |
152 | 167 |
153 } | 168 } // namespace blink |
154 | 169 |
155 #endif | 170 #endif // Timer_h |
OLD | NEW |