From 2efdee5cb8ad495d8f27157558e96233c9a69e3d Mon Sep 17 00:00:00 2001 From: TuxSH Date: Mon, 19 Nov 2018 12:17:06 +0100 Subject: [PATCH] meso: KProcess: add ForEachThread --- .../include/mesosphere/processes/KProcess.hpp | 15 +++++++++++++++ .../include/mesosphere/threading/KThread.hpp | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/mesosphere/include/mesosphere/processes/KProcess.hpp b/mesosphere/include/mesosphere/processes/KProcess.hpp index eaa1ce9fc..bb576095b 100644 --- a/mesosphere/include/mesosphere/processes/KProcess.hpp +++ b/mesosphere/include/mesosphere/processes/KProcess.hpp @@ -46,7 +46,20 @@ class KProcess final : public KSynchronizationObject /* FIXME */ { void SetDebug(KDebug *debug); void ClearDebug(State attachState); + template + void ForEachThread(F f, Args &&...args) + { + std::scoped_lock s{mutex}; + std::scoped_lock s2{threadingMutex}; + + for (KThread &t : threadList) { + f(t, std::forward(args)...); + } + } + private: + KThread::ProcessList threadList{}; + KThread *lastThreads[MAX_CORES]{nullptr}; ulong lastIdleSelectionCount[MAX_CORES]{0}; long schedulerOperationCount = -1; @@ -57,6 +70,8 @@ class KProcess final : public KSynchronizationObject /* FIXME */ { KDebug *debug = nullptr; SharedPtr reslimit{}; KHandleTable handleTable{}; + + mutable KMutex mutex{}, threadingMutex{}; }; MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(Process); diff --git a/mesosphere/include/mesosphere/threading/KThread.hpp b/mesosphere/include/mesosphere/threading/KThread.hpp index dd9cee705..50545564c 100644 --- a/mesosphere/include/mesosphere/threading/KThread.hpp +++ b/mesosphere/include/mesosphere/threading/KThread.hpp @@ -17,8 +17,10 @@ struct LightSessionRequest; struct KThreadContext; +struct ThreadProcessListTag; struct ThreadWaitListTag; struct ThreadMutexWaitListTag; +using ThreadProcessListBaseHook = boost::intrusive::list_base_hook >; using ThreadWaitListBaseHook = boost::intrusive::list_base_hook >; using ThreadMutexWaitListBaseHook = boost::intrusive::list_base_hook >; @@ -27,6 +29,7 @@ class KThread final : public ILimitedResource, public ISetAllocated, public IAlarmable, + public ThreadProcessListBaseHook, public ThreadWaitListBaseHook, public ThreadMutexWaitListBaseHook { @@ -106,6 +109,12 @@ class KThread final : KernelLoading = 4, }; + + using ProcessList = typename boost::intrusive::make_list< + KThread, + boost::intrusive::base_hook + >::type; + using SchedulerList = typename boost::intrusive::make_list< KThread, boost::intrusive::value_traits