Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: Source/wtf/ThreadSpecific.h

Issue 15861022: Build WTF as dll in component build (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix AutoDrainedPool ctor and ThreadSpecificThreadExit exports Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/wtf/SHA1.h ('k') | Source/wtf/Threading.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Jian Li <jianli@chromium.org> 3 * Copyright (C) 2009 Jian Li <jianli@chromium.org>
4 * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com> 4 * Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com>
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 24 matching lines...) Expand all
35 * repeatedly if there is still non-NULL value associated with the function. 35 * repeatedly if there is still non-NULL value associated with the function.
36 * @ In Windows native implementation, the destructor function will be called 36 * @ In Windows native implementation, the destructor function will be called
37 * only once. 37 * only once.
38 * This semantic discrepancy does not impose any problem because nowhere in 38 * This semantic discrepancy does not impose any problem because nowhere in
39 * WebKit the repeated call bahavior is utilized. 39 * WebKit the repeated call bahavior is utilized.
40 */ 40 */
41 41
42 #ifndef WTF_ThreadSpecific_h 42 #ifndef WTF_ThreadSpecific_h
43 #define WTF_ThreadSpecific_h 43 #define WTF_ThreadSpecific_h
44 44
45 #include <wtf/Noncopyable.h> 45 #include "wtf/Noncopyable.h"
46 #include <wtf/StdLibExtras.h> 46 #include "wtf/StdLibExtras.h"
47 #include "wtf/WTFExport.h"
47 48
48 #if USE(PTHREADS) 49 #if USE(PTHREADS)
49 #include <pthread.h> 50 #include <pthread.h>
50 #elif OS(WINDOWS) 51 #elif OS(WINDOWS)
51 #include <windows.h> 52 #include <windows.h>
52 #endif 53 #endif
53 54
54 namespace WTF { 55 namespace WTF {
55 56
56 #if OS(WINDOWS) 57 #if OS(WINDOWS)
57 // ThreadSpecificThreadExit should be called each time when a thread is detached . 58 // ThreadSpecificThreadExit should be called each time when a thread is detached .
58 // This is done automatically for threads created with WTF::createThread. 59 // This is done automatically for threads created with WTF::createThread.
59 void ThreadSpecificThreadExit(); 60 WTF_EXPORT void ThreadSpecificThreadExit();
60 #endif 61 #endif
61 62
62 template<typename T> class ThreadSpecific { 63 template<typename T> class ThreadSpecific {
63 WTF_MAKE_NONCOPYABLE(ThreadSpecific); 64 WTF_MAKE_NONCOPYABLE(ThreadSpecific);
64 public: 65 public:
65 ThreadSpecific(); 66 ThreadSpecific();
66 bool isSet(); // Useful as a fast check to see if this thread has set this v alue. 67 bool isSet(); // Useful as a fast check to see if this thread has set this v alue.
67 T* operator->(); 68 T* operator->();
68 operator T*(); 69 operator T*();
69 T& operator*(); 70 T& operator*();
70 71
71 private: 72 private:
72 #if OS(WINDOWS) 73 #if OS(WINDOWS)
73 friend void ThreadSpecificThreadExit(); 74 WTF_EXPORT friend void ThreadSpecificThreadExit();
74 #endif 75 #endif
75 76
76 // Not implemented. It's technically possible to destroy a thread specific k ey, but one would need 77 // Not implemented. It's technically possible to destroy a thread specific k ey, but one would need
77 // to make sure that all values have been destroyed already (usually, that a ll threads that used it 78 // to make sure that all values have been destroyed already (usually, that a ll threads that used it
78 // have exited). It's unlikely that any user of this call will be in that si tuation - and having 79 // have exited). It's unlikely that any user of this call will be in that si tuation - and having
79 // a destructor defined can be confusing, given that it has such strong pre- requisites to work correctly. 80 // a destructor defined can be confusing, given that it has such strong pre- requisites to work correctly.
80 ~ThreadSpecific(); 81 ~ThreadSpecific();
81 82
82 T* get(); 83 T* get();
83 void set(T*); 84 void set(T*);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // TLS_OUT_OF_INDEXES is not defined on WinCE. 158 // TLS_OUT_OF_INDEXES is not defined on WinCE.
158 #ifndef TLS_OUT_OF_INDEXES 159 #ifndef TLS_OUT_OF_INDEXES
159 #define TLS_OUT_OF_INDEXES 0xffffffff 160 #define TLS_OUT_OF_INDEXES 0xffffffff
160 #endif 161 #endif
161 162
162 // The maximum number of TLS keys that can be created. For simplification, we as sume that: 163 // The maximum number of TLS keys that can be created. For simplification, we as sume that:
163 // 1) Once the instance of ThreadSpecific<> is created, it will not be destructe d until the program dies. 164 // 1) Once the instance of ThreadSpecific<> is created, it will not be destructe d until the program dies.
164 // 2) We do not need to hold many instances of ThreadSpecific<> data. This fixed number should be far enough. 165 // 2) We do not need to hold many instances of ThreadSpecific<> data. This fixed number should be far enough.
165 const int kMaxTlsKeySize = 256; 166 const int kMaxTlsKeySize = 256;
166 167
167 long& tlsKeyCount(); 168 WTF_EXPORT long& tlsKeyCount();
168 DWORD* tlsKeys(); 169 WTF_EXPORT DWORD* tlsKeys();
169 170
170 class PlatformThreadSpecificKey; 171 class PlatformThreadSpecificKey;
171 typedef PlatformThreadSpecificKey* ThreadSpecificKey; 172 typedef PlatformThreadSpecificKey* ThreadSpecificKey;
172 173
173 void threadSpecificKeyCreate(ThreadSpecificKey*, void (*)(void *)); 174 WTF_EXPORT void threadSpecificKeyCreate(ThreadSpecificKey*, void (*)(void *));
174 void threadSpecificKeyDelete(ThreadSpecificKey); 175 WTF_EXPORT void threadSpecificKeyDelete(ThreadSpecificKey);
175 void threadSpecificSet(ThreadSpecificKey, void*); 176 WTF_EXPORT void threadSpecificSet(ThreadSpecificKey, void*);
176 void* threadSpecificGet(ThreadSpecificKey); 177 WTF_EXPORT void* threadSpecificGet(ThreadSpecificKey);
177 178
178 template<typename T> 179 template<typename T>
179 inline ThreadSpecific<T>::ThreadSpecific() 180 inline ThreadSpecific<T>::ThreadSpecific()
180 : m_index(-1) 181 : m_index(-1)
181 { 182 {
182 DWORD tlsKey = TlsAlloc(); 183 DWORD tlsKey = TlsAlloc();
183 if (tlsKey == TLS_OUT_OF_INDEXES) 184 if (tlsKey == TLS_OUT_OF_INDEXES)
184 CRASH(); 185 CRASH();
185 186
186 m_index = InterlockedIncrement(&tlsKeyCount()) - 1; 187 m_index = InterlockedIncrement(&tlsKeyCount()) - 1;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 270
270 template<typename T> 271 template<typename T>
271 inline T& ThreadSpecific<T>::operator*() 272 inline T& ThreadSpecific<T>::operator*()
272 { 273 {
273 return *operator T*(); 274 return *operator T*();
274 } 275 }
275 276
276 } // namespace WTF 277 } // namespace WTF
277 278
278 #endif // WTF_ThreadSpecific_h 279 #endif // WTF_ThreadSpecific_h
OLDNEW
« no previous file with comments | « Source/wtf/SHA1.h ('k') | Source/wtf/Threading.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698