bug 586859: Turn off threading in case it added a random cycle collector crash a=backout

This commit is contained in:
Taras Glek
2011-01-07 12:39:19 -08:00
parent 5f05607467
commit 4b7fcd0941

View File

@@ -62,7 +62,6 @@
#include "nsIZipReader.h"
#include "nsWeakReference.h"
#include "nsZipArchive.h"
#include "mozilla/FunctionTimer.h"
#include "mozilla/Omnijar.h"
#include "prenv.h"
@@ -117,7 +116,7 @@ StartupCache* StartupCache::gStartupCache;
PRBool StartupCache::gShutdownInitiated;
StartupCache::StartupCache()
: mArchive(NULL), mStartupWriteInitiated(PR_FALSE), mWriteThread(NULL) {}
: mArchive(NULL), mStartupWriteInitiated(PR_FALSE) { }
StartupCache::~StartupCache()
{
@@ -204,7 +203,6 @@ StartupCache::Init()
nsresult
StartupCache::LoadArchive()
{
WaitOnWriteThread();
PRBool exists;
mArchive = NULL;
nsresult rv = mFile->Exists(&exists);
@@ -220,7 +218,6 @@ StartupCache::LoadArchive()
nsresult
StartupCache::GetBuffer(const char* id, char** outbuf, PRUint32* length)
{
WaitOnWriteThread();
if (!mStartupWriteInitiated) {
CacheEntry* entry;
nsDependentCString idStr(id);
@@ -258,7 +255,6 @@ StartupCache::GetBuffer(const char* id, char** outbuf, PRUint32* length)
nsresult
StartupCache::PutBuffer(const char* id, const char* inbuf, PRUint32 len)
{
WaitOnWriteThread();
if (StartupCache::gShutdownInitiated) {
return NS_ERROR_NOT_AVAILABLE;
}
@@ -310,7 +306,7 @@ CacheCloseHelper(const nsACString& key, nsAutoPtr<CacheEntry>& data,
NS_ASSERTION(NS_SUCCEEDED(rv) && hasEntry == PR_FALSE,
"Existing entry in disk StartupCache.");
#endif
rv = writer->AddEntryStream(key, holder->time, PR_TRUE, stream, false);
rv = writer->AddEntryStream(key, holder->time, PR_FALSE, stream, false);
if (NS_FAILED(rv)) {
NS_WARNING("cache entry deleted but not written to disk.");
@@ -321,7 +317,6 @@ CacheCloseHelper(const nsACString& key, nsAutoPtr<CacheEntry>& data,
void
StartupCache::WriteToDisk()
{
WaitOnWriteThread();
nsresult rv;
mStartupWriteInitiated = PR_TRUE;
@@ -355,7 +350,7 @@ StartupCache::WriteToDisk()
// Close the archive so Windows doesn't choke.
mArchive = NULL;
zipW->Close();
// our reader's view of the archive is outdated now, reload it.
LoadArchive();
@@ -365,53 +360,17 @@ StartupCache::WriteToDisk()
void
StartupCache::InvalidateCache()
{
WaitOnWriteThread();
mTable.Clear();
mArchive = NULL;
mFile->Remove(false);
LoadArchive();
}
/*
* WaitOnWriteThread() is called from a main thread to wait for the worker
* thread to finish. However since the same code is used in the worker thread and
* main thread, the worker thread can also call WaitOnWriteThread() which is a no-op.
*/
void
StartupCache::WaitOnWriteThread()
{
PRThread* writeThread = mWriteThread;
if (!writeThread || writeThread == PR_GetCurrentThread())
return;
NS_TIME_FUNCTION_MIN(30);
//stick a functiontimer thing here
//NS_WARNING("Waiting on startupcache write");
PR_JoinThread(writeThread);
mWriteThread = NULL;
}
void
StartupCache::ThreadedWrite(void *aClosure)
{
gStartupCache->WriteToDisk();
}
/*
* The write-thread is spawned on a timeout(which is reset with every write). This
* can avoid a slow shutdown. After writing out the cache, the zipreader is
* reloaded on the worker thread.
*/
void
StartupCache::WriteTimeout(nsITimer *aTimer, void *aClosure)
{
gStartupCache->mWriteThread = PR_CreateThread(PR_USER_THREAD,
StartupCache::ThreadedWrite,
NULL,
PR_PRIORITY_NORMAL,
PR_LOCAL_THREAD,
PR_JOINABLE_THREAD,
0);
StartupCache* sc = (StartupCache*) aClosure;
sc->WriteToDisk();
}
// We don't want to refcount StartupCache, so we'll just
@@ -621,7 +580,6 @@ StartupCacheWrapper::StartupWriteComplete(PRBool *complete)
if (!sc) {
return NS_ERROR_NOT_INITIALIZED;
}
sc->WaitOnWriteThread();
*complete = sc->mStartupWriteInitiated && sc->mTable.Count() == 0;
return NS_OK;
}