Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 typedef const uint8_t* ConstAddress; | 45 typedef const uint8_t* ConstAddress; |
| 46 | 46 |
| 47 enum ThreadAffinity { | 47 enum ThreadAffinity { |
| 48 AnyThread, | 48 AnyThread, |
| 49 MainThreadOnly, | 49 MainThreadOnly, |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // By default all types are considered to be used on the main thread only. | 52 // By default all types are considered to be used on the main thread only. |
| 53 template<typename T> | 53 template<typename T> |
| 54 struct ThreadingTrait { | 54 struct ThreadingTrait { |
| 55 static const ThreadAffinity Affinity = MainThreadOnly; | 55 static const ThreadAffinity Affinity = AnyThread; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Marks specified class as requiring thread safe handles which can be used from any thread. | 58 // Marks specified class as requiring thread safe handles which can be used from any thread. |
| 59 // Notice that marking base class does not automatically mark its descendants an d they | 59 // Notice that marking base class does not automatically mark its descendants an d they |
| 60 // have to be explicitly marked. | 60 // have to be explicitly marked. |
| 61 #define REQUIRE_THREADSAFE_HANDLES(Class) \ | 61 #define REQUIRE_THREADSAFE_HANDLES(Class) \ |
| 62 class Class; \ | 62 class Class; \ |
| 63 template<> struct ThreadingTrait<Class> { \ | 63 template<> struct ThreadingTrait<Class> { \ |
| 64 static const ThreadAffinity Affinity = AnyThread; \ | 64 static const ThreadAffinity Affinity = AnyThread; \ |
| 65 } | 65 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 m_endOfStack = endOfStack; | 218 m_endOfStack = endOfStack; |
| 219 } | 219 } |
| 220 | 220 |
| 221 static void visitRoots(Visitor*); | 221 static void visitRoots(Visitor*); |
| 222 static void init(intptr_t* startOfStack); | 222 static void init(intptr_t* startOfStack); |
| 223 static void shutdown(); | 223 static void shutdown(); |
| 224 | 224 |
| 225 static void attach(intptr_t* startOfStack); | 225 static void attach(intptr_t* startOfStack); |
| 226 static void detach(); | 226 static void detach(); |
| 227 | 227 |
| 228 static ThreadState* Current() { return **s_threadSpecific; } | 228 static ThreadState* Current() |
| 229 { | |
| 230 intptr_t dummy; | |
| 231 if (LIKELY(s_mainThreadStackTop < &dummy && &dummy <= s_mainThreadStackB ottom)) | |
|
haraken
2013/12/12 06:33:47
Of a couple of approaches I have tried, this is th
Mads Ager (chromium)
2013/12/12 06:51:56
I find this rather nasty. It is probably true that
| |
| 232 return MainThreadState(); | |
| 233 return **s_threadSpecific; | |
| 234 } | |
| 229 static ThreadState* MainThreadState() { return &s_mainThreadState; } | 235 static ThreadState* MainThreadState() { return &s_mainThreadState; } |
| 230 static bool IsMainThread() { return Current() == MainThreadState(); } | 236 static bool IsMainThread() { return Current() == MainThreadState(); } |
| 231 | 237 |
| 232 static void stopThreads(StackState); | 238 static void stopThreads(StackState); |
| 233 static void resumeThreads(); | 239 static void resumeThreads(); |
| 234 | 240 |
| 235 void safePoint(); | 241 void safePoint(); |
| 236 | 242 |
| 237 class SafePointScope { | 243 class SafePointScope { |
| 238 public: | 244 public: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 267 protected: | 273 protected: |
| 268 void onInterrupted(); | 274 void onInterrupted(); |
| 269 }; | 275 }; |
| 270 | 276 |
| 271 void setInterruptor(Interruptor*); | 277 void setInterruptor(Interruptor*); |
| 272 | 278 |
| 273 // Should only be called under protection of threadAttachMutex(). | 279 // Should only be called under protection of threadAttachMutex(). |
| 274 Interruptor* interruptor() const { return m_interruptor; } | 280 Interruptor* interruptor() const { return m_interruptor; } |
| 275 | 281 |
| 276 private: | 282 private: |
| 283 static intptr_t* s_mainThreadStackBottom; | |
| 284 static intptr_t* s_mainThreadStackTop; | |
| 277 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; | 285 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
| 278 static ThreadState s_mainThreadState; | 286 static ThreadState s_mainThreadState; |
| 279 static SafePointBarrier* s_safePointBarrier; | 287 static SafePointBarrier* s_safePointBarrier; |
| 280 // This variable is flipped to true after all threads are stoped and outermo st GC has started. | 288 // This variable is flipped to true after all threads are stoped and outermo st GC has started. |
| 281 static bool s_inGC; | 289 static bool s_inGC; |
| 282 | 290 |
| 283 void create(intptr_t* startOfStack); | 291 void create(intptr_t* startOfStack); |
| 284 void destroy(); | 292 void destroy(); |
| 285 void trace(Visitor*); | 293 void trace(Visitor*); |
| 286 bool pointersOnStack() const { return m_stackState == HeapPointersOnStack; } | 294 bool pointersOnStack() const { return m_stackState == HeapPointersOnStack; } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WTF, Int32Array); | 401 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WTF, Int32Array); |
| 394 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WTF, Uint32Array); | 402 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WTF, Uint32Array); |
| 395 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WTF, Float32Array); | 403 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WTF, Float32Array); |
| 396 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WTF, Float64Array); | 404 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WTF, Float64Array); |
| 397 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WebKit, IDBCallbacksProxy); | 405 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WebKit, IDBCallbacksProxy); |
| 398 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WebKit, IDBDatabaseBackendProxy); | 406 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WebKit, IDBDatabaseBackendProxy); |
| 399 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WebKit, IDBDatabaseCallbacksProxy); | 407 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WebKit, IDBDatabaseCallbacksProxy); |
| 400 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WebKit, IDBFactoryBackendProxy); | 408 REQUIRE_THREADSAFE_HANDLES_WITH_NAMESPACE(WebKit, IDBFactoryBackendProxy); |
| 401 | 409 |
| 402 #endif | 410 #endif |
| OLD | NEW |