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