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

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

Issue 6747014: Base: Last set of files to use BASE_API (for base.dll) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 9 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // WARNING: Thread local storage is a bit tricky to get right. Please make 5 // WARNING: Thread local storage is a bit tricky to get right. Please make
6 // sure that this is really the proper solution for what you're trying to 6 // sure that this is really the proper solution for what you're trying to
7 // achieve. Don't prematurely optimize, most likely you can just use a Lock. 7 // achieve. Don't prematurely optimize, most likely you can just use a Lock.
8 // 8 //
9 // These classes implement a wrapper around the platform's TLS storage 9 // These classes implement a wrapper around the platform's TLS storage
10 // mechanism. On construction, they will allocate a TLS slot, and free the 10 // mechanism. On construction, they will allocate a TLS slot, and free the
11 // TLS slot on destruction. No memory management (creation or destruction) is 11 // TLS slot on destruction. No memory management (creation or destruction) is
(...skipping 30 matching lines...) Expand all
42 // // Return the current MyClass associated with the calling thread, can be 42 // // Return the current MyClass associated with the calling thread, can be
43 // // NULL if there isn't a MyClass associated. 43 // // NULL if there isn't a MyClass associated.
44 // MyClass* MyClass::current() { 44 // MyClass* MyClass::current() {
45 // return Singleton<ThreadLocalPointer<MyClass> >::get()->Get(); 45 // return Singleton<ThreadLocalPointer<MyClass> >::get()->Get();
46 // } 46 // }
47 47
48 #ifndef BASE_THREADING_THREAD_LOCAL_H_ 48 #ifndef BASE_THREADING_THREAD_LOCAL_H_
49 #define BASE_THREADING_THREAD_LOCAL_H_ 49 #define BASE_THREADING_THREAD_LOCAL_H_
50 #pragma once 50 #pragma once
51 51
52 #include "base/base_api.h"
52 #include "base/basictypes.h" 53 #include "base/basictypes.h"
53 54
54 #if defined(OS_POSIX) 55 #if defined(OS_POSIX)
55 #include <pthread.h> 56 #include <pthread.h>
56 #endif 57 #endif
57 58
58 namespace base { 59 namespace base {
59 60
60 namespace internal { 61 namespace internal {
61 62
62 // Helper functions that abstract the cross-platform APIs. Do not use directly. 63 // Helper functions that abstract the cross-platform APIs. Do not use directly.
63 struct ThreadLocalPlatform { 64 struct BASE_API ThreadLocalPlatform {
64 #if defined(OS_WIN) 65 #if defined(OS_WIN)
65 typedef unsigned long SlotType; 66 typedef unsigned long SlotType;
66 #elif defined(OS_POSIX) 67 #elif defined(OS_POSIX)
67 typedef pthread_key_t SlotType; 68 typedef pthread_key_t SlotType;
68 #endif 69 #endif
69 70
70 static void AllocateSlot(SlotType& slot); 71 static void AllocateSlot(SlotType& slot);
71 static void FreeSlot(SlotType& slot); 72 static void FreeSlot(SlotType& slot);
72 static void* GetValueFromSlot(SlotType& slot); 73 static void* GetValueFromSlot(SlotType& slot);
73 static void SetValueInSlot(SlotType& slot, void* value); 74 static void SetValueInSlot(SlotType& slot, void* value);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 119
119 private: 120 private:
120 ThreadLocalPointer<void> tlp_; 121 ThreadLocalPointer<void> tlp_;
121 122
122 DISALLOW_COPY_AND_ASSIGN(ThreadLocalBoolean); 123 DISALLOW_COPY_AND_ASSIGN(ThreadLocalBoolean);
123 }; 124 };
124 125
125 } // namespace base 126 } // namespace base
126 127
127 #endif // BASE_THREADING_THREAD_LOCAL_H_ 128 #endif // BASE_THREADING_THREAD_LOCAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698