[webkit-reviews] review requested: [Bug 31639] Add asserts to RefCounted to make sure ref/deref happens on the right thread. : [Attachment 44201] Proposed patch.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Dec 2 18:49:44 PST 2009

Dmitry Titov <dimich at chromium.org> has asked  for review:
Bug 31639: Add asserts to RefCounted to make sure ref/deref happens on the
right thread.

Attachment 44201: Proposed patch.

------- Additional Comments from Dmitry Titov <dimich at chromium.org>
Adds ASSERT to RefCountedBase to verify the ref()/deref() and hasOneref(),
refCount() happen on the same thread.

For objects that are intentionally used in cross-process scenario, there is
disableThreadVerification() which excludes them from the checks. I used this to
exclude Stringimpl and classes used in IconDatabase.

Also, the checks only are activated when refcount becomes >= 2 and deactivated
when refcount goes below 2 (borrowed the idea from CrossThreadRefCounted). This
prevents the assertions in a very typical scenario when object is created on
one thread and then passed via PassRefPtr to another thread where it is used
exclusively and then destroyed. It seems it's mostly ok to transfer an object
with refcount 1 between threads - so the asserts are only activated when
refcount is >1, meaning the object is actually 'shared'.

Perf impact on Debug build is about 2% on run-webkit-tests, and there are no
asserts fired during the run.

More information about the webkit-reviews mailing list