Page Speed Optimization Libraries
1.7.30.3
|
#include "rewrite_options.h"
Public Member Functions | |
virtual void | Merge (const OptionBase *src_base) |
void | checked_set (const int64 &value) |
ThreadSystem::RWLock * | mutex () const |
void | set_mutex (ThreadSystem::RWLock *lock) |
Like Option<int64>, but merge by taking the Max of the two values. Note that this could be templatized on type in which case we'd need to inline the implementation of Merge.
This class has an optional mutex for allowing Apache to flush cache by mutating its global_options(). Note that global_options() is never used directly in a rewrite_driver, but is cloned with this optional Mutex held.
The "optional" mutex is always present, but it defaults to a NullRWLock, which has empty implementations of all locking/unlocking functions. Only in Apache (currently) do we override that with a real RWLock from the thread system.
void net_instaweb::RewriteOptions::MutexedOptionInt64MergeWithMax::checked_set | ( | const int64 & | value | ) | [inline] |
The value() must only be taken when the mutex is held. This is only called by RewriteOptions::UpdateCacheInvalidationTimestampMs and MutexedOptionInt64MergeWithMax::Merge, which are holding locks when calling value().
Note that we don't require or take the lock for set(), so we don't override set. When updating or merging, we already have a lock and can't take it again. When writing the invalidation timestamp at initial configuration time, we don't need the lock.
virtual void net_instaweb::RewriteOptions::MutexedOptionInt64MergeWithMax::Merge | ( | const OptionBase * | src_base | ) | [virtual] |
Merges src_base into this by taking the maximum of the two values.
We expect ot have exclusive access to 'this' and don't need to lock it, but we use locked access to src_base->value().
Reimplemented from net_instaweb::RewriteOptions::OptionTemplateBase< int64 >.
ThreadSystem::RWLock* net_instaweb::RewriteOptions::MutexedOptionInt64MergeWithMax::mutex | ( | ) | const [inline] |
Returns the mutex for this object. When this class is constructed it gets a NullRWLock which doesn't actually lock anything. This is because we generally initialize RewriteOptions from only one thread, and thereafter do only reads. However, one exception is the cache-invalidation timestamp in the global_options for Apache ServerContexts, which can be written from any thread handling a request, particularly with the Worker MPM. So we install a real RWLock* for Apache's global_options.
Also note that this mutex, when installed, is also used to lock access to RewriteOptions::signature(), which depends on the cache invalidation timestamp.
void net_instaweb::RewriteOptions::MutexedOptionInt64MergeWithMax::set_mutex | ( | ThreadSystem::RWLock * | lock | ) | [inline] |
Takes ownership of mutex. Note that by default, mutex() has a NullRWLock. Only by calling set_mutex do we add locking semantics for the invalidation timestamp & signature. If we allow other settings to be spontaneously changed we will have to add further locking.