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