Chromium Embedded Framework (CEF)  114.2.1+gd70a0a8+chromium-114.0.5735.45
base::ThreadChecker Class Reference

ThreadChecker is a helper class used to help verify that some methods of a class are called from the same thread. More...

#include "include/base/cef_thread_checker.h"

Inheritance diagram for base::ThreadChecker:
base::cef_internal::ThreadCheckerDoNothing

Additional Inherited Members

- Public Member Functions inherited from base::cef_internal::ThreadCheckerDoNothing
bool CalledOnValidThread () const
 
void DetachFromThread ()
 

Detailed Description

ThreadChecker is a helper class used to help verify that some methods of a class are called from the same thread.

It provides identical functionality to base::NonThreadSafe, but it is meant to be held as a member variable, rather than inherited from base::NonThreadSafe.

While inheriting from base::NonThreadSafe may give a clear indication about the thread-safety of a class, it may also lead to violations of the style guide with regard to multiple inheritance. The choice between having a ThreadChecker member and inheriting from base::NonThreadSafe should be based on whether:

  • Derived classes need to know the thread they belong to, as opposed to having that functionality fully encapsulated in the base class.
  • Derived classes should be able to reassign the base class to another thread, via DetachFromThread.

If neither of these are true, then having a ThreadChecker member and calling CalledOnValidThread is the preferable solution.

Example:

  class MyClass {
   public:
    void Foo() {
      DCHECK(thread_checker_.CalledOnValidThread());
      ... (do stuff) ...
    }

   private:
    ThreadChecker thread_checker_;
  }

In Release mode, CalledOnValidThread will always return true.


The documentation for this class was generated from the following file: