From fccb146e3fe437b0df1e9c50d4b8e1080ddb4bd9 Mon Sep 17 00:00:00 2001 From: "kenton@google.com" Date: Fri, 18 Dec 2009 02:11:36 +0000 Subject: Massive roll-up of changes. See CHANGES.txt. --- src/google/protobuf/dynamic_message.h | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/google/protobuf/dynamic_message.h') diff --git a/src/google/protobuf/dynamic_message.h b/src/google/protobuf/dynamic_message.h index f38d3b09..81dd2c63 100644 --- a/src/google/protobuf/dynamic_message.h +++ b/src/google/protobuf/dynamic_message.h @@ -73,9 +73,25 @@ class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { // Construct a DynamicMessageFactory that will search for extensions in // the given DescriptorPool. + // + // DEPRECATED: Use CodedInputStream::SetExtensionRegistry() to tell the + // parser to look for extensions in an alternate pool. However, note that + // this is almost never what you want to do. Almost all users should use + // the zero-arg constructor. DynamicMessageFactory(const DescriptorPool* pool); + ~DynamicMessageFactory(); + // Call this to tell the DynamicMessageFactory that if it is given a + // Descriptor d for which: + // d->file()->pool() == DescriptorPool::generated_pool(), + // then it should delegate to MessageFactory::generated_factory() instead + // of constructing a dynamic implementation of the message. In theory there + // is no down side to doing this, so it may become the default in the future. + void SetDelegateToGeneratedFactory(bool enable) { + delegate_to_generated_factory_ = enable; + } + // implements MessageFactory --------------------------------------- // Given a Descriptor, constructs the default (prototype) Message of that @@ -92,14 +108,12 @@ class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { // The given descriptor must outlive the returned message, and hence must // outlive the DynamicMessageFactory. // - // Note that while GetPrototype() is idempotent, it is not const. This - // implies that it is not thread-safe to call GetPrototype() on the same - // DynamicMessageFactory in two different threads simultaneously. However, - // the returned objects are just as thread-safe as any other Message. + // The method is thread-safe. const Message* GetPrototype(const Descriptor* type); private: const DescriptorPool* pool_; + bool delegate_to_generated_factory_; // This struct just contains a hash_map. We can't #include from // this header due to hacks needed for hash_map portability in the open source @@ -108,6 +122,10 @@ class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { // headers may only #include other public headers. struct PrototypeMap; scoped_ptr prototypes_; + mutable Mutex prototypes_mutex_; + + friend class DynamicMessage; + const Message* GetPrototypeNoLock(const Descriptor* type); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessageFactory); }; @@ -116,4 +134,3 @@ class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { } // namespace google #endif // GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ - -- cgit v1.2.3