template <typename LockType>

class Lock

Defined at line 173 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

Base lock wrapper type that provides the essential interface required by

Guard

<LockType

, Option> to perform locking and validation. This type wraps

an instance of LockType that is used to perform the actual synchronization.

When lock validation is enabled this type also stores the LockClassId for

the lock class this lock belongs to.

The "lock class" that each lock belongs to is created by each unique

instantiation of the types LockDep

<Class

, LockType, Index> or

SingletonLockDep

<Class

, LockType, LockFlags> below. These types subclass

Lock

<LockType

> to provide type erasure required when virtual accessors are

used to specify capabilities to Clang static lock analysis.

For example, the lock_ members of LockableType and AnotherLockableType below

are different types due to how LockDep

<

> instruments the lock members.

Both unique LockDep

<

> instantiations derive from the same Lock

<LockType

>,

providing a common capability type (erasing the LockDep

<

> type) that may be

used in static lock annotations with the expression "get_lock()".

struct LockableInterface {

virtual ~LockableInterface = 0;

virtual Lock

<fbl

::Mutex>* get_lock() = 0;

virtual void Clear() __TA_REQUIRES(get_lock()) = 0;

};

class LockableType : public LockableInterface {

public:

LockableType() = default;

~LockableType() override = default;

Lock

<fbl

::Mutex>* get_lock() override { return

&lock

_; }

void Clear() override { count_ = 0; }

void Increment() {

Guard

<fbl

::Mutex> guard{get_lock()};

count_++;

}

private:

LOCK_DEP_INSTRUMENT(LockableType, fbl::Mutex) lock_;

int count_ __TA_GUARDED(get_lock()) {0};

};

class AnotherLockableType : public LockableInterface {

public:

AnotherLockableType() = default;

~AnotherLockableType() override = default;

Lock

<fbl

::Mutex>* get_lock() override { return

&lock

_; }

void Clear() override { test_.clear(); }

void Append(const std::string

&

string) {

Guard

<fbl

::Mutex> guard{get_lock()};

text_.append(string)

}

private:

LOCK_DEP_INSTRUMENT(AnotherLockableType, fbl::Mutex) lock_;

std::string text_ __TA_GUARDED(get_lock()) {};

};

Public Methods

void Lock<LockType> (Lock<LockType> && )

Defined at line 175 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

void Lock<LockType> (const Lock<LockType> & )

Defined at line 176 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

Lock<LockType> & operator= (Lock<LockType> && )

Defined at line 177 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

Lock<LockType> & operator= (const Lock<LockType> & )

Defined at line 178 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

void ~Lock<LockType> ()

Defined at line 180 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

LockType & lock ()

Provides direct access to the underlying lock. Care should be taken when

manipulating the underlying lock. Incorrect manipulation could confuse

the validator, trigger lock assertions, and/or deadlock.

Defined at line 185 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

const LockType & lock ()

Defined at line 186 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

LockType & capability ()

Returns the capability of the underlying lock. This is expected by Guard

as an additional static assertion target.

Defined at line 190 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

const LockType & capability ()

Defined at line 191 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

LockClassId id ()

Returns the LockClassId of the lock class this lock belongs to.

Defined at line 194 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

Protected Methods

template <typename... Args>
void Lock<LockType> (LockClassId id, Args &&... args)

Initializes the Lock instance with the given LockClassId and passes any

additional arguments to the underlying lock constructor.

Defined at line 200 of file ../../zircon/system/ulib/lockdep/include/lockdep/lock_class.h

Friends

template <size_t, typename, typename>
class GuardMultiple
template <typenametypenametypename>
class Guard