Skip to content
Snippets Groups Projects
Commit 1c16998a authored by Florian Schmaus's avatar Florian Schmaus
Browse files

[LawsScheduler] Guard Runtime::getWorkerId() with CallerEnvironment

Calling Runtime::getWorkerId() is only possible from within the
runtime, hence guard the call with CallerEnvironment.
parent 520f8f1b
No related branches found
No related tags found
1 merge request!192[LawsScheduler] Guard Runtime::getWorkerId() with CallerEnvironment
......@@ -22,6 +22,7 @@ LawsScheduler::LawsScheduler(Runtime& runtime) : AbstractWorkStealingScheduler(r
addNewWorkerHook(newWorkerHook);
}
template <CallerEnvironment callerEnvironment>
void LawsScheduler::tryScheduleToPriorityQueue(Fiber& fiber) {
workeraffinity_t* const affinity_buffer = getAffinityBuffer(fiber);
if (!affinity_buffer) {
......@@ -29,9 +30,12 @@ void LawsScheduler::tryScheduleToPriorityQueue(Fiber& fiber) {
}
workeraffinity_t affinity = *affinity_buffer;
workerid_t workerId = Runtime::getWorkerId();
if (affinity == workerId) {
return;
if constexpr (callerEnvironment == CallerEnvironment::EMPER) {
workerid_t workerId = Runtime::getWorkerId();
if (affinity == workerId) {
return;
}
}
if (affinity == Fiber::NOT_AFFINE) {
......@@ -46,12 +50,12 @@ void LawsScheduler::tryScheduleToPriorityQueue(Fiber& fiber) {
}
void LawsScheduler::scheduleInternal(Fiber& fiber) {
tryScheduleToPriorityQueue(fiber);
tryScheduleToPriorityQueue<CallerEnvironment::EMPER>(fiber);
scheduleViaWorkStealing(fiber);
}
void LawsScheduler::scheduleFromAnywhereInternal(Fiber& fiber) {
tryScheduleToPriorityQueue(fiber);
tryScheduleToPriorityQueue<CallerEnvironment::ANYWHERE>(fiber);
enqueueInAnywhereQueue(fiber);
onNewWork<CallerEnvironment::ANYWHERE>();
}
......@@ -59,7 +63,7 @@ void LawsScheduler::scheduleFromAnywhereInternal(Fiber& fiber) {
void LawsScheduler::scheduleFromAnywhereInternal(Fiber** fibers, unsigned count) {
for (unsigned i = 0; i < count; ++i) {
Fiber& fiber = *fibers[i];
tryScheduleToPriorityQueue(fiber);
tryScheduleToPriorityQueue<CallerEnvironment::ANYWHERE>(fiber);
}
insertInAnywhereQueue(fibers, count);
onNewWork<CallerEnvironment::ANYWHERE>();
......
......@@ -2,6 +2,7 @@
// Copyright © 2020-2021 Florian Schmaus
#pragma once
#include "CallerEnvironment.hpp"
#include "Fiber.hpp"
#include "lib/adt/MpscQueue.hpp"
#include "strategies/AbstractWorkStealingScheduler.hpp"
......@@ -17,6 +18,7 @@ class LawsScheduler : public AbstractWorkStealingScheduler {
static thread_local LawsMpscQueue priorityQueue;
template <CallerEnvironment callerEnvironment>
void tryScheduleToPriorityQueue(Fiber& fiber);
protected:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment