mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Create 2272 release branch for CEF3.
git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/2272@1993 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
53
libcef_dll/base/cef_ref_counted.cc
Normal file
53
libcef_dll/base/cef_ref_counted.cc
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "include/base/cef_ref_counted.h"
|
||||
#include "include/base/cef_thread_collision_warner.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
namespace subtle {
|
||||
|
||||
bool RefCountedThreadSafeBase::HasOneRef() const {
|
||||
return AtomicRefCountIsOne(
|
||||
&const_cast<RefCountedThreadSafeBase*>(this)->ref_count_);
|
||||
}
|
||||
|
||||
RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) {
|
||||
#ifndef NDEBUG
|
||||
in_dtor_ = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
RefCountedThreadSafeBase::~RefCountedThreadSafeBase() {
|
||||
#ifndef NDEBUG
|
||||
DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without "
|
||||
"calling Release()";
|
||||
#endif
|
||||
}
|
||||
|
||||
void RefCountedThreadSafeBase::AddRef() const {
|
||||
#ifndef NDEBUG
|
||||
DCHECK(!in_dtor_);
|
||||
#endif
|
||||
AtomicRefCountInc(&ref_count_);
|
||||
}
|
||||
|
||||
bool RefCountedThreadSafeBase::Release() const {
|
||||
#ifndef NDEBUG
|
||||
DCHECK(!in_dtor_);
|
||||
DCHECK(!AtomicRefCountIsZero(&ref_count_));
|
||||
#endif
|
||||
if (!AtomicRefCountDec(&ref_count_)) {
|
||||
#ifndef NDEBUG
|
||||
in_dtor_ = true;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace subtle
|
||||
|
||||
} // namespace base
|
Reference in New Issue
Block a user