diff options
Diffstat (limited to 'ppapi/shared_impl/var_tracker.cc')
-rw-r--r-- | ppapi/shared_impl/var_tracker.cc | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/ppapi/shared_impl/var_tracker.cc b/ppapi/shared_impl/var_tracker.cc index 6bc0261..5e33a23 100644 --- a/ppapi/shared_impl/var_tracker.cc +++ b/ppapi/shared_impl/var_tracker.cc @@ -27,22 +27,27 @@ VarTracker::VarInfo::VarInfo(Var* v, int input_ref_count) track_with_no_reference_count(0) { } -VarTracker::VarTracker() : last_var_id_(0) { +VarTracker::VarTracker(ThreadMode thread_mode) : last_var_id_(0) { + if (thread_mode == SINGLE_THREADED) + thread_checker_.reset(new base::ThreadChecker); } VarTracker::~VarTracker() { } -int32 VarTracker::AddVar(Var* var) { - DCHECK(CalledOnValidThread()); +void VarTracker::CheckThreadingPreconditions() const { + DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); ProxyLock::AssertAcquired(); +} + +int32 VarTracker::AddVar(Var* var) { + CheckThreadingPreconditions(); return AddVarInternal(var, ADD_VAR_TAKE_ONE_REFERENCE); } Var* VarTracker::GetVar(int32 var_id) const { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); VarMap::const_iterator result = live_vars_.find(var_id); if (result == live_vars_.end()) @@ -51,8 +56,7 @@ Var* VarTracker::GetVar(int32 var_id) const { } Var* VarTracker::GetVar(const PP_Var& var) const { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); if (!IsVarTypeRefcounted(var.type)) return NULL; @@ -60,8 +64,7 @@ Var* VarTracker::GetVar(const PP_Var& var) const { } bool VarTracker::AddRefVar(int32 var_id) { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); DLOG_IF(ERROR, !CheckIdType(var_id, PP_ID_TYPE_VAR)) << var_id << " is not a PP_Var ID."; @@ -86,8 +89,7 @@ bool VarTracker::AddRefVar(int32 var_id) { } bool VarTracker::AddRefVar(const PP_Var& var) { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); if (!IsVarTypeRefcounted(var.type)) return false; @@ -95,8 +97,7 @@ bool VarTracker::AddRefVar(const PP_Var& var) { } bool VarTracker::ReleaseVar(int32 var_id) { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); DLOG_IF(ERROR, !CheckIdType(var_id, PP_ID_TYPE_VAR)) << var_id << " is not a PP_Var ID."; @@ -127,8 +128,7 @@ bool VarTracker::ReleaseVar(int32 var_id) { } bool VarTracker::ReleaseVar(const PP_Var& var) { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); if (!IsVarTypeRefcounted(var.type)) return false; @@ -152,8 +152,7 @@ VarTracker::VarMap::iterator VarTracker::GetLiveVar(int32 id) { } int VarTracker::GetRefCountForObject(const PP_Var& plugin_object) { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); VarMap::iterator found = GetLiveVar(plugin_object); if (found == live_vars_.end()) @@ -163,8 +162,7 @@ int VarTracker::GetRefCountForObject(const PP_Var& plugin_object) { int VarTracker::GetTrackedWithNoReferenceCountForObject( const PP_Var& plugin_object) { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); VarMap::iterator found = GetLiveVar(plugin_object); if (found == live_vars_.end()) @@ -186,8 +184,7 @@ bool VarTracker::IsVarTypeRefcounted(PP_VarType type) const { } PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes) { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); scoped_refptr<ArrayBufferVar> array_buffer(CreateArrayBuffer(size_in_bytes)); if (!array_buffer) @@ -197,8 +194,7 @@ PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes) { PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes, const void* data) { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); ArrayBufferVar* array_buffer = MakeArrayBufferVar(size_in_bytes, data); return array_buffer ? array_buffer->GetPPVar() : PP_MakeNull(); @@ -206,8 +202,7 @@ PP_Var VarTracker::MakeArrayBufferPPVar(uint32 size_in_bytes, ArrayBufferVar* VarTracker::MakeArrayBufferVar(uint32 size_in_bytes, const void* data) { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); ArrayBufferVar* array_buffer(CreateArrayBuffer(size_in_bytes)); if (!array_buffer) @@ -217,8 +212,7 @@ ArrayBufferVar* VarTracker::MakeArrayBufferVar(uint32 size_in_bytes, } std::vector<PP_Var> VarTracker::GetLiveVars() { - DCHECK(CalledOnValidThread()); - ProxyLock::AssertAcquired(); + CheckThreadingPreconditions(); std::vector<PP_Var> var_vector; var_vector.reserve(live_vars_.size()); |