| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) | 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 55 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 56 * DEALINGS IN THE SOFTWARE. | 56 * DEALINGS IN THE SOFTWARE. |
| 57 */ | 57 */ |
| 58 | 58 |
| 59 #ifndef Threading_h | 59 #ifndef Threading_h |
| 60 #define Threading_h | 60 #define Threading_h |
| 61 | 61 |
| 62 #include <wtf/Platform.h> | 62 #include <wtf/Platform.h> |
| 63 | 63 |
| 64 #include <stdint.h> | 64 #include <stdint.h> |
| 65 #include <wtf/Assertions.h> | 65 #include "wtf/Assertions.h" |
| 66 #include <wtf/Atomics.h> | 66 #include "wtf/Atomics.h" |
| 67 #include <wtf/Locker.h> | 67 #include "wtf/CurrentTime.h" |
| 68 #include <wtf/Noncopyable.h> | 68 #include "wtf/Locker.h" |
| 69 #include <wtf/ThreadSafeRefCounted.h> | 69 #include "wtf/Noncopyable.h" |
| 70 #include <wtf/ThreadingPrimitives.h> | 70 #include "wtf/ThreadSafeRefCounted.h" |
| 71 #include "wtf/ThreadingPrimitives.h" |
| 72 #include "wtf/WTFExport.h" |
| 71 | 73 |
| 72 // For portability, we do not use thread-safe statics natively supported by some
compilers (e.g. gcc). | 74 // For portability, we do not use thread-safe statics natively supported by some
compilers (e.g. gcc). |
| 73 #define AtomicallyInitializedStatic(T, name) \ | 75 #define AtomicallyInitializedStatic(T, name) \ |
| 74 WTF::lockAtomicallyInitializedStaticMutex(); \ | 76 WTF::lockAtomicallyInitializedStaticMutex(); \ |
| 75 static T name; \ | 77 static T name; \ |
| 76 WTF::unlockAtomicallyInitializedStaticMutex(); | 78 WTF::unlockAtomicallyInitializedStaticMutex(); |
| 77 | 79 |
| 78 namespace WTF { | 80 namespace WTF { |
| 79 | 81 |
| 80 typedef uint32_t ThreadIdentifier; | 82 typedef uint32_t ThreadIdentifier; |
| 81 typedef void (*ThreadFunction)(void* argument); | 83 typedef void (*ThreadFunction)(void* argument); |
| 82 | 84 |
| 83 // This function must be called from the main thread. It is safe to call it repe
atedly. | 85 // This function must be called exactly once from the main thread before using a
nything else in WTF. |
| 84 // Darwin is an exception to this rule: it is OK to call it from any thread, the
only | 86 WTF_EXPORT void initialize(TimeFunction currentTimeFunction, TimeFunction monoto
nicallyIncreasingTimeFunction); |
| 85 // requirement is that the calls are not reentrant. | |
| 86 void initializeThreading(); | |
| 87 | 87 |
| 88 // Returns 0 if thread creation failed. | 88 // Returns 0 if thread creation failed. |
| 89 // The thread name must be a literal since on some platforms it's passed in to t
he thread. | 89 // The thread name must be a literal since on some platforms it's passed in to t
he thread. |
| 90 ThreadIdentifier createThread(ThreadFunction, void*, const char* threadName); | 90 WTF_EXPORT ThreadIdentifier createThread(ThreadFunction, void*, const char* thre
adName); |
| 91 | 91 |
| 92 // Internal platform-specific createThread implementation. | 92 // Internal platform-specific createThread implementation. |
| 93 ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadN
ame); | 93 WTF_EXPORT ThreadIdentifier createThreadInternal(ThreadFunction, void*, const ch
ar* threadName); |
| 94 | 94 |
| 95 // Called in the thread during initialization. | 95 // Called in the thread during initialization. |
| 96 // Helpful for platforms where the thread name must be set from within the threa
d. | 96 // Helpful for platforms where the thread name must be set from within the threa
d. |
| 97 void initializeCurrentThreadInternal(const char* threadName); | 97 WTF_EXPORT void initializeCurrentThreadInternal(const char* threadName); |
| 98 | 98 |
| 99 ThreadIdentifier currentThread(); | 99 WTF_EXPORT ThreadIdentifier currentThread(); |
| 100 int waitForThreadCompletion(ThreadIdentifier); | 100 WTF_EXPORT int waitForThreadCompletion(ThreadIdentifier); |
| 101 void detachThread(ThreadIdentifier); | 101 WTF_EXPORT void detachThread(ThreadIdentifier); |
| 102 | 102 |
| 103 void yield(); | 103 WTF_EXPORT void yield(); |
| 104 | 104 |
| 105 void lockAtomicallyInitializedStaticMutex(); | 105 WTF_EXPORT void lockAtomicallyInitializedStaticMutex(); |
| 106 void unlockAtomicallyInitializedStaticMutex(); | 106 WTF_EXPORT void unlockAtomicallyInitializedStaticMutex(); |
| 107 | 107 |
| 108 } // namespace WTF | 108 } // namespace WTF |
| 109 | 109 |
| 110 using WTF::ThreadIdentifier; | 110 using WTF::ThreadIdentifier; |
| 111 using WTF::createThread; | 111 using WTF::createThread; |
| 112 using WTF::currentThread; | 112 using WTF::currentThread; |
| 113 using WTF::detachThread; | 113 using WTF::detachThread; |
| 114 using WTF::waitForThreadCompletion; | 114 using WTF::waitForThreadCompletion; |
| 115 using WTF::yield; | 115 using WTF::yield; |
| 116 | 116 |
| 117 #endif // Threading_h | 117 #endif // Threading_h |
| OLD | NEW |