Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions iocore/eventsystem/I_Lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Mutex_trylock(
#ifdef DEBUG
const SourceLocation &location, const char *ahandler,
#endif
Ptr<ProxyMutex> &m, EThread *t)
ProxyMutex *m, EThread *t)
{
ink_assert(t != nullptr);
ink_assert(t == reinterpret_cast<EThread *>(this_thread()));
Expand Down Expand Up @@ -295,12 +295,26 @@ Mutex_trylock(
return true;
}

inline bool
Mutex_trylock(
#ifdef DEBUG
const SourceLocation &location, const char *ahandler,
#endif
Ptr<ProxyMutex> &m, EThread *t)
{
return Mutex_trylock(
#ifdef DEBUG
location, ahandler,
#endif
m.get(), t);
}

inline int
Mutex_lock(
#ifdef DEBUG
const SourceLocation &location, const char *ahandler,
#endif
Ptr<ProxyMutex> &m, EThread *t)
ProxyMutex *m, EThread *t)
{
ink_assert(t != nullptr);
if (m->thread_holding != t) {
Expand All @@ -327,8 +341,22 @@ Mutex_lock(
return true;
}

inline int
Mutex_lock(
#ifdef DEBUG
const SourceLocation &location, const char *ahandler,
#endif
Ptr<ProxyMutex> &m, EThread *t)
{
return Mutex_lock(
#ifdef DEBUG
location, ahandler,
#endif
m.get(), t);
}

inline void
Mutex_unlock(Ptr<ProxyMutex> &m, EThread *t)
Mutex_unlock(ProxyMutex *m, EThread *t)
{
if (m->nthread_holding) {
ink_assert(t == m->thread_holding);
Expand All @@ -351,6 +379,12 @@ Mutex_unlock(Ptr<ProxyMutex> &m, EThread *t)
}
}

inline void
Mutex_unlock(Ptr<ProxyMutex> &m, EThread *t)
{
Mutex_unlock(m.get(), t);
}

class WeakMutexLock
{
private:
Expand Down
19 changes: 11 additions & 8 deletions src/traffic_server/InkIOCoreAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,17 @@ TSEventThreadSelf(void)

////////////////////////////////////////////////////////////////////
//
// Mutexes
// Mutexes: For TSMutexCreate and TSMutexDestroy, the refcount of the
// ProxyMutex object is not incremented or decremented. If the resulting
// ProxyMutex is passed to a INKContInternal, it's mutex smart pointer
// will take ownership of the ProxyMutex and delete it when the last
// reference is removed. TSMutexDestroy should not be called in that case.
//
////////////////////////////////////////////////////////////////////
TSMutex
TSMutexCreate()
{
ProxyMutex *mutexp = new_ProxyMutex();
mutexp->refcount_inc();

// TODO: Remove this when allocations can never fail.
sdk_assert(sdk_sanity_check_mutex((TSMutex)mutexp) == TS_SUCCESS);
Expand All @@ -255,9 +258,9 @@ TSMutexDestroy(TSMutex m)
{
sdk_assert(sdk_sanity_check_mutex(m) == TS_SUCCESS);
ProxyMutex *mutexp = reinterpret_cast<ProxyMutex *>(m);
// Decrement the refcount added in TSMutexCreate. Delete if this
// was the last ref count
if (mutexp && mutexp->refcount_dec() == 0) {

if (mutexp) {
ink_release_assert(mutexp->refcount() == 0);
mutexp->free();
}
}
Expand Down Expand Up @@ -296,23 +299,23 @@ void
TSMutexLock(TSMutex mutexp)
{
sdk_assert(sdk_sanity_check_mutex(mutexp) == TS_SUCCESS);
Ptr<ProxyMutex> proxy_mutex(reinterpret_cast<ProxyMutex *>(mutexp));
ProxyMutex *proxy_mutex = reinterpret_cast<ProxyMutex *>(mutexp);
MUTEX_TAKE_LOCK(proxy_mutex, this_ethread());
}

TSReturnCode
TSMutexLockTry(TSMutex mutexp)
{
sdk_assert(sdk_sanity_check_mutex(mutexp) == TS_SUCCESS);
Ptr<ProxyMutex> proxy_mutex(reinterpret_cast<ProxyMutex *>(mutexp));
ProxyMutex *proxy_mutex = reinterpret_cast<ProxyMutex *>(mutexp);
return (MUTEX_TAKE_TRY_LOCK(proxy_mutex, this_ethread()) ? TS_SUCCESS : TS_ERROR);
}

void
TSMutexUnlock(TSMutex mutexp)
{
sdk_assert(sdk_sanity_check_mutex(mutexp) == TS_SUCCESS);
Ptr<ProxyMutex> proxy_mutex(reinterpret_cast<ProxyMutex *>(mutexp));
ProxyMutex *proxy_mutex(reinterpret_cast<ProxyMutex *>(mutexp));
MUTEX_UNTAKE_LOCK(proxy_mutex, this_ethread());
}

Expand Down