OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 | 33 |
34 #ifdef ADDRESS_SANITIZER | 34 #ifdef ADDRESS_SANITIZER |
35 #include <sanitizer/asan_interface.h> | 35 #include <sanitizer/asan_interface.h> |
36 #endif | 36 #endif |
37 | 37 |
38 namespace google { | 38 namespace google { |
39 namespace protobuf { | 39 namespace protobuf { |
40 | 40 |
41 | 41 |
42 google::protobuf::internal::SequenceNumber Arena::lifecycle_id_generator_; | |
43 #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) | 42 #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) |
44 Arena::ThreadCache& Arena::thread_cache() { | 43 Arena::ThreadCache& Arena::thread_cache() { |
45 static internal::ThreadLocalStorage<ThreadCache>* thread_cache_ = | 44 static internal::ThreadLocalStorage<ThreadCache>* thread_cache_ = |
46 new internal::ThreadLocalStorage<ThreadCache>(); | 45 new internal::ThreadLocalStorage<ThreadCache>(); |
47 return *thread_cache_->Get(); | 46 return *thread_cache_->Get(); |
48 } | 47 } |
49 #elif defined(PROTOBUF_USE_DLLS) | 48 #elif defined(PROTOBUF_USE_DLLS) |
50 Arena::ThreadCache& Arena::thread_cache() { | 49 Arena::ThreadCache& Arena::thread_cache() { |
51 static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_ = { -1, NULL }; | 50 static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_ = { -1, NULL }; |
52 return thread_cache_; | 51 return thread_cache_; |
53 } | 52 } |
54 #else | 53 #else |
55 GOOGLE_THREAD_LOCAL Arena::ThreadCache Arena::thread_cache_ = { -1, NULL }; | 54 GOOGLE_THREAD_LOCAL Arena::ThreadCache Arena::thread_cache_ = { -1, NULL }; |
56 #endif | 55 #endif |
57 | 56 |
58 void Arena::Init() { | 57 void Arena::Init() { |
59 lifecycle_id_ = lifecycle_id_generator_.GetNext(); | 58 lifecycle_id_ = internal::cr_lifecycle_id_generator_.GetNext(); |
60 blocks_ = 0; | 59 blocks_ = 0; |
61 hint_ = 0; | 60 hint_ = 0; |
62 owns_first_block_ = true; | 61 owns_first_block_ = true; |
63 cleanup_list_ = 0; | 62 cleanup_list_ = 0; |
64 | 63 |
65 if (options_.initial_block != NULL && options_.initial_block_size > 0) { | 64 if (options_.initial_block != NULL && options_.initial_block_size > 0) { |
66 GOOGLE_CHECK_GE(options_.initial_block_size, sizeof(Block)) | 65 GOOGLE_CHECK_GE(options_.initial_block_size, sizeof(Block)) |
67 << ": Initial block size too small for header."; | 66 << ": Initial block size too small for header."; |
68 | 67 |
69 // Add first unowned block to list. | 68 // Add first unowned block to list. |
(...skipping 22 matching lines...) Expand all Loading... |
92 uint64 space_allocated = ResetInternal(); | 91 uint64 space_allocated = ResetInternal(); |
93 | 92 |
94 // Call the destruction hook | 93 // Call the destruction hook |
95 if (options_.on_arena_destruction != NULL) { | 94 if (options_.on_arena_destruction != NULL) { |
96 options_.on_arena_destruction(this, hooks_cookie_, space_allocated); | 95 options_.on_arena_destruction(this, hooks_cookie_, space_allocated); |
97 } | 96 } |
98 } | 97 } |
99 | 98 |
100 uint64 Arena::Reset() { | 99 uint64 Arena::Reset() { |
101 // Invalidate any ThreadCaches pointing to any blocks we just destroyed. | 100 // Invalidate any ThreadCaches pointing to any blocks we just destroyed. |
102 lifecycle_id_ = lifecycle_id_generator_.GetNext(); | 101 lifecycle_id_ = internal::cr_lifecycle_id_generator_.GetNext(); |
103 return ResetInternal(); | 102 return ResetInternal(); |
104 } | 103 } |
105 | 104 |
106 uint64 Arena::ResetInternal() { | 105 uint64 Arena::ResetInternal() { |
107 CleanupList(); | 106 CleanupList(); |
108 uint64 space_allocated = FreeBlocks(); | 107 uint64 space_allocated = FreeBlocks(); |
109 | 108 |
110 // Call the reset hook | 109 // Call the reset hook |
111 if (options_.on_arena_reset != NULL) { | 110 if (options_.on_arena_reset != NULL) { |
112 options_.on_arena_reset(this, hooks_cookie_, space_allocated); | 111 options_.on_arena_reset(this, hooks_cookie_, space_allocated); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // entry per thread. | 311 // entry per thread. |
313 Block* b = reinterpret_cast<Block*>(google::protobuf::internal::Acquire_Load(&
blocks_)); | 312 Block* b = reinterpret_cast<Block*>(google::protobuf::internal::Acquire_Load(&
blocks_)); |
314 while (b != NULL && b->owner != me) { | 313 while (b != NULL && b->owner != me) { |
315 b = b->next; | 314 b = b->next; |
316 } | 315 } |
317 return b; | 316 return b; |
318 } | 317 } |
319 | 318 |
320 } // namespace protobuf | 319 } // namespace protobuf |
321 } // namespace google | 320 } // namespace google |
OLD | NEW |