-
Notifications
You must be signed in to change notification settings - Fork 851
Open
Description
WEAK_SCOPED_MUTEX_LOCK and WEAK_MUTEX_TRY_LOCK are introduced to allow the mutex to be a nullptr.
trafficserver/include/iocore/eventsystem/Lock.h
Lines 52 to 57 in 31c1592
| // 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.
trafficserver/src/api/APIHook.cc
Lines 73 to 75 in 31c1592
| 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.
trafficserver/include/iocore/eventsystem/Continuation.h
Lines 223 to 229 in 31c1592
| 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.