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

Side by Side Diff: base/threading/thread_local_storage.h

Issue 2692273008: Hacky slashy (Closed)
Patch Set: wip Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_THREADING_THREAD_LOCAL_STORAGE_H_ 5 #ifndef BASE_THREADING_THREAD_LOCAL_STORAGE_H_
6 #define BASE_THREADING_THREAD_LOCAL_STORAGE_H_ 6 #define BASE_THREADING_THREAD_LOCAL_STORAGE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 14
15 #if defined(OS_WIN) 15 #if defined(OS_WIN)
16 #include <windows.h> 16 #include <windows.h>
17 #elif defined(OS_POSIX) 17 #elif defined(OS_POSIX)
18 #include <pthread.h> 18 #include <pthread.h>
19 #elif defined(OS_FUCHSIA)
20 #include <threads.h>
19 #endif 21 #endif
20 22
21 namespace base { 23 namespace base {
22 24
23 namespace internal { 25 namespace internal {
24 26
25 // WARNING: You should *NOT* use this class directly. 27 // WARNING: You should *NOT* use this class directly.
26 // PlatformThreadLocalStorage is a low-level abstraction of the OS's TLS 28 // PlatformThreadLocalStorage is a low-level abstraction of the OS's TLS
27 // interface. Instead, you should use one of the following: 29 // interface. Instead, you should use one of the following:
28 // * ThreadLocalBoolean (from thread_local.h) for booleans. 30 // * ThreadLocalBoolean (from thread_local.h) for booleans.
29 // * ThreadLocalPointer (from thread_local.h) for pointers. 31 // * ThreadLocalPointer (from thread_local.h) for pointers.
30 // * ThreadLocalStorage::StaticSlot/Slot for more direct control of the slot. 32 // * ThreadLocalStorage::StaticSlot/Slot for more direct control of the slot.
31 class BASE_EXPORT PlatformThreadLocalStorage { 33 class BASE_EXPORT PlatformThreadLocalStorage {
32 public: 34 public:
33 35
34 #if defined(OS_WIN) 36 #if defined(OS_WIN)
35 typedef unsigned long TLSKey; 37 typedef unsigned long TLSKey;
36 enum : unsigned { TLS_KEY_OUT_OF_INDEXES = TLS_OUT_OF_INDEXES }; 38 enum : unsigned { TLS_KEY_OUT_OF_INDEXES = TLS_OUT_OF_INDEXES };
37 #elif defined(OS_POSIX) 39 #elif defined(OS_POSIX)
38 typedef pthread_key_t TLSKey; 40 typedef pthread_key_t TLSKey;
39 // The following is a "reserved key" which is used in our generic Chromium 41 // The following is a "reserved key" which is used in our generic Chromium
40 // ThreadLocalStorage implementation. We expect that an OS will not return 42 // ThreadLocalStorage implementation. We expect that an OS will not return
41 // such a key, but if it is returned (i.e., the OS tries to allocate it) we 43 // such a key, but if it is returned (i.e., the OS tries to allocate it) we
42 // will just request another key. 44 // will just request another key.
43 enum { TLS_KEY_OUT_OF_INDEXES = 0x7FFFFFFF }; 45 enum { TLS_KEY_OUT_OF_INDEXES = 0x7FFFFFFF };
46 #elif defined(OS_FUCHSIA)
47 typedef tss_t TLSKey;
48 // The following is a "reserved key" which is used in our generic Chromium
49 // ThreadLocalStorage implementation. We expect that an OS will not return
50 // such a key, but if it is returned (i.e., the OS tries to allocate it) we
51 // will just request another key.
52 enum { TLS_KEY_OUT_OF_INDEXES = 0x7FFFFFFF };
44 #endif 53 #endif
45 54
46 // The following methods need to be supported on each OS platform, so that 55 // The following methods need to be supported on each OS platform, so that
47 // the Chromium ThreadLocalStore functionality can be constructed. 56 // the Chromium ThreadLocalStore functionality can be constructed.
48 // Chromium will use these methods to acquire a single OS slot, and then use 57 // Chromium will use these methods to acquire a single OS slot, and then use
49 // that to support a much larger number of Chromium slots (independent of the 58 // that to support a much larger number of Chromium slots (independent of the
50 // OS restrictions). 59 // OS restrictions).
51 // The following returns true if it successfully is able to return an OS 60 // The following returns true if it successfully is able to return an OS
52 // key in |key|. 61 // key in |key|.
53 static bool AllocTLS(TLSKey* key); 62 static bool AllocTLS(TLSKey* key);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 DISALLOW_COPY_AND_ASSIGN(Slot); 160 DISALLOW_COPY_AND_ASSIGN(Slot);
152 }; 161 };
153 162
154 private: 163 private:
155 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage); 164 DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage);
156 }; 165 };
157 166
158 } // namespace base 167 } // namespace base
159 168
160 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_ 169 #endif // BASE_THREADING_THREAD_LOCAL_STORAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698