| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "wtf/MainThread.h" | 32 #include "wtf/MainThread.h" |
| 33 | 33 |
| 34 #include "wtf/Assertions.h" | 34 #include "wtf/Assertions.h" |
| 35 #include "wtf/Functional.h" | 35 #include "wtf/Functional.h" |
| 36 #include "wtf/Threading.h" | 36 #include "wtf/Threading.h" |
| 37 #include "wtf/text/AtomicString.h" | 37 #include "wtf/text/AtomicString.h" |
| 38 #include "wtf/text/StringStatics.h" |
| 38 | 39 |
| 39 namespace WTF { | 40 namespace WTF { |
| 40 | 41 |
| 41 static ThreadIdentifier mainThreadIdentifier; | 42 static ThreadIdentifier mainThreadIdentifier; |
| 42 static void (*callOnMainThreadFunction)(MainThreadFunction, void*); | 43 static void (*callOnMainThreadFunction)(MainThreadFunction, void*); |
| 43 | 44 |
| 44 void initializeMainThread(void (*function)(MainThreadFunction, void*)) | 45 void initializeMainThread(void (*function)(MainThreadFunction, void*)) |
| 45 { | 46 { |
| 46 static bool initializedMainThread; | 47 static bool initializedMainThread; |
| 47 if (initializedMainThread) | 48 if (initializedMainThread) |
| 48 return; | 49 return; |
| 49 initializedMainThread = true; | 50 initializedMainThread = true; |
| 50 callOnMainThreadFunction = function; | 51 callOnMainThreadFunction = function; |
| 51 | 52 |
| 52 mainThreadIdentifier = currentThread(); | 53 mainThreadIdentifier = currentThread(); |
| 53 | 54 |
| 54 AtomicString::init(); | 55 AtomicString::init(); |
| 56 StringStatics::init(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 namespace internal { | 59 namespace internal { |
| 58 | 60 |
| 59 void callOnMainThread(MainThreadFunction* function, void* context) | 61 void callOnMainThread(MainThreadFunction* function, void* context) |
| 60 { | 62 { |
| 61 (*callOnMainThreadFunction)(function, context); | 63 (*callOnMainThreadFunction)(function, context); |
| 62 } | 64 } |
| 63 | 65 |
| 64 } // namespace internal | 66 } // namespace internal |
| 65 | 67 |
| 66 bool isMainThread() | 68 bool isMainThread() |
| 67 { | 69 { |
| 68 return currentThread() == mainThreadIdentifier; | 70 return currentThread() == mainThreadIdentifier; |
| 69 } | 71 } |
| 70 | 72 |
| 71 } // namespace WTF | 73 } // namespace WTF |
| OLD | NEW |