Page Speed Optimization Libraries
1.4.26.1
|
Go to the source code of this file.
Classes | |
class | RefCountedOwner< T > |
See file comment. NET_INSTAWEB_UTIL_PUBLIC_REF_COUNTED_OWNER_H_. More... | |
class | RefCountedOwner< T >::Family |
A RefCountedOwner<T> helps a family of objects manage lifetime of a single shared T, initializing it with the first owner, and getting rid of it when all the owners are gone. This is different from a singleton in that there is no limit to having only a single instance of T, but rather a single T instance per a single RefCountedOwner<T>::Family instance.
Warning: this class doesn't provide for full thread safety; as it assumes that all the owners will be created and destroyed in a single thread. The accessors, however, are readonly, so can be used from multiple threads if their use follows the sequential initialization and precedes object destruction.
Typical usage: class OwnerClass { static RefCountedOwner<SharedClass>::Family shared_family_; RefCountedOwner<SharedClass> shared_; };
OwnerClass::OwnerClass() : shared_(&shared_family_) { if (shared_.ShouldInitialize()) { shared_->Initialize(new SharedClass(...)); } }