mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-23 02:05:42 +00:00
Bug 1280089 - Use js::Mutex/js::LockGuard instead of PRLock/AutoSPSLock for the SPSProfiler; r=terrence
This commit is contained in:
parent
69d0fa99e5
commit
0df4a565cc
@ -30,7 +30,6 @@ SPSProfiler::SPSProfiler(JSRuntime* rt)
|
||||
max_(0),
|
||||
slowAssertions(false),
|
||||
enabled_(false),
|
||||
lock_(nullptr),
|
||||
eventMarker_(nullptr)
|
||||
{
|
||||
MOZ_ASSERT(rt != nullptr);
|
||||
@ -39,10 +38,6 @@ SPSProfiler::SPSProfiler(JSRuntime* rt)
|
||||
bool
|
||||
SPSProfiler::init()
|
||||
{
|
||||
lock_ = PR_NewLock();
|
||||
if (lock_ == nullptr)
|
||||
return false;
|
||||
|
||||
if (!strings.init())
|
||||
return false;
|
||||
|
||||
@ -55,14 +50,12 @@ SPSProfiler::~SPSProfiler()
|
||||
for (ProfileStringMap::Enum e(strings); !e.empty(); e.popFront())
|
||||
js_free(const_cast<char*>(e.front().value()));
|
||||
}
|
||||
if (lock_)
|
||||
PR_DestroyLock(lock_);
|
||||
}
|
||||
|
||||
void
|
||||
SPSProfiler::setProfilingStack(ProfileEntry* stack, uint32_t* size, uint32_t max)
|
||||
{
|
||||
AutoSPSLock lock(lock_);
|
||||
LockGuard<Mutex> lock(lock_);
|
||||
MOZ_ASSERT_IF(size_ && *size_ != 0, !enabled());
|
||||
MOZ_ASSERT(strings.initialized());
|
||||
|
||||
@ -145,7 +138,7 @@ SPSProfiler::enable(bool enabled)
|
||||
const char*
|
||||
SPSProfiler::profileString(JSScript* script, JSFunction* maybeFun)
|
||||
{
|
||||
AutoSPSLock lock(lock_);
|
||||
LockGuard<Mutex> lock(lock_);
|
||||
MOZ_ASSERT(strings.initialized());
|
||||
ProfileStringMap::AddPtr s = strings.lookupForAdd(script);
|
||||
if (s)
|
||||
@ -170,7 +163,7 @@ SPSProfiler::onScriptFinalized(JSScript* script)
|
||||
* off, we still want to remove the string, so no check of enabled() is
|
||||
* done.
|
||||
*/
|
||||
AutoSPSLock lock(lock_);
|
||||
LockGuard<Mutex> lock(lock_);
|
||||
if (!strings.initialized())
|
||||
return;
|
||||
if (ProfileStringMap::Ptr entry = strings.lookup(script)) {
|
||||
|
@ -12,10 +12,11 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "jslock.h"
|
||||
#include "jsscript.h"
|
||||
|
||||
#include "js/ProfilingStack.h"
|
||||
#include "threading/LockGuard.h"
|
||||
#include "threading/Mutex.h"
|
||||
|
||||
/*
|
||||
* SPS Profiler integration with the JS Engine
|
||||
@ -126,7 +127,7 @@ class SPSProfiler
|
||||
uint32_t max_;
|
||||
bool slowAssertions;
|
||||
uint32_t enabled_;
|
||||
PRLock* lock_;
|
||||
js::Mutex lock_;
|
||||
void (*eventMarker_)(const char*);
|
||||
|
||||
const char* allocProfileString(JSScript* script, JSFunction* function);
|
||||
@ -211,25 +212,6 @@ class SPSProfiler
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* This class is used to make sure the strings table
|
||||
* is only accessed on one thread at a time.
|
||||
*/
|
||||
class AutoSPSLock
|
||||
{
|
||||
public:
|
||||
explicit AutoSPSLock(PRLock* lock)
|
||||
{
|
||||
MOZ_ASSERT(lock, "Parameter should not be null!");
|
||||
lock_ = lock;
|
||||
PR_Lock(lock);
|
||||
}
|
||||
~AutoSPSLock() { PR_Unlock(lock_); }
|
||||
|
||||
private:
|
||||
PRLock* lock_;
|
||||
};
|
||||
|
||||
/*
|
||||
* This class is used to suppress profiler sampling during
|
||||
* critical sections where stack state is not valid.
|
||||
@ -251,14 +233,14 @@ class MOZ_RAII AutoSuppressProfilerSampling
|
||||
inline size_t
|
||||
SPSProfiler::stringsCount()
|
||||
{
|
||||
AutoSPSLock lock(lock_);
|
||||
LockGuard<Mutex> lock(lock_);
|
||||
return strings.count();
|
||||
}
|
||||
|
||||
inline void
|
||||
SPSProfiler::stringsReset()
|
||||
{
|
||||
AutoSPSLock lock(lock_);
|
||||
LockGuard<Mutex> lock(lock_);
|
||||
strings.clear();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user