| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2011, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| 11 // copyright notice, this list of conditions and the following disclaimer | 11 // copyright notice, this list of conditions and the following disclaimer |
| (...skipping 23 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 #include <config.h> | 36 #include <config.h> |
| 37 #ifdef HAVE_PTHREAD | 37 #ifdef HAVE_PTHREAD |
| 38 #include <pthread.h> // for pthread_t, pthread_key_t | 38 #include <pthread.h> // for pthread_t, pthread_key_t |
| 39 #endif | 39 #endif |
| 40 #include <stddef.h> // for size_t, NULL | 40 #include <stddef.h> // for size_t, NULL |
| 41 #ifdef HAVE_STDINT_H | 41 #ifdef HAVE_STDINT_H |
| 42 #include <stdint.h> // for uint32_t, uint64_t | 42 #include <stdint.h> // for uint32_t, uint64_t |
| 43 #endif | 43 #endif |
| 44 #include <sys/types.h> // for ssize_t | 44 #include <sys/types.h> // for ssize_t |
| 45 #include "common.h" | 45 #include "common.h" // for SizeMap, kMaxSize, etc |
| 46 #include "linked_list.h" | 46 #include "free_list.h" // for FL_Pop, FL_PopRange, etc |
| 47 #include "internal_logging.h" // for ASSERT, etc |
| 47 #include "maybe_threads.h" | 48 #include "maybe_threads.h" |
| 48 #include "page_heap_allocator.h" | |
| 49 #include "sampler.h" | |
| 50 #include "static_vars.h" | |
| 51 | |
| 52 #include "common.h" // for SizeMap, kMaxSize, etc | |
| 53 #include "internal_logging.h" // for ASSERT, etc | |
| 54 #include "linked_list.h" // for SLL_Pop, SLL_PopRange, etc | |
| 55 #include "page_heap_allocator.h" // for PageHeapAllocator | 49 #include "page_heap_allocator.h" // for PageHeapAllocator |
| 56 #include "sampler.h" // for Sampler | 50 #include "sampler.h" // for Sampler |
| 57 #include "static_vars.h" // for Static | 51 #include "static_vars.h" // for Static |
| 58 | 52 |
| 59 namespace tcmalloc { | 53 namespace tcmalloc { |
| 60 | 54 |
| 61 // Even if we have support for thread-local storage in the compiler | 55 // Even if we have support for thread-local storage in the compiler |
| 62 // and linker, the OS may not support it. We need to check that at | 56 // and linker, the OS may not support it. We need to check that at |
| 63 // runtime. Right now, we have to keep a manual set of "bad" OSes. | 57 // runtime. Right now, we have to keep a manual set of "bad" OSes. |
| 64 #if defined(HAVE_TLS) | 58 #if defined(HAVE_TLS) |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // Is list empty? | 185 // Is list empty? |
| 192 bool empty() const { | 186 bool empty() const { |
| 193 return list_ == NULL; | 187 return list_ == NULL; |
| 194 } | 188 } |
| 195 | 189 |
| 196 // Low-water mark management | 190 // Low-water mark management |
| 197 int lowwatermark() const { return lowater_; } | 191 int lowwatermark() const { return lowater_; } |
| 198 void clear_lowwatermark() { lowater_ = length_; } | 192 void clear_lowwatermark() { lowater_ = length_; } |
| 199 | 193 |
| 200 void Push(void* ptr) { | 194 void Push(void* ptr) { |
| 201 SLL_Push(&list_, ptr); | 195 FL_Push(&list_, ptr); |
| 202 length_++; | 196 length_++; |
| 203 } | 197 } |
| 204 | 198 |
| 205 void* Pop() { | 199 void* Pop() { |
| 206 ASSERT(list_ != NULL); | 200 ASSERT(list_ != NULL); |
| 207 length_--; | 201 length_--; |
| 208 if (length_ < lowater_) lowater_ = length_; | 202 if (length_ < lowater_) lowater_ = length_; |
| 209 return SLL_Pop(&list_); | 203 return FL_Pop(&list_); |
| 210 } | 204 } |
| 211 | 205 |
| 212 void PushRange(int N, void *start, void *end) { | 206 void PushRange(int N, void *start, void *end) { |
| 213 SLL_PushRange(&list_, start, end); | 207 FL_PushRange(&list_, start, end); |
| 214 length_ += N; | 208 length_ += N; |
| 215 } | 209 } |
| 216 | 210 |
| 217 void PopRange(int N, void **start, void **end) { | 211 void PopRange(int N, void **start, void **end) { |
| 218 SLL_PopRange(&list_, N, start, end); | 212 FL_PopRange(&list_, N, start, end); |
| 219 ASSERT(length_ >= N); | 213 ASSERT(length_ >= N); |
| 220 length_ -= N; | 214 length_ -= N; |
| 221 if (length_ < lowater_) lowater_ = length_; | 215 if (length_ < lowater_) lowater_ = length_; |
| 222 } | 216 } |
| 223 }; | 217 }; |
| 224 | 218 |
| 225 // Gets and returns an object from the central cache, and, if possible, | 219 // Gets and returns an object from the central cache, and, if possible, |
| 226 // also adds some objects of that size class to this thread cache. | 220 // also adds some objects of that size class to this thread cache. |
| 227 void* FetchFromCentralCache(size_t cl, size_t byte_size); | 221 void* FetchFromCentralCache(size_t cl, size_t byte_size); |
| 228 | 222 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // because we may be in the thread destruction code and may have | 383 // because we may be in the thread destruction code and may have |
| 390 // already cleaned up the cache for this thread. | 384 // already cleaned up the cache for this thread. |
| 391 inline ThreadCache* ThreadCache::GetCacheIfPresent() { | 385 inline ThreadCache* ThreadCache::GetCacheIfPresent() { |
| 392 if (!tsd_inited_) return NULL; | 386 if (!tsd_inited_) return NULL; |
| 393 return GetThreadHeap(); | 387 return GetThreadHeap(); |
| 394 } | 388 } |
| 395 | 389 |
| 396 } // namespace tcmalloc | 390 } // namespace tcmalloc |
| 397 | 391 |
| 398 #endif // TCMALLOC_THREAD_CACHE_H_ | 392 #endif // TCMALLOC_THREAD_CACHE_H_ |
| OLD | NEW |