-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 867762: NSPR and SQLite Main Thread I/O Interposing. r=BenWa
UltraBlame original commit: 1a0ff6b97e035ddc3be189a8db8a0a75493177c1
- Loading branch information
Showing
12 changed files
with
806 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
|
||
|
||
|
||
|
||
#include "IOInterposer.h" | ||
#include "NSPRInterposer.h" | ||
#include "SQLiteInterposer.h" | ||
|
||
using namespace mozilla; | ||
|
||
static StaticAutoPtr<IOInterposer> sSingleton; | ||
|
||
IOInterposer* | ||
IOInterposer::GetInstance() | ||
{ | ||
if (!sSingleton) { | ||
|
||
|
||
|
||
sSingleton = new IOInterposer(); | ||
sSingleton->Init(); | ||
} | ||
|
||
return sSingleton.get(); | ||
} | ||
|
||
void | ||
IOInterposer::ClearInstance() | ||
{ | ||
|
||
|
||
|
||
sSingleton = nullptr; | ||
} | ||
|
||
IOInterposer::IOInterposer() | ||
:mMutex("IOInterposer::mMutex") | ||
{ | ||
|
||
|
||
|
||
} | ||
|
||
IOInterposer::~IOInterposer() | ||
{ | ||
|
||
|
||
|
||
Enable(false); | ||
NSPRInterposer::ClearInstance(); | ||
SQLiteInterposer::ClearInstance(); | ||
} | ||
|
||
bool | ||
IOInterposer::Init() | ||
{ | ||
|
||
|
||
|
||
mozilla::MutexAutoLock lock(mMutex); | ||
IOInterposerModule* nsprModule = NSPRInterposer::GetInstance(this, | ||
IOInterposeObserver::OpAll); | ||
if (!nsprModule) { | ||
return false; | ||
} | ||
|
||
IOInterposerModule* sqlModule = SQLiteInterposer::GetInstance(this, | ||
IOInterposeObserver::OpAll); | ||
if (!sqlModule) { | ||
return false; | ||
} | ||
|
||
mModules.AppendElement(nsprModule); | ||
mModules.AppendElement(sqlModule); | ||
return true; | ||
} | ||
|
||
void | ||
IOInterposer::Enable(bool aEnable) | ||
{ | ||
mozilla::MutexAutoLock lock(mMutex); | ||
for (PRUint32 i = 0; i < mModules.Length(); ++i ) { | ||
mModules[i]->Enable(aEnable); | ||
} | ||
} | ||
|
||
void | ||
IOInterposer::Register(IOInterposeObserver::Operation aOp, | ||
IOInterposeObserver* aObserver) | ||
{ | ||
|
||
|
||
|
||
if (aOp & IOInterposeObserver::OpRead) { | ||
mReadObservers.AppendElement(aObserver); | ||
} | ||
if (aOp & IOInterposeObserver::OpWrite) { | ||
mWriteObservers.AppendElement(aObserver); | ||
} | ||
if (aOp & IOInterposeObserver::OpFSync) { | ||
mFSyncObservers.AppendElement(aObserver); | ||
} | ||
} | ||
|
||
void | ||
IOInterposer::Deregister(IOInterposeObserver::Operation aOp, | ||
IOInterposeObserver* aObserver) | ||
{ | ||
|
||
|
||
|
||
if (aOp & IOInterposeObserver::OpRead) { | ||
mReadObservers.RemoveElement(aObserver); | ||
} | ||
if (aOp & IOInterposeObserver::OpWrite) { | ||
mWriteObservers.RemoveElement(aObserver); | ||
} | ||
if (aOp & IOInterposeObserver::OpFSync) { | ||
mFSyncObservers.RemoveElement(aObserver); | ||
} | ||
} | ||
|
||
void | ||
IOInterposer::Observe(IOInterposeObserver::Operation aOp, double& aDuration, | ||
const char* aModuleInfo) | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
switch (aOp) { | ||
case IOInterposeObserver::OpRead: | ||
{ | ||
for (PRUint32 i = 0; i < mReadObservers.Length(); ++i) { | ||
mReadObservers[i]->Observe(aOp, aDuration, aModuleInfo); | ||
} | ||
} | ||
break; | ||
case IOInterposeObserver::OpWrite: | ||
{ | ||
for (PRUint32 i = 0; i < mWriteObservers.Length(); ++i) { | ||
mWriteObservers[i]->Observe(aOp, aDuration, aModuleInfo); | ||
} | ||
} | ||
break; | ||
case IOInterposeObserver::OpFSync: | ||
{ | ||
for (PRUint32 i = 0; i < mFSyncObservers.Length(); ++i) { | ||
mFSyncObservers[i]->Observe(aOp, aDuration, aModuleInfo); | ||
} | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
|
||
|
||
|
||
|
||
#ifndef IOINTERPOSER_H_ | ||
#define IOINTERPOSER_H_ | ||
|
||
#include "mozilla/Attributes.h" | ||
#include "mozilla/Mutex.h" | ||
#include "mozilla/StaticPtr.h" | ||
#include "mozilla/XPCOM.h" | ||
|
||
namespace mozilla { | ||
|
||
|
||
|
||
|
||
|
||
|
||
class IOInterposeObserver | ||
{ | ||
public: | ||
enum Operation | ||
{ | ||
OpNone = 0, | ||
OpRead = (1 << 0), | ||
OpWrite = (1 << 1), | ||
OpFSync = (1 << 2), | ||
OpWriteFSync = (OpWrite | OpFSync), | ||
OpAll = (OpRead | OpWrite | OpFSync) | ||
}; | ||
virtual void Observe(Operation aOp, double& aDuration, | ||
const char* aModuleInfo) = 0; | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
class IOInterposerModule | ||
{ | ||
public: | ||
virtual ~IOInterposerModule() {} | ||
virtual void Enable(bool aEnable) = 0; | ||
|
||
protected: | ||
IOInterposerModule() {} | ||
|
||
private: | ||
IOInterposerModule(const IOInterposerModule&); | ||
IOInterposerModule& operator=(const IOInterposerModule&); | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
class IOInterposer MOZ_FINAL : public IOInterposeObserver | ||
{ | ||
public: | ||
~IOInterposer(); | ||
|
||
|
||
|
||
|
||
|
||
|
||
void Enable(bool aEnable); | ||
|
||
void Register(IOInterposeObserver::Operation aOp, | ||
IOInterposeObserver* aObserver); | ||
void Deregister(IOInterposeObserver::Operation aOp, | ||
IOInterposeObserver* aObserver); | ||
void Observe(IOInterposeObserver::Operation aOp, double& aDuration, | ||
const char* aModuleInfo); | ||
|
||
static IOInterposer* GetInstance(); | ||
|
||
|
||
|
||
|
||
|
||
|
||
static void ClearInstance(); | ||
|
||
private: | ||
IOInterposer(); | ||
bool Init(); | ||
IOInterposer(const IOInterposer&); | ||
IOInterposer& operator=(const IOInterposer&); | ||
|
||
|
||
|
||
mozilla::Mutex mMutex; | ||
nsTArray<IOInterposerModule*> mModules; | ||
nsTArray<IOInterposeObserver*> mReadObservers; | ||
nsTArray<IOInterposeObserver*> mWriteObservers; | ||
nsTArray<IOInterposeObserver*> mFSyncObservers; | ||
}; | ||
|
||
} | ||
|
||
#endif | ||
|
Oops, something went wrong.