| 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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 // lifecycle_id of the arena being used. | 552 // lifecycle_id of the arena being used. |
| 553 int64 last_lifecycle_id_seen; | 553 int64 last_lifecycle_id_seen; |
| 554 Block* last_block_used_; | 554 Block* last_block_used_; |
| 555 }; | 555 }; |
| 556 | 556 |
| 557 static const size_t kHeaderSize = sizeof(Block); | 557 static const size_t kHeaderSize = sizeof(Block); |
| 558 #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) | 558 #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) |
| 559 // Android ndk does not support GOOGLE_THREAD_LOCAL keyword so we use a custom
thread | 559 // Android ndk does not support GOOGLE_THREAD_LOCAL keyword so we use a custom
thread |
| 560 // local storage class we implemented. | 560 // local storage class we implemented. |
| 561 // iOS also does not support the GOOGLE_THREAD_LOCAL keyword. | 561 // iOS also does not support the GOOGLE_THREAD_LOCAL keyword. |
| 562 static ThreadCache& thread_cache(); | 562 static ThreadCache& cr_thread_cache(); |
| 563 #elif defined(PROTOBUF_USE_DLLS) | 563 #elif defined(PROTOBUF_USE_DLLS) |
| 564 // Thread local variables cannot be exposed through DLL interface but we can | 564 // Thread local variables cannot be exposed through DLL interface but we can |
| 565 // wrap them in static functions. | 565 // wrap them in static functions. |
| 566 static ThreadCache& thread_cache(); | 566 static ThreadCache& cr_thread_cache(); |
| 567 #else | 567 #else |
| 568 static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_; | 568 static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_; |
| 569 static ThreadCache& thread_cache() { return thread_cache_; } | 569 static ThreadCache& cr_thread_cache() { |
| 570 return thread_cache_; |
| 571 } |
| 570 #endif | 572 #endif |
| 571 | 573 |
| 572 // SFINAE for skipping addition to delete list for a message type when created | 574 // SFINAE for skipping addition to delete list for a message type when created |
| 573 // with CreateMessage. This is mainly to skip proto2/proto1 message objects | 575 // with CreateMessage. This is mainly to skip proto2/proto1 message objects |
| 574 // with cc_enable_arenas=true from being part of the delete list. Also, note, | 576 // with cc_enable_arenas=true from being part of the delete list. Also, note, |
| 575 // compiler will optimize out the branch in CreateInternal<T>. | 577 // compiler will optimize out the branch in CreateInternal<T>. |
| 576 template<typename T> | 578 template<typename T> |
| 577 static inline bool SkipDeleteList(typename T::DestructorSkippable_*) { | 579 static inline bool SkipDeleteList(typename T::DestructorSkippable_*) { |
| 578 return true; | 580 return true; |
| 579 } | 581 } |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 // TODO(rohananil, cfallin): We could pass in a sub-arena into this method | 869 // TODO(rohananil, cfallin): We could pass in a sub-arena into this method |
| 868 // to avoid polluting blocks of this arena with list nodes. This would help in | 870 // to avoid polluting blocks of this arena with list nodes. This would help in |
| 869 // mixed mode (where many protobufs have cc_enable_arenas=false), and is an | 871 // mixed mode (where many protobufs have cc_enable_arenas=false), and is an |
| 870 // alternative to a chunked linked-list, but with extra overhead of *next. | 872 // alternative to a chunked linked-list, but with extra overhead of *next. |
| 871 void AddListNode(void* elem, void (*cleanup)(void*)); | 873 void AddListNode(void* elem, void (*cleanup)(void*)); |
| 872 // Delete or Destruct all objects owned by the arena. | 874 // Delete or Destruct all objects owned by the arena. |
| 873 void CleanupList(); | 875 void CleanupList(); |
| 874 uint64 ResetInternal(); | 876 uint64 ResetInternal(); |
| 875 | 877 |
| 876 inline void SetThreadCacheBlock(Block* block) { | 878 inline void SetThreadCacheBlock(Block* block) { |
| 877 thread_cache().last_block_used_ = block; | 879 cr_thread_cache().last_block_used_ = block; |
| 878 thread_cache().last_lifecycle_id_seen = lifecycle_id_; | 880 cr_thread_cache().last_lifecycle_id_seen = lifecycle_id_; |
| 879 } | 881 } |
| 880 | 882 |
| 881 int64 lifecycle_id_; // Unique for each arena. Changes on Reset(). | 883 int64 lifecycle_id_; // Unique for each arena. Changes on Reset(). |
| 882 | 884 |
| 883 google::protobuf::internal::AtomicWord blocks_; // Head of linked list of all
allocated blocks | 885 google::protobuf::internal::AtomicWord blocks_; // Head of linked list of all
allocated blocks |
| 884 google::protobuf::internal::AtomicWord hint_; // Fast thread-local block ac
cess | 886 google::protobuf::internal::AtomicWord hint_; // Fast thread-local block ac
cess |
| 885 | 887 |
| 886 // Node contains the ptr of the object to be cleaned up and the associated | 888 // Node contains the ptr of the object to be cleaned up and the associated |
| 887 // cleanup function ptr. | 889 // cleanup function ptr. |
| 888 struct Node { | 890 struct Node { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 918 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Arena); | 920 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Arena); |
| 919 }; | 921 }; |
| 920 | 922 |
| 921 // Defined above for supporting environments without RTTI. | 923 // Defined above for supporting environments without RTTI. |
| 922 #undef RTTI_TYPE_ID | 924 #undef RTTI_TYPE_ID |
| 923 | 925 |
| 924 } // namespace protobuf | 926 } // namespace protobuf |
| 925 | 927 |
| 926 } // namespace google | 928 } // namespace google |
| 927 #endif // GOOGLE_PROTOBUF_ARENA_H__ | 929 #endif // GOOGLE_PROTOBUF_ARENA_H__ |
| OLD | NEW |