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