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

Side by Side Diff: mojo/public/utility/thread_local.h

Issue 134823005: Mojo: re-organize public tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 11 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 | « mojo/public/utility/run_loop_unittest.cc ('k') | mojo/public/utility/thread_local_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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
(...skipping 30 matching lines...) Expand all
41 // 41 //
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 MOJO_PUBLIC_UTILITY_THREAD_LOCAL_H_ 48 #ifndef MOJO_PUBLIC_UTILITY_THREAD_LOCAL_H_
49 #define MOJO_PUBLIC_UTILITY_THREAD_LOCAL_H_ 49 #define MOJO_PUBLIC_UTILITY_THREAD_LOCAL_H_
50 50
51 #include "build/build_config.h" 51 #ifndef _WIN32
52
53 #if defined(OS_POSIX)
54 #include <pthread.h> 52 #include <pthread.h>
55 #endif 53 #endif
56 54
57 #include "mojo/public/system/macros.h" 55 #include "mojo/public/system/macros.h"
58 56
59 namespace mojo { 57 namespace mojo {
60 namespace internal { 58 namespace internal {
61 59
62 // Helper functions that abstract the cross-platform APIs. Do not use directly. 60 // Helper functions that abstract the cross-platform APIs. Do not use directly.
63 struct ThreadLocalPlatform { 61 struct ThreadLocalPlatform {
64 #if defined(OS_WIN) 62 #ifdef _WIN32
65 typedef unsigned long SlotType; 63 typedef unsigned long SlotType;
66 #elif defined(OS_POSIX) 64 #else
67 typedef pthread_key_t SlotType; 65 typedef pthread_key_t SlotType;
68 #endif 66 #endif
69 67
70 static void AllocateSlot(SlotType* slot); 68 static void AllocateSlot(SlotType* slot);
71 static void FreeSlot(SlotType slot); 69 static void FreeSlot(SlotType slot);
72 static void* GetValueFromSlot(SlotType slot); 70 static void* GetValueFromSlot(SlotType slot);
73 static void SetValueInSlot(SlotType slot, void* value); 71 static void SetValueInSlot(SlotType slot, void* value);
74 }; 72 };
75 73
76 } // namespace internal 74 } // namespace internal
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 117
120 private: 118 private:
121 ThreadLocalPointer<void> tlp_; 119 ThreadLocalPointer<void> tlp_;
122 120
123 MOJO_DISALLOW_COPY_AND_ASSIGN(ThreadLocalBoolean); 121 MOJO_DISALLOW_COPY_AND_ASSIGN(ThreadLocalBoolean);
124 }; 122 };
125 123
126 } // namespace mojo 124 } // namespace mojo
127 125
128 #endif // MOJO_PUBLIC_UTILITY_THREAD_LOCAL_H_ 126 #endif // MOJO_PUBLIC_UTILITY_THREAD_LOCAL_H_
OLDNEW
« no previous file with comments | « mojo/public/utility/run_loop_unittest.cc ('k') | mojo/public/utility/thread_local_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698