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 17 matching lines...) Expand all Loading... |
28 */ | 28 */ |
29 | 29 |
30 #ifndef Threading_h | 30 #ifndef Threading_h |
31 #define Threading_h | 31 #define Threading_h |
32 | 32 |
33 #include "wtf/Atomics.h" | 33 #include "wtf/Atomics.h" |
34 #include "wtf/TypeTraits.h" | 34 #include "wtf/TypeTraits.h" |
35 #include "wtf/WTFExport.h" | 35 #include "wtf/WTFExport.h" |
36 #include <stdint.h> | 36 #include <stdint.h> |
37 | 37 |
38 // For portability, we do not make use of C++11 thread-safe statics, as supporte
d | 38 // For portability, we do not make use of C++11 thread-safe statics, as |
39 // by some toolchains. Make use of double-checked locking to reduce overhead. | 39 // supported by some toolchains. Make use of double-checked locking to reduce |
40 // Note that this uses system-wide default lock, and cannot be used before | 40 // overhead. Note that this uses system-wide default lock, and cannot be used |
41 // WTF::initializeThreading() is called. | 41 // before WTF::initializeThreading() is called. |
42 #define DEFINE_THREAD_SAFE_STATIC_LOCAL(T, name, initializer) \ | 42 #define DEFINE_THREAD_SAFE_STATIC_LOCAL(T, name, initializer) \ |
43 /* Init to nullptr is thread-safe on all implementations. */ \ | 43 /* Init to nullptr is thread-safe on all implementations. */ \ |
44 static void* name##Pointer = nullptr; \ | 44 static void* name##Pointer = nullptr; \ |
45 if (!WTF::acquireLoad(&name##Pointer)) { \ | 45 if (!WTF::acquireLoad(&name##Pointer)) { \ |
46 WTF::lockAtomicallyInitializedStaticMutex(); \ | 46 WTF::lockAtomicallyInitializedStaticMutex(); \ |
47 if (!WTF::acquireLoad(&name##Pointer)) { \ | 47 if (!WTF::acquireLoad(&name##Pointer)) { \ |
48 std::remove_const<T>::type* initializerResult = initializer; \ | 48 std::remove_const<T>::type* initializerResult = initializer; \ |
49 WTF::releaseStore(&name##Pointer, initializerResult); \ | 49 WTF::releaseStore(&name##Pointer, initializerResult); \ |
50 } \ | 50 } \ |
51 WTF::unlockAtomicallyInitializedStaticMutex(); \ | 51 WTF::unlockAtomicallyInitializedStaticMutex(); \ |
(...skipping 18 matching lines...) Expand all Loading... |
70 WTF_EXPORT bool isBeforeThreadCreated(); | 70 WTF_EXPORT bool isBeforeThreadCreated(); |
71 WTF_EXPORT void willCreateThread(); | 71 WTF_EXPORT void willCreateThread(); |
72 #endif | 72 #endif |
73 | 73 |
74 } // namespace WTF | 74 } // namespace WTF |
75 | 75 |
76 using WTF::ThreadIdentifier; | 76 using WTF::ThreadIdentifier; |
77 using WTF::currentThread; | 77 using WTF::currentThread; |
78 | 78 |
79 #endif // Threading_h | 79 #endif // Threading_h |
OLD | NEW |