am 97ece7a9: Merge "EGL: add deferred saving of the cache" into ics-mr1
* commit '97ece7a95f76ec724633d4f4764291ea4dc20933': EGL: add deferred saving of the cache
This commit is contained in:
commit
d4e367fb86
@ -34,6 +34,9 @@ static const size_t maxTotalSize = 64 * 1024;
|
|||||||
static const char* cacheFileMagic = "EGL$";
|
static const char* cacheFileMagic = "EGL$";
|
||||||
static const size_t cacheFileHeaderSize = 8;
|
static const size_t cacheFileHeaderSize = 8;
|
||||||
|
|
||||||
|
// The time in seconds to wait before saving newly inserted cache entries.
|
||||||
|
static const unsigned int deferredSaveDelay = 4;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
namespace android {
|
namespace android {
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -128,6 +131,30 @@ void egl_cache_t::setBlob(const void* key, EGLsizei keySize, const void* value,
|
|||||||
if (mInitialized) {
|
if (mInitialized) {
|
||||||
sp<BlobCache> bc = getBlobCacheLocked();
|
sp<BlobCache> bc = getBlobCacheLocked();
|
||||||
bc->set(key, keySize, value, valueSize);
|
bc->set(key, keySize, value, valueSize);
|
||||||
|
|
||||||
|
if (!mSavePending) {
|
||||||
|
class DeferredSaveThread : public Thread {
|
||||||
|
public:
|
||||||
|
DeferredSaveThread() : Thread(false) {}
|
||||||
|
|
||||||
|
virtual bool threadLoop() {
|
||||||
|
sleep(deferredSaveDelay);
|
||||||
|
egl_cache_t* c = egl_cache_t::get();
|
||||||
|
Mutex::Autolock lock(c->mMutex);
|
||||||
|
if (c->mInitialized) {
|
||||||
|
c->saveBlobCacheLocked();
|
||||||
|
}
|
||||||
|
c->mSavePending = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// The thread will hold a strong ref to itself until it has finished
|
||||||
|
// running, so there's no need to keep a ref around.
|
||||||
|
sp<Thread> deferredSaveThread(new DeferredSaveThread());
|
||||||
|
mSavePending = true;
|
||||||
|
deferredSaveThread->run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +108,13 @@ private:
|
|||||||
// from disk.
|
// from disk.
|
||||||
String8 mFilename;
|
String8 mFilename;
|
||||||
|
|
||||||
|
// mSavePending indicates whether or not a deferred save operation is
|
||||||
|
// pending. Each time a key/value pair is inserted into the cache via
|
||||||
|
// setBlob, a deferred save is initiated if one is not already pending.
|
||||||
|
// This will wait some amount of time and then trigger a save of the cache
|
||||||
|
// contents to disk.
|
||||||
|
bool mSavePending;
|
||||||
|
|
||||||
// mMutex is the mutex used to prevent concurrent access to the member
|
// mMutex is the mutex used to prevent concurrent access to the member
|
||||||
// variables. It must be locked whenever the member variables are accessed.
|
// variables. It must be locked whenever the member variables are accessed.
|
||||||
mutable Mutex mMutex;
|
mutable Mutex mMutex;
|
||||||
|
Loading…
Reference in New Issue
Block a user