Skip to content

WEAK_SCOPED_MUTEX_LOCK/WEAK_MUTEX_TRY_LOCK revisited #11100

@masaori335

Description

@masaori335

WEAK_SCOPED_MUTEX_LOCK and WEAK_MUTEX_TRY_LOCK are introduced to allow the mutex to be a nullptr.

// A weak version of the SCOPED_MUTEX_LOCK macro, allows the mutex to be a nullptr.
#ifdef DEBUG
#define WEAK_SCOPED_MUTEX_LOCK(_l, _m, _t) WeakMutexLock _l(MakeSourceLocation(), (char *)nullptr, _m, _t);
#else // DEBUG
#define WEAK_SCOPED_MUTEX_LOCK(_l, _m, _t) WeakMutexLock _l(_m, _t);
#endif // DEBUG

Typical usage is below.

WEAK_SCOPED_MUTEX_LOCK(lock, m_cont->mutex, this_ethread());
return m_cont->handleEvent(event, edata);

However, if we take a look at the Continuation::handleEvent in this case, it has a release assert of the mutex.

TS_INLINE int
handleEvent(int event = CONTINUATION_EVENT_NONE, void *data = nullptr)
{
// If there is a lock, we must be holding it on entry
ink_release_assert(!mutex || mutex->thread_holding == this_ethread());
return (this->*handler)(event, data);
}

It looks like we don't have reason to use WEAK_ version to allow nullptr in many cases.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions