| 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 23 matching lines...) Expand all Loading... |
| 34 #include "wtf/Functional.h" | 34 #include "wtf/Functional.h" |
| 35 #include "wtf/Threading.h" | 35 #include "wtf/Threading.h" |
| 36 #include "wtf/text/AtomicString.h" | 36 #include "wtf/text/AtomicString.h" |
| 37 #include "wtf/text/StringStatics.h" | 37 #include "wtf/text/StringStatics.h" |
| 38 | 38 |
| 39 namespace WTF { | 39 namespace WTF { |
| 40 | 40 |
| 41 static ThreadIdentifier mainThreadIdentifier; | 41 static ThreadIdentifier mainThreadIdentifier; |
| 42 static void (*callOnMainThreadFunction)(MainThreadFunction, void*); | 42 static void (*callOnMainThreadFunction)(MainThreadFunction, void*); |
| 43 | 43 |
| 44 void initializeMainThread(void (*function)(MainThreadFunction, void*)) | 44 void initializeMainThread(void (*function)(MainThreadFunction, void*)) { |
| 45 { | 45 static bool initializedMainThread; |
| 46 static bool initializedMainThread; | 46 if (initializedMainThread) |
| 47 if (initializedMainThread) | 47 return; |
| 48 return; | 48 initializedMainThread = true; |
| 49 initializedMainThread = true; | 49 callOnMainThreadFunction = function; |
| 50 callOnMainThreadFunction = function; | |
| 51 | 50 |
| 52 mainThreadIdentifier = currentThread(); | 51 mainThreadIdentifier = currentThread(); |
| 53 | 52 |
| 54 AtomicString::init(); | 53 AtomicString::init(); |
| 55 StringStatics::init(); | 54 StringStatics::init(); |
| 56 } | 55 } |
| 57 | 56 |
| 58 namespace internal { | 57 namespace internal { |
| 59 | 58 |
| 60 void callOnMainThread(MainThreadFunction* function, void* context) | 59 void callOnMainThread(MainThreadFunction* function, void* context) { |
| 61 { | 60 (*callOnMainThreadFunction)(function, context); |
| 62 (*callOnMainThreadFunction)(function, context); | |
| 63 } | 61 } |
| 64 | 62 |
| 65 } // namespace internal | 63 } // namespace internal |
| 66 | 64 |
| 67 bool isMainThread() | 65 bool isMainThread() { |
| 68 { | 66 return currentThread() == mainThreadIdentifier; |
| 69 return currentThread() == mainThreadIdentifier; | |
| 70 } | 67 } |
| 71 | 68 |
| 72 } // namespace WTF | 69 } // namespace WTF |
| OLD | NEW |