Skip to content
Closed
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
27 changes: 2 additions & 25 deletions iocore/eventsystem/I_Continuation.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "tscore/List.h"
#include "I_Lock.h"
#include "tscore/ContFlags.h"
#include "I_ThreadAffinity.h"

class Continuation;
class ContinuationQueue;
Expand Down Expand Up @@ -94,7 +95,7 @@ class force_VFPT_to_top

*/

class Continuation : private force_VFPT_to_top
class Continuation : private force_VFPT_to_top, public ThreadAffinity
{
public:
/**
Expand Down Expand Up @@ -145,30 +146,6 @@ class Continuation : private force_VFPT_to_top
*/
ContFlags control_flags;

EThread *thread_affinity = nullptr;

bool
setThreadAffinity(EThread *ethread)
{
if (ethread != nullptr) {
thread_affinity = ethread;
return true;
}
return false;
}

EThread *
getThreadAffinity()
{
return thread_affinity;
}

void
clearThreadAffinity()
{
thread_affinity = nullptr;
}

/**
Receives the event code and data for an Event.

Expand Down
9 changes: 8 additions & 1 deletion iocore/eventsystem/I_Lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "tscore/ink_platform.h"
#include "tscore/Diags.h"
#include "I_Thread.h"
#include "I_ThreadAffinity.h"

#define MAX_LOCK_TIME HRTIME_MSECONDS(200)
#define THREAD_MUTEX_THREAD_HOLDING (-1024 * 1024)
Expand Down Expand Up @@ -143,7 +144,7 @@ inkcoreapi extern void lock_taken(const SourceLocation &, const char *handler);
allow you to lock/unlock the underlying mutex object.

*/
class ProxyMutex : public RefCountObj
class ProxyMutex : public RefCountObj, public ThreadAffinity
{
public:
/**
Expand Down Expand Up @@ -247,6 +248,9 @@ Mutex_trylock(
ink_assert(t != nullptr);
ink_assert(t == reinterpret_cast<EThread *>(this_thread()));
if (m->thread_holding != t) {
if (m->getThreadAffinity() != nullptr) {
ink_release_assert(t == m->getThreadAffinity());
}
if (!ink_mutex_try_acquire(&m->the_mutex)) {
#ifdef DEBUG
lock_waiting(m->srcloc, m->handler);
Expand Down Expand Up @@ -290,6 +294,9 @@ Mutex_lock(
{
ink_assert(t != nullptr);
if (m->thread_holding != t) {
if (m->getThreadAffinity() != nullptr) {
ink_release_assert(t == m->getThreadAffinity());
}
ink_mutex_acquire(&m->the_mutex);
m->thread_holding = t;
ink_assert(m->thread_holding);
Expand Down
54 changes: 54 additions & 0 deletions iocore/eventsystem/I_ThreadAffinity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/** @file

A brief file description

@section license License

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

#pragma once

class ThreadAffinity
{
public:
bool
setThreadAffinity(EThread *ethread)
{
if (ethread != nullptr) {
_thread_affinity = ethread;
return true;
}
return false;
}

EThread *
getThreadAffinity() const
{
return _thread_affinity;
}

void
clearThreadAffinity()
{
_thread_affinity = nullptr;
}

private:
EThread *_thread_affinity = nullptr;
};
1 change: 1 addition & 0 deletions iocore/net/UnixNet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ initialize_thread_for_net(EThread *thread)
new (reinterpret_cast<ink_dummy_for_new *>(get_PollCont(thread))) PollCont(thread->mutex, nh);
nh->mutex = new_ProxyMutex();
nh->thread = thread;
nh->mutex->setThreadAffinity(thread);

PollCont *pc = get_PollCont(thread);
PollDescriptor *pd = pc->pollDescriptor;
Expand Down