mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
meso: KProcess: add ForEachThread
This commit is contained in:
parent
240f455bc0
commit
2efdee5cb8
2 changed files with 24 additions and 0 deletions
|
@ -46,7 +46,20 @@ class KProcess final : public KSynchronizationObject /* FIXME */ {
|
||||||
void SetDebug(KDebug *debug);
|
void SetDebug(KDebug *debug);
|
||||||
void ClearDebug(State attachState);
|
void ClearDebug(State attachState);
|
||||||
|
|
||||||
|
template<typename F, typename ...Args>
|
||||||
|
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:
|
private:
|
||||||
|
KThread::ProcessList threadList{};
|
||||||
|
|
||||||
KThread *lastThreads[MAX_CORES]{nullptr};
|
KThread *lastThreads[MAX_CORES]{nullptr};
|
||||||
ulong lastIdleSelectionCount[MAX_CORES]{0};
|
ulong lastIdleSelectionCount[MAX_CORES]{0};
|
||||||
long schedulerOperationCount = -1;
|
long schedulerOperationCount = -1;
|
||||||
|
@ -57,6 +70,8 @@ class KProcess final : public KSynchronizationObject /* FIXME */ {
|
||||||
KDebug *debug = nullptr;
|
KDebug *debug = nullptr;
|
||||||
SharedPtr<KResourceLimit> reslimit{};
|
SharedPtr<KResourceLimit> reslimit{};
|
||||||
KHandleTable handleTable{};
|
KHandleTable handleTable{};
|
||||||
|
|
||||||
|
mutable KMutex mutex{}, threadingMutex{};
|
||||||
};
|
};
|
||||||
|
|
||||||
MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(Process);
|
MESOSPHERE_AUTO_OBJECT_DEFINE_INCREF(Process);
|
||||||
|
|
|
@ -17,8 +17,10 @@ struct LightSessionRequest;
|
||||||
|
|
||||||
struct KThreadContext;
|
struct KThreadContext;
|
||||||
|
|
||||||
|
struct ThreadProcessListTag;
|
||||||
struct ThreadWaitListTag;
|
struct ThreadWaitListTag;
|
||||||
struct ThreadMutexWaitListTag;
|
struct ThreadMutexWaitListTag;
|
||||||
|
using ThreadProcessListBaseHook = boost::intrusive::list_base_hook<boost::intrusive::tag<ThreadProcessListTag> >;
|
||||||
using ThreadWaitListBaseHook = boost::intrusive::list_base_hook<boost::intrusive::tag<ThreadWaitListTag> >;
|
using ThreadWaitListBaseHook = boost::intrusive::list_base_hook<boost::intrusive::tag<ThreadWaitListTag> >;
|
||||||
using ThreadMutexWaitListBaseHook = boost::intrusive::list_base_hook<boost::intrusive::tag<ThreadMutexWaitListTag> >;
|
using ThreadMutexWaitListBaseHook = boost::intrusive::list_base_hook<boost::intrusive::tag<ThreadMutexWaitListTag> >;
|
||||||
|
|
||||||
|
@ -27,6 +29,7 @@ class KThread final :
|
||||||
public ILimitedResource<KThread>,
|
public ILimitedResource<KThread>,
|
||||||
public ISetAllocated<KThread>,
|
public ISetAllocated<KThread>,
|
||||||
public IAlarmable,
|
public IAlarmable,
|
||||||
|
public ThreadProcessListBaseHook,
|
||||||
public ThreadWaitListBaseHook,
|
public ThreadWaitListBaseHook,
|
||||||
public ThreadMutexWaitListBaseHook
|
public ThreadMutexWaitListBaseHook
|
||||||
{
|
{
|
||||||
|
@ -106,6 +109,12 @@ class KThread final :
|
||||||
KernelLoading = 4,
|
KernelLoading = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
using ProcessList = typename boost::intrusive::make_list<
|
||||||
|
KThread,
|
||||||
|
boost::intrusive::base_hook<ThreadProcessListBaseHook>
|
||||||
|
>::type;
|
||||||
|
|
||||||
using SchedulerList = typename boost::intrusive::make_list<
|
using SchedulerList = typename boost::intrusive::make_list<
|
||||||
KThread,
|
KThread,
|
||||||
boost::intrusive::value_traits<KThread::SchedulerValueTraits>
|
boost::intrusive::value_traits<KThread::SchedulerValueTraits>
|
||||||
|
|
Loading…
Reference in a new issue